summaryrefslogtreecommitdiffstats
path: root/src/H5FDstdio.c
diff options
context:
space:
mode:
authorMuQun Yang <ymuqun@hdfgroup.org>2003-04-29 19:13:21 (GMT)
committerMuQun Yang <ymuqun@hdfgroup.org>2003-04-29 19:13:21 (GMT)
commitf555485a003a93a9f97f89f73af3b5b6ea269b24 (patch)
tree2b9af7882a7637e6273e95fc6e0e1f434fb6497b /src/H5FDstdio.c
parent6c214577206cec6fc78fd0c5b722e6f2df107e14 (diff)
downloadhdf5-f555485a003a93a9f97f89f73af3b5b6ea269b24.zip
hdf5-f555485a003a93a9f97f89f73af3b5b6ea269b24.tar.gz
hdf5-f555485a003a93a9f97f89f73af3b5b6ea269b24.tar.bz2
[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:
Diffstat (limited to 'src/H5FDstdio.c')
-rw-r--r--src/H5FDstdio.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/H5FDstdio.c b/src/H5FDstdio.c
index f7510fe..958ae97 100644
--- a/src/H5FDstdio.c
+++ b/src/H5FDstdio.c
@@ -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;