From 5e7acfed72dab3bb0a653067b99b18368bdba3f3 Mon Sep 17 00:00:00 2001 From: Scott Wegner Date: Mon, 18 Jun 2007 13:19:56 -0500 Subject: [svn-r13873] Purpose: Code cleanup Description: Changed a macro in H5FDwindows.c from IO_BUF_SIZE to a more specific WINDOWS_MAX_BUF, and moved it to our H5pubconf.h, where users can customize it to their own preference. This value is needed because of a bug in the Windows _write function, it is unsafe to write buffers larger than 2GB-1 bytes in one write. Tested: VS2005 on WinXP. --- src/H5FDwindows.c | 13 ++++--------- windows/src/H5pubconf.h | 7 +++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/H5FDwindows.c b/src/H5FDwindows.c index e0ef11e..9d2b3f9 100644 --- a/src/H5FDwindows.c +++ b/src/H5FDwindows.c @@ -53,11 +53,6 @@ static hid_t H5FD_WINDOWS_g = 0; #define OP_WRITE 2 /* - * This is the max number of bytes that will be read or written by the file driver. - * Values above 2^31-1 may cause trouble with Windows. Default is 2^30. - */ -#define IO_BUF_SIZE 1073741824 -/* * The description of a file belonging to this driver. The `eoa' and `eof' * determine the amount of hdf5 address space in use and the high-water mark * of the file (the current size of the underlying file). The `pos' @@ -800,7 +795,7 @@ H5FD_windows_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, h while (size>0) { #ifndef WINDOWS_USE_STDIO do { - nbytes = _read(file->fd, buf, (unsigned)(size <= IO_BUF_SIZE ? size: IO_BUF_SIZE)); + nbytes = _read(file->fd, buf, (unsigned)(size <= WINDOWS_MAX_BUF ? size: WINDOWS_MAX_BUF)); } while (-1==nbytes && EINTR==errno); if (-1==nbytes) /* error */ HSYS_GOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "file read failed") @@ -811,7 +806,7 @@ H5FD_windows_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, h } #else do { - nbytes = fread(buf,(size_t)1,(size <= IO_BUF_SIZE ? size: IO_BUF_SIZE),file->fp); + nbytes = fread(buf,(size_t)1,(size <= WINDOWS_MAX_BUF ? size: WINDOWS_MAX_BUF),file->fp); } while (!nbytes && EINTR==errno); if(!nbytes) { if (ferror(file->fp)) /* error */ @@ -909,14 +904,14 @@ H5FD_windows_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, while (size>0) { do { #ifndef WINDOWS_USE_STDIO - nbytes = _write(file->fd, buf, (unsigned)(size <= IO_BUF_SIZE ? size: IO_BUF_SIZE)); + nbytes = _write(file->fd, buf, (unsigned)(size <= WINDOWS_MAX_BUF ? size: WINDOWS_MAX_BUF)); } while (-1==nbytes && EINTR==errno); if (-1==nbytes) /* error */ #else /* Write 1GB or less at a time */ - nbytes = fwrite(buf, 1, (size <= IO_BUF_SIZE ? size: IO_BUF_SIZE),file->fp); + nbytes = fwrite(buf, 1, (size <= WINDOWS_MAX_BUF ? size: WINDOWS_MAX_BUF),file->fp); } while (!nbytes && EINTR==errno); if (!nbytes) /* error */ #endif /* WINDOWS_USE_STDIO */ diff --git a/windows/src/H5pubconf.h b/windows/src/H5pubconf.h index aac8f41..9c4ef9b 100755 --- a/windows/src/H5pubconf.h +++ b/windows/src/H5pubconf.h @@ -126,9 +126,16 @@ in the file file_io.win32.c and including it on the projects #define H5_HAVE_WINDOWS 1 #ifdef H5_HAVE_WINDOWS + /* uncomment the following line if you would like to use the buffered stdio functions in the Windows file driver. */ // #define WINDOWS_USE_STDIO 1 + +/* this value controls the maximum data written in one write call in the + * Windows file driver. Safe values are between 1 <= IO_BUF_SIZE <= 2GB-1. + * The default is 1GB. */ +#define WINDOWS_MAX_BUF 1073741824 + #endif /* H5_HAVE_WINDOWS */ /* comment the following line out if you are not using N-bit filter*/ -- cgit v0.12