[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.
This commit is contained in:
Scott Wegner 2007-06-18 13:19:56 -05:00
parent 4d9397a101
commit 5e7acfed72
2 changed files with 11 additions and 9 deletions

View File

@ -52,11 +52,6 @@ static hid_t H5FD_WINDOWS_g = 0;
#define OP_READ 1
#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
@ -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 */

View File

@ -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*/