[svn-r6777] Purpose:

A bug fix for windows.
Description:
Many tests failed on windows when stdio driver is on.
I suspect it is the compiler bug.
After some investigation, the symptom is:
The signature of HDF5 file cannot be found.
The real problem is the signature was appended at the end of the whole
file instead of inserting at the starting of the file.
It seems when the file pointer(signature) is reset to the starting of the file,
windows mis-placed it to the end of the file after finding the file is close to
the end.

Solution:
Fortuately, ftell and fseek still function well on windows,
so I use ftell and fseek to force the file pointer to go to the position it is supposed
to go.

Platforms tested:
since the only change in this file is within ifdef WIN32 macro; it won't
affect the mainstream platforms, so I don't have to three platforms.

Platforms to confirm(test with basic function): Linux 2.4
Platforms to throughly test: windows 2000 with VS6.0
test on three different

Misc. update:
This commit is contained in:
MuQun Yang 2003-04-29 14:13:21 -05:00
parent 6c21457720
commit f555485a00

View File

@ -770,6 +770,10 @@ static herr_t
H5FD_stdio_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr,
size_t size, const void *buf)
{
#ifdef WIN32
fpos_t tempos;
#endif
H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
static const char *func="H5FD_stdio_write"; /* Function Name for error reporting */
@ -794,7 +798,7 @@ H5FD_stdio_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr,
if ((file->op != H5FD_STDIO_OP_WRITE && file->op != H5FD_STDIO_OP_SEEK) ||
file->pos != addr) {
#ifdef WIN32
fpos_t tempos =(fpos_t)(addr+SEEK_SET);
tempos =(fpos_t)(addr+SEEK_SET);
if (fsetpos(file->fp,&tempos) != 0) {
file->op = H5FD_STDIO_OP_UNKNOWN;
@ -827,7 +831,18 @@ H5FD_stdio_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr,
*/
file->op = H5FD_STDIO_OP_WRITE;
file->pos = addr + size;
/* The following code needs to be added for windows VC 6.0. This should be a VC++
compiler bug. When not using ftell and fseek, although you reset the position to
the starting of the file, fwrite will somehow to go to the end of the file and
add contents. It seems they used a circular seeking algorithm, the starting point
overlaps with the ending point and windows doesn't handle correctly for the case when
file was written to the disk close to the end of the file and rewrite from the beginning
of the file. This is how HDF5 signature was written for some failing cases. */
#ifdef WIN32
tempos = ftell(file->fp);
fseek(file->fp,tempos,SEEK_SET);
#endif
/* Update EOF if necessary */
if (file->pos>file->eof)
file->eof = file->pos;