From eb26303cf434c1ca6df34f613b9d2e6c72149ade Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Wed, 16 Apr 2003 14:24:05 -0500 Subject: [svn-r6689] Purpose: Bug fix. Description: The stdio filer driver is not reducing the file's size in the manner that the sec2 driver does. Solution: Copy code from the sec2 for handling this properly. Platforms tested: h5committested --- src/H5FDsec2.c | 7 +++---- src/H5FDstdio.c | 53 ++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c index 6cf835c..94eabfb 100644 --- a/src/H5FDsec2.c +++ b/src/H5FDsec2.c @@ -796,10 +796,6 @@ static herr_t H5FD_sec2_flush(H5FD_t *_file, hid_t UNUSED dxpl_id, unsigned UNUSED closing) { H5FD_sec2_t *file = (H5FD_sec2_t*)_file; -#ifdef WIN32 - HFILE filehandle; /* Windows file handle */ - LARGE_INTEGER li; /* 64-bit integer for SetFilePointer() call */ -#endif /* WIN32 */ herr_t ret_value=SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5FD_sec2_flush, FAIL); @@ -809,6 +805,9 @@ H5FD_sec2_flush(H5FD_t *_file, hid_t UNUSED dxpl_id, unsigned UNUSED closing) /* Extend the file to make sure it's large enough */ if (file->eoa!=file->eof) { #ifdef WIN32 + HFILE filehandle; /* Windows file handle */ + LARGE_INTEGER li; /* 64-bit integer for SetFilePointer() call */ + /* Map the posix file handle to a Windows file handle */ filehandle = _get_osfhandle(file->fd); diff --git a/src/H5FDstdio.c b/src/H5FDstdio.c index 83357eb..5e7246a 100644 --- a/src/H5FDstdio.c +++ b/src/H5FDstdio.c @@ -139,6 +139,18 @@ typedef struct H5FD_stdio_t { sizeof(long)write_access) { - /* Makes sure that the true file size is the same (or larger) than the end-of-address. */ - if (file->eoa>file->eof) { - if (fseek(file->fp, (long)(file->eoa-1), SEEK_SET)<0) - H5Epush_ret(func, H5E_IO, H5E_SEEKERROR, "fseek failed", -1); - if (fwrite("", 1, 1, file->fp)!=1) - H5Epush_ret(func, H5E_IO, H5E_SEEKERROR, "EOF fwrite failed", -1); + /* Makes sure that the true file size is the same as the end-of-address. */ + if (file->eoa!=file->eof) { + int fd=fileno(file->fp); /* File descriptor for HDF5 file */ +#ifdef WIN32 + HFILE filehandle; /* Windows file handle */ + LARGE_INTEGER li; /* 64-bit integer for SetFilePointer() call */ + + /* Map the posix file handle to a Windows file handle */ + filehandle = _get_osfhandle(file->fd); + + /* Translate 64-bit integers into form Windows wants */ + /* [This algorithm is from the Windows documentation for SetFilePointer()] */ + li.QuadPart = file->eoa; + SetFilePointer((HANDLE)filehandle,li.LowPart,&li.HighPart,FILE_BEGIN); + if(SetEndOfFile((HANDLE)filehandle)==0) + H5Epush_ret(func, H5E_IO, H5E_SEEKERROR, "unable to extend file properly", -1); +#else /* WIN32 */ + if (-1==file_truncate(fd, (file_offset_t)file->eoa)) + H5Epush_ret(func, H5E_IO, H5E_SEEKERROR, "unable to extend file properly", -1); +#endif /* WIN32 */ + /* Update the eof value */ file->eof = file->eoa; - file->pos = file->eoa; - /* fall through to set the IO operation */ - } - /* - * What happens to the file position? Is it guaranteed to be the same - * after the fflush() as it was before? - */ - file->op = H5FD_STDIO_OP_UNKNOWN; + /* Reset last file I/O information */ + file->pos = HADDR_UNDEF; + file->op = H5FD_STDIO_OP_UNKNOWN; + } /* end if */ /* * Flush @@ -881,7 +904,7 @@ H5FD_stdio_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing) if (fflush(file->fp) < 0) H5Epush_ret(func, H5E_IO, H5E_WRITEERROR, "fflush failed", -1); } /* end if */ - } /* end if */ + } /* end if */ else { /* Double-check for problems */ if (file->eoa>file->eof) -- cgit v0.12