Fixed a critical bug in SaveBuffers().

The bug was present since the first time SaveBuffers() was introduced.
When saving buffer metadata, I used saved_buffers[i], whereas the right
expression to use should have been saved_buffers[num_buffers].

All the other changes in this commit were made in an effort to solve
this bug; all along I thought something was wrong either in stdlib's
fread/fwrite, or in Postgres, because I repeatdly found all-zero
SavedBuffer structs in log files.

One set of important change, other than the above bug-fix, is that I
introduced the file{Open,Close,Read,Write} functions, to reduce the
amount of error-checking needed in the calling code. Apart from
replacing the fopen/fclose calls in BlockReader, I also used these to
replace the AllocateFile/FreeFile calls. I didn't like the idea of using
AllocateFile/FreeFile in BufferSaver from the beginning, becuase of
their close association with transactions (and that did cause debugging
headache at one point).

The code is ready for testing now.