summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2003-04-16 19:24:05 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2003-04-16 19:24:05 (GMT)
commiteb26303cf434c1ca6df34f613b9d2e6c72149ade (patch)
treeaa9db5ad6c948610b3a3d2096b215159819c9431 /src
parentdf785657a5ac5f8f7d12bf68de47d60922e01993 (diff)
downloadhdf5-eb26303cf434c1ca6df34f613b9d2e6c72149ade.zip
hdf5-eb26303cf434c1ca6df34f613b9d2e6c72149ade.tar.gz
hdf5-eb26303cf434c1ca6df34f613b9d2e6c72149ade.tar.bz2
[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
Diffstat (limited to 'src')
-rw-r--r--src/H5FDsec2.c7
-rw-r--r--src/H5FDstdio.c53
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)<sizeof(size_t) || HADDR_UNDEF==(A)+(Z) || (long)((A)+(Z))<(long)(A))
#endif
+#ifdef H5_HAVE_LSEEK64
+# define file_offset_t off64_t
+# define file_truncate ftruncate64
+#elif defined (WIN32) && !defined(__MWERKS__)
+# /*MSVC*/
+# define file_offset_t __int64
+# define file_truncate _ftruncatei64
+#else
+# define file_offset_t off_t
+# define file_truncate ftruncate
+#endif
+
/* Prototypes */
static H5FD_t *H5FD_stdio_open(const char *name, unsigned flags,
hid_t fapl_id, haddr_t maxaddr);
@@ -857,22 +869,33 @@ H5FD_stdio_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing)
/* Only try to flush the file if we have write access */
if(file->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)