summaryrefslogtreecommitdiffstats
path: root/src/H5FDstdio.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2020-10-01 14:04:36 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2020-10-01 14:04:36 (GMT)
commitf1ba03cea5b82699a984c80bd2deac14fdc8df18 (patch)
treeebe777c3e0b83f4c4cec9212731da9ebe0a0cfd3 /src/H5FDstdio.c
parent10343c197906415388f2a4c8d292e21d25cf7381 (diff)
downloadhdf5-f1ba03cea5b82699a984c80bd2deac14fdc8df18.zip
hdf5-f1ba03cea5b82699a984c80bd2deac14fdc8df18.tar.gz
hdf5-f1ba03cea5b82699a984c80bd2deac14fdc8df18.tar.bz2
Source formatted
Diffstat (limited to 'src/H5FDstdio.c')
-rw-r--r--src/H5FDstdio.c599
1 files changed, 300 insertions, 299 deletions
diff --git a/src/H5FDstdio.c b/src/H5FDstdio.c
index 1d401c2..c0836c2 100644
--- a/src/H5FDstdio.c
+++ b/src/H5FDstdio.c
@@ -41,8 +41,8 @@
#ifdef H5_HAVE_WIN32_API
/* The following two defines must be before any windows headers are included */
-#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
-#define NOGDI /* Exclude Graphic Display Interface macros */
+#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
+#define NOGDI /* Exclude Graphic Display Interface macros */
#include <windows.h>
#include <io.h>
@@ -57,10 +57,10 @@ static size_t H5_STDIO_MAX_IO_BYTES_g = (size_t)-1;
/* File operations */
typedef enum {
- H5FD_STDIO_OP_UNKNOWN=0,
- H5FD_STDIO_OP_READ=1,
- H5FD_STDIO_OP_WRITE=2,
- H5FD_STDIO_OP_SEEK=3
+ H5FD_STDIO_OP_UNKNOWN = 0,
+ H5FD_STDIO_OP_READ = 1,
+ H5FD_STDIO_OP_WRITE = 2,
+ H5FD_STDIO_OP_SEEK = 3
} H5FD_stdio_file_op;
/* The description of a file belonging to this driver. The 'eoa' and 'eof'
@@ -75,14 +75,14 @@ typedef enum {
* occurs), and 'op' will be set to H5F_OP_UNKNOWN.
*/
typedef struct H5FD_stdio_t {
- H5FD_t pub; /* public stuff, must be first */
- FILE *fp; /* the file handle */
- int fd; /* file descriptor (for truncate) */
- haddr_t eoa; /* end of allocated region */
- haddr_t eof; /* end of file; current file size */
- haddr_t pos; /* current file I/O position */
- unsigned write_access; /* Flag to indicate the file was opened with write access */
- H5FD_stdio_file_op op; /* last operation */
+ H5FD_t pub; /* public stuff, must be first */
+ FILE * fp; /* the file handle */
+ int fd; /* file descriptor (for truncate) */
+ haddr_t eoa; /* end of allocated region */
+ haddr_t eof; /* end of file; current file size */
+ haddr_t pos; /* current file I/O position */
+ unsigned write_access; /* Flag to indicate the file was opened with write access */
+ H5FD_stdio_file_op op; /* last operation */
#ifndef H5_HAVE_WIN32_API
/* On most systems the combination of device and i-node number uniquely
* identify a file. Note that Cygwin, MinGW and other Windows POSIX
@@ -90,8 +90,8 @@ typedef struct H5FD_stdio_t {
* and will use the 'device + inodes' scheme as opposed to the
* Windows code further below.
*/
- dev_t device; /* file device number */
- ino_t inode; /* file i-node number */
+ dev_t device; /* file device number */
+ ino_t inode; /* file i-node number */
#else
/* Files in windows are uniquely identified by the volume serial
* number and the file index (both low and high parts).
@@ -107,21 +107,21 @@ typedef struct H5FD_stdio_t {
*
* http://msdn.microsoft.com/en-us/library/aa363788(v=VS.85).aspx
*/
- DWORD nFileIndexLow;
- DWORD nFileIndexHigh;
- DWORD dwVolumeSerialNumber;
+ DWORD nFileIndexLow;
+ DWORD nFileIndexHigh;
+ DWORD dwVolumeSerialNumber;
- HANDLE hFile; /* Native windows file handle */
-#endif /* H5_HAVE_WIN32_API */
+ HANDLE hFile; /* Native windows file handle */
+#endif /* H5_HAVE_WIN32_API */
} H5FD_stdio_t;
/* Use similar structure as in H5private.h by defining Windows stuff first. */
#ifdef H5_HAVE_WIN32_API
#ifndef H5_HAVE_MINGW
- #define file_fseek _fseeki64
- #define file_offset_t __int64
- #define file_ftruncate _chsize_s /* Supported in VS 2005 or newer */
- #define file_ftell _ftelli64
+#define file_fseek _fseeki64
+#define file_offset_t __int64
+#define file_ftruncate _chsize_s /* Supported in VS 2005 or newer */
+#define file_ftell _ftelli64
#endif /* H5_HAVE_MINGW */
#endif /* H5_HAVE_WIN32_API */
@@ -129,10 +129,10 @@ typedef struct H5FD_stdio_t {
* more platform-independent names.
*/
#ifndef file_fseek
- #define file_fseek fseeko
- #define file_offset_t off_t
- #define file_ftruncate ftruncate
- #define file_ftell ftello
+#define file_fseek fseeko
+#define file_offset_t off_t
+#define file_ftruncate ftruncate
+#define file_ftell ftello
#endif /* file_fseek */
/* These macros check for overflow of various quantities. These macros
@@ -150,69 +150,68 @@ typedef struct H5FD_stdio_t {
* argument of the file seek function.
*/
/* adding for windows NT filesystem support. */
-#define MAXADDR (((haddr_t)1<<(8*sizeof(file_offset_t)-1))-1)
-#define ADDR_OVERFLOW(A) (HADDR_UNDEF==(A) || ((A) & ~(haddr_t)MAXADDR))
-#define SIZE_OVERFLOW(Z) ((Z) & ~(hsize_t)MAXADDR)
-#define REGION_OVERFLOW(A,Z) (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || \
- HADDR_UNDEF==(A)+(Z) || (file_offset_t)((A)+(Z))<(file_offset_t)(A))
+#define MAXADDR (((haddr_t)1 << (8 * sizeof(file_offset_t) - 1)) - 1)
+#define ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || ((A) & ~(haddr_t)MAXADDR))
+#define SIZE_OVERFLOW(Z) ((Z) & ~(hsize_t)MAXADDR)
+#define REGION_OVERFLOW(A, Z) \
+ (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || HADDR_UNDEF == (A) + (Z) || \
+ (file_offset_t)((A) + (Z)) < (file_offset_t)(A))
/* Prototypes */
-static herr_t H5FD_stdio_term(void);
-static H5FD_t *H5FD_stdio_open(const char *name, unsigned flags,
- hid_t fapl_id, haddr_t maxaddr);
-static herr_t H5FD_stdio_close(H5FD_t *lf);
-static int H5FD_stdio_cmp(const H5FD_t *_f1, const H5FD_t *_f2);
-static herr_t H5FD_stdio_query(const H5FD_t *_f1, unsigned long *flags);
+static herr_t H5FD_stdio_term(void);
+static H5FD_t *H5FD_stdio_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr);
+static herr_t H5FD_stdio_close(H5FD_t *lf);
+static int H5FD_stdio_cmp(const H5FD_t *_f1, const H5FD_t *_f2);
+static herr_t H5FD_stdio_query(const H5FD_t *_f1, unsigned long *flags);
static haddr_t H5FD_stdio_alloc(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, hsize_t size);
static haddr_t H5FD_stdio_get_eoa(const H5FD_t *_file, H5FD_mem_t type);
-static herr_t H5FD_stdio_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t addr);
+static herr_t H5FD_stdio_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t addr);
static haddr_t H5FD_stdio_get_eof(const H5FD_t *_file, H5FD_mem_t type);
-static herr_t H5FD_stdio_get_handle(H5FD_t *_file, hid_t fapl, void** file_handle);
-static herr_t H5FD_stdio_read(H5FD_t *lf, H5FD_mem_t type, hid_t fapl_id, haddr_t addr,
- size_t size, void *buf);
-static herr_t H5FD_stdio_write(H5FD_t *lf, H5FD_mem_t type, hid_t fapl_id, haddr_t addr,
- size_t size, const void *buf);
-static herr_t H5FD_stdio_flush(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
-static herr_t H5FD_stdio_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
-static herr_t H5FD_stdio_lock(H5FD_t *_file, hbool_t rw);
-static herr_t H5FD_stdio_unlock(H5FD_t *_file);
+static herr_t H5FD_stdio_get_handle(H5FD_t *_file, hid_t fapl, void **file_handle);
+static herr_t H5FD_stdio_read(H5FD_t *lf, H5FD_mem_t type, hid_t fapl_id, haddr_t addr, size_t size,
+ void *buf);
+static herr_t H5FD_stdio_write(H5FD_t *lf, H5FD_mem_t type, hid_t fapl_id, haddr_t addr, size_t size,
+ const void *buf);
+static herr_t H5FD_stdio_flush(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
+static herr_t H5FD_stdio_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
+static herr_t H5FD_stdio_lock(H5FD_t *_file, hbool_t rw);
+static herr_t H5FD_stdio_unlock(H5FD_t *_file);
static const H5FD_class_t H5FD_stdio_g = {
- "stdio", /* name */
- MAXADDR, /* maxaddr */
- H5F_CLOSE_WEAK, /* fc_degree */
- H5FD_stdio_term, /* terminate */
- NULL, /* sb_size */
- NULL, /* sb_encode */
- NULL, /* sb_decode */
- 0, /* fapl_size */
- NULL, /* fapl_get */
- NULL, /* fapl_copy */
- NULL, /* fapl_free */
- 0, /* dxpl_size */
- NULL, /* dxpl_copy */
- NULL, /* dxpl_free */
- H5FD_stdio_open, /* open */
- H5FD_stdio_close, /* close */
- H5FD_stdio_cmp, /* cmp */
- H5FD_stdio_query, /* query */
- NULL, /* get_type_map */
- H5FD_stdio_alloc, /* alloc */
- NULL, /* free */
- H5FD_stdio_get_eoa, /* get_eoa */
- H5FD_stdio_set_eoa, /* set_eoa */
- H5FD_stdio_get_eof, /* get_eof */
- H5FD_stdio_get_handle, /* get_handle */
- H5FD_stdio_read, /* read */
- H5FD_stdio_write, /* write */
- H5FD_stdio_flush, /* flush */
- H5FD_stdio_truncate, /* truncate */
- H5FD_stdio_lock, /* lock */
- H5FD_stdio_unlock, /* unlock */
- H5FD_FLMAP_DICHOTOMY /* fl_map */
+ "stdio", /* name */
+ MAXADDR, /* maxaddr */
+ H5F_CLOSE_WEAK, /* fc_degree */
+ H5FD_stdio_term, /* terminate */
+ NULL, /* sb_size */
+ NULL, /* sb_encode */
+ NULL, /* sb_decode */
+ 0, /* fapl_size */
+ NULL, /* fapl_get */
+ NULL, /* fapl_copy */
+ NULL, /* fapl_free */
+ 0, /* dxpl_size */
+ NULL, /* dxpl_copy */
+ NULL, /* dxpl_free */
+ H5FD_stdio_open, /* open */
+ H5FD_stdio_close, /* close */
+ H5FD_stdio_cmp, /* cmp */
+ H5FD_stdio_query, /* query */
+ NULL, /* get_type_map */
+ H5FD_stdio_alloc, /* alloc */
+ NULL, /* free */
+ H5FD_stdio_get_eoa, /* get_eoa */
+ H5FD_stdio_set_eoa, /* set_eoa */
+ H5FD_stdio_get_eof, /* get_eof */
+ H5FD_stdio_get_handle, /* get_handle */
+ H5FD_stdio_read, /* read */
+ H5FD_stdio_write, /* write */
+ H5FD_stdio_flush, /* flush */
+ H5FD_stdio_truncate, /* truncate */
+ H5FD_stdio_lock, /* lock */
+ H5FD_stdio_unlock, /* unlock */
+ H5FD_FLMAP_DICHOTOMY /* fl_map */
};
-
/*-------------------------------------------------------------------------
* Function: H5FD_stdio_init
*
@@ -234,12 +233,11 @@ H5FD_stdio_init(void)
/* Clear the error stack */
H5Eclear2(H5E_DEFAULT);
- if (H5I_VFL!=H5Iget_type(H5FD_STDIO_g))
+ if (H5I_VFL != H5Iget_type(H5FD_STDIO_g))
H5FD_STDIO_g = H5FDregister(&H5FD_stdio_g);
return H5FD_STDIO_g;
} /* end H5FD_stdio_init() */
-
/*---------------------------------------------------------------------------
* Function: H5FD_stdio_term
*
@@ -261,7 +259,6 @@ H5FD_stdio_term(void)
return 0;
} /* end H5FD_stdio_term() */
-
/*-------------------------------------------------------------------------
* Function: H5Pset_fapl_stdio
*
@@ -279,20 +276,19 @@ H5FD_stdio_term(void)
herr_t
H5Pset_fapl_stdio(hid_t fapl_id)
{
- static const char *func = "H5FDset_fapl_stdio"; /*for error reporting*/
+ static const char *func = "H5FDset_fapl_stdio"; /*for error reporting*/
/*NO TRACE*/
/* Clear the error stack */
H5Eclear2(H5E_DEFAULT);
- if(0 == H5Pisa_class(fapl_id, H5P_FILE_ACCESS))
+ if (0 == H5Pisa_class(fapl_id, H5P_FILE_ACCESS))
H5Epush_ret(func, H5E_ERR_CLS, H5E_PLIST, H5E_BADTYPE, "not a file access property list", -1)
- return H5Pset_driver(fapl_id, H5FD_STDIO, NULL);
+ return H5Pset_driver(fapl_id, H5FD_STDIO, NULL);
} /* end H5Pset_fapl_stdio() */
-
/*-------------------------------------------------------------------------
* Function: H5FD_stdio_open
*
@@ -318,18 +314,17 @@ H5Pset_fapl_stdio(hid_t fapl_id)
*-------------------------------------------------------------------------
*/
static H5FD_t *
-H5FD_stdio_open( const char *name, unsigned flags, hid_t /*UNUSED*/ fapl_id,
- haddr_t maxaddr)
+H5FD_stdio_open(const char *name, unsigned flags, hid_t /*UNUSED*/ fapl_id, haddr_t maxaddr)
{
- FILE *f = NULL;
- unsigned write_access = 0; /* File opened with write access? */
- H5FD_stdio_t *file = NULL;
- static const char *func = "H5FD_stdio_open"; /* Function Name for error reporting */
+ FILE * f = NULL;
+ unsigned write_access = 0; /* File opened with write access? */
+ H5FD_stdio_t * file = NULL;
+ static const char *func = "H5FD_stdio_open"; /* Function Name for error reporting */
#ifdef H5_HAVE_WIN32_API
struct _BY_HANDLE_FILE_INFORMATION fileinfo;
-#else /* H5_HAVE_WIN32_API */
- struct stat sb;
-#endif /* H5_HAVE_WIN32_API */
+#else /* H5_HAVE_WIN32_API */
+ struct stat sb;
+#endif /* H5_HAVE_WIN32_API */
/* Sanity check on file offsets */
assert(sizeof(file_offset_t) >= sizeof(size_t));
@@ -342,104 +337,108 @@ H5FD_stdio_open( const char *name, unsigned flags, hid_t /*UNUSED*/ fapl_id,
/* Check arguments */
if (!name || !*name)
- H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_BADVALUE, "invalid file name", NULL)
- if (0 == maxaddr || HADDR_UNDEF == maxaddr)
- H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_BADRANGE, "bogus maxaddr", NULL)
- if (ADDR_OVERFLOW(maxaddr))
- H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_OVERFLOW, "maxaddr too large", NULL)
-
- /* Tentatively open file in read-only mode, to check for existence */
- if(flags & H5F_ACC_RDWR)
- f = fopen(name, "rb+");
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_BADVALUE, "invalid file name",
+ NULL) if (0 == maxaddr || HADDR_UNDEF == maxaddr)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_BADRANGE, "bogus maxaddr",
+ NULL) if (ADDR_OVERFLOW(maxaddr))
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_OVERFLOW, "maxaddr too large", NULL)
+
+ /* Tentatively open file in read-only mode, to check for existence */
+ if (flags & H5F_ACC_RDWR) f = fopen(name, "rb+");
else
f = fopen(name, "rb");
- if(!f) {
+ if (!f) {
/* File doesn't exist */
- if(flags & H5F_ACC_CREAT) {
+ if (flags & H5F_ACC_CREAT) {
assert(flags & H5F_ACC_RDWR);
- f = fopen(name, "wb+");
- write_access = 1; /* Note the write access */
+ f = fopen(name, "wb+");
+ write_access = 1; /* Note the write access */
}
else
- H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_CANTOPENFILE, "file doesn't exist and CREAT wasn't specified", NULL)
- } else if(flags & H5F_ACC_EXCL) {
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_CANTOPENFILE,
+ "file doesn't exist and CREAT wasn't specified", NULL)
+ }
+ else if (flags & H5F_ACC_EXCL) {
/* File exists, but EXCL is passed. Fail. */
assert(flags & H5F_ACC_CREAT);
fclose(f);
- H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FILEEXISTS, "file exists but CREAT and EXCL were specified", NULL)
- } else if(flags & H5F_ACC_RDWR) {
- if(flags & H5F_ACC_TRUNC)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FILEEXISTS,
+ "file exists but CREAT and EXCL were specified", NULL)
+ }
+ else if (flags & H5F_ACC_RDWR) {
+ if (flags & H5F_ACC_TRUNC)
f = freopen(name, "wb+", f);
- write_access = 1; /* Note the write access */
- } /* end if */
+ write_access = 1; /* Note the write access */
+ } /* end if */
/* Note there is no need to reopen if neither TRUNC nor EXCL are specified,
* as the tentative open will work */
- if(!f)
+ if (!f)
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_CANTOPENFILE, "fopen failed", NULL)
- /* Build the return value */
- if(NULL == (file = (H5FD_stdio_t *)calloc((size_t)1, sizeof(H5FD_stdio_t)))) {
- fclose(f);
- H5Epush_ret(func, H5E_ERR_CLS, H5E_RESOURCE, H5E_NOSPACE, "memory allocation failed", NULL)
- } /* end if */
- file->fp = f;
- file->op = H5FD_STDIO_OP_SEEK;
- file->pos = HADDR_UNDEF;
- file->write_access = write_access; /* Note the write_access for later */
- if(file_fseek(file->fp, (file_offset_t)0, SEEK_END) < 0) {
+ /* Build the return value */
+ if (NULL == (file = (H5FD_stdio_t *)calloc((size_t)1, sizeof(H5FD_stdio_t))))
+ {
+ fclose(f);
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_RESOURCE, H5E_NOSPACE, "memory allocation failed", NULL)
+ } /* end if */
+ file->fp = f;
+ file->op = H5FD_STDIO_OP_SEEK;
+ file->pos = HADDR_UNDEF;
+ file->write_access = write_access; /* Note the write_access for later */
+ if (file_fseek(file->fp, (file_offset_t)0, SEEK_END) < 0) {
file->op = H5FD_STDIO_OP_UNKNOWN;
- } else {
+ }
+ else {
file_offset_t x = file_ftell(file->fp);
- assert (x >= 0);
+ assert(x >= 0);
file->eof = (haddr_t)x;
}
/* Get the file descriptor (needed for truncate and some Windows information) */
#ifdef H5_HAVE_WIN32_API
file->fd = _fileno(file->fp);
-#else /* H5_HAVE_WIN32_API */
+#else /* H5_HAVE_WIN32_API */
file->fd = fileno(file->fp);
#endif /* H5_HAVE_WIN32_API */
- if(file->fd < 0) {
+ if (file->fd < 0) {
free(file);
fclose(f);
H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTOPENFILE, "unable to get file descriptor", NULL);
} /* end if */
-
#ifdef H5_HAVE_WIN32_API
file->hFile = (HANDLE)_get_osfhandle(file->fd);
- if(INVALID_HANDLE_VALUE == file->hFile) {
+ if (INVALID_HANDLE_VALUE == file->hFile) {
free(file);
fclose(f);
H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTOPENFILE, "unable to get Windows file handle", NULL);
} /* end if */
- if(!GetFileInformationByHandle((HANDLE)file->hFile, &fileinfo)) {
+ if (!GetFileInformationByHandle((HANDLE)file->hFile, &fileinfo)) {
free(file);
fclose(f);
- H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTOPENFILE, "unable to get Windows file descriptor information", NULL);
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTOPENFILE,
+ "unable to get Windows file descriptor information", NULL);
} /* end if */
- file->nFileIndexHigh = fileinfo.nFileIndexHigh;
- file->nFileIndexLow = fileinfo.nFileIndexLow;
+ file->nFileIndexHigh = fileinfo.nFileIndexHigh;
+ file->nFileIndexLow = fileinfo.nFileIndexLow;
file->dwVolumeSerialNumber = fileinfo.dwVolumeSerialNumber;
-#else /* H5_HAVE_WIN32_API */
- if(fstat(file->fd, &sb) < 0) {
+#else /* H5_HAVE_WIN32_API */
+ if (fstat(file->fd, &sb) < 0) {
free(file);
fclose(f);
H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_BADFILE, "unable to fstat file", NULL)
} /* end if */
file->device = sb.st_dev;
- file->inode = sb.st_ino;
+ file->inode = sb.st_ino;
#endif /* H5_HAVE_WIN32_API */
- return((H5FD_t*)file);
+ return ((H5FD_t *)file);
} /* end H5FD_stdio_open() */
-
/*-------------------------------------------------------------------------
* Function: H5F_stdio_close
*
@@ -458,8 +457,8 @@ H5FD_stdio_open( const char *name, unsigned flags, hid_t /*UNUSED*/ fapl_id,
static herr_t
H5FD_stdio_close(H5FD_t *_file)
{
- H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
- static const char *func = "H5FD_stdio_close"; /* Function Name for error reporting */
+ H5FD_stdio_t * file = (H5FD_stdio_t *)_file;
+ static const char *func = "H5FD_stdio_close"; /* Function Name for error reporting */
/* Clear the error stack */
H5Eclear2(H5E_DEFAULT);
@@ -467,12 +466,11 @@ H5FD_stdio_close(H5FD_t *_file)
if (fclose(file->fp) < 0)
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_CLOSEERROR, "fclose failed", -1)
- free(file);
+ free(file);
return 0;
} /* end H5FD_stdio_close() */
-
/*-------------------------------------------------------------------------
* Function: H5FD_stdio_cmp
*
@@ -492,41 +490,52 @@ H5FD_stdio_close(H5FD_t *_file)
static int
H5FD_stdio_cmp(const H5FD_t *_f1, const H5FD_t *_f2)
{
- const H5FD_stdio_t *f1 = (const H5FD_stdio_t*)_f1;
- const H5FD_stdio_t *f2 = (const H5FD_stdio_t*)_f2;
+ const H5FD_stdio_t *f1 = (const H5FD_stdio_t *)_f1;
+ const H5FD_stdio_t *f2 = (const H5FD_stdio_t *)_f2;
/* Clear the error stack */
H5Eclear2(H5E_DEFAULT);
#ifdef H5_HAVE_WIN32_API
- if(f1->dwVolumeSerialNumber < f2->dwVolumeSerialNumber) return -1;
- if(f1->dwVolumeSerialNumber > f2->dwVolumeSerialNumber) return 1;
-
- if(f1->nFileIndexHigh < f2->nFileIndexHigh) return -1;
- if(f1->nFileIndexHigh > f2->nFileIndexHigh) return 1;
-
- if(f1->nFileIndexLow < f2->nFileIndexLow) return -1;
- if(f1->nFileIndexLow > f2->nFileIndexLow) return 1;
+ if (f1->dwVolumeSerialNumber < f2->dwVolumeSerialNumber)
+ return -1;
+ if (f1->dwVolumeSerialNumber > f2->dwVolumeSerialNumber)
+ return 1;
+
+ if (f1->nFileIndexHigh < f2->nFileIndexHigh)
+ return -1;
+ if (f1->nFileIndexHigh > f2->nFileIndexHigh)
+ return 1;
+
+ if (f1->nFileIndexLow < f2->nFileIndexLow)
+ return -1;
+ if (f1->nFileIndexLow > f2->nFileIndexLow)
+ return 1;
#else /* H5_HAVE_WIN32_API */
#ifdef H5_DEV_T_IS_SCALAR
- if(f1->device < f2->device) return -1;
- if(f1->device > f2->device) return 1;
-#else /* H5_DEV_T_IS_SCALAR */
+ if (f1->device < f2->device)
+ return -1;
+ if (f1->device > f2->device)
+ return 1;
+#else /* H5_DEV_T_IS_SCALAR */
/* If dev_t isn't a scalar value on this system, just use memcmp to
* determine if the values are the same or not. The actual return value
* shouldn't really matter...
*/
- if(memcmp(&(f1->device),&(f2->device),sizeof(dev_t)) < 0) return -1;
- if(memcmp(&(f1->device),&(f2->device),sizeof(dev_t)) > 0) return 1;
+ if (memcmp(&(f1->device), &(f2->device), sizeof(dev_t)) < 0)
+ return -1;
+ if (memcmp(&(f1->device), &(f2->device), sizeof(dev_t)) > 0)
+ return 1;
#endif /* H5_DEV_T_IS_SCALAR */
- if(f1->inode < f2->inode) return -1;
- if(f1->inode > f2->inode) return 1;
+ if (f1->inode < f2->inode)
+ return -1;
+ if (f1->inode > f2->inode)
+ return 1;
#endif /* H5_HAVE_WIN32_API */
return 0;
} /* H5FD_stdio_cmp() */
-
/*-------------------------------------------------------------------------
* Function: H5FD_stdio_query
*
@@ -546,26 +555,26 @@ static herr_t
H5FD_stdio_query(const H5FD_t *_f, unsigned long /*OUT*/ *flags)
{
/* Quiet the compiler */
- _f=_f;
+ _f = _f;
/* Set the VFL feature flags that this driver supports.
*
* Note that this VFD does not support SWMR due to the unpredictable
* nature of the buffering layer.
*/
- if(flags) {
+ if (flags) {
*flags = 0;
- *flags |= H5FD_FEAT_AGGREGATE_METADATA; /* OK to aggregate metadata allocations */
- *flags |= H5FD_FEAT_ACCUMULATE_METADATA; /* OK to accumulate metadata for faster writes */
- *flags |= H5FD_FEAT_DATA_SIEVE; /* OK to perform data sieving for faster raw data reads & writes */
- *flags |= H5FD_FEAT_AGGREGATE_SMALLDATA; /* OK to aggregate "small" raw data allocations */
- *flags |= H5FD_FEAT_DEFAULT_VFD_COMPATIBLE; /* VFD creates a file which can be opened with the default VFD */
+ *flags |= H5FD_FEAT_AGGREGATE_METADATA; /* OK to aggregate metadata allocations */
+ *flags |= H5FD_FEAT_ACCUMULATE_METADATA; /* OK to accumulate metadata for faster writes */
+ *flags |= H5FD_FEAT_DATA_SIEVE; /* OK to perform data sieving for faster raw data reads & writes */
+ *flags |= H5FD_FEAT_AGGREGATE_SMALLDATA; /* OK to aggregate "small" raw data allocations */
+ *flags |= H5FD_FEAT_DEFAULT_VFD_COMPATIBLE; /* VFD creates a file which can be opened with the default
+ VFD */
}
return 0;
} /* end H5FD_stdio_query() */
-
/*-------------------------------------------------------------------------
* Function: H5FD_stdio_alloc
*
@@ -587,11 +596,11 @@ H5FD_stdio_query(const H5FD_t *_f, unsigned long /*OUT*/ *flags)
static haddr_t
H5FD_stdio_alloc(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxpl_id, hsize_t size)
{
- H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
- haddr_t addr;
+ H5FD_stdio_t *file = (H5FD_stdio_t *)_file;
+ haddr_t addr;
/* Quiet compiler */
- type = type;
+ type = type;
dxpl_id = dxpl_id;
/* Clear the error stack */
@@ -605,7 +614,6 @@ H5FD_stdio_alloc(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxp
return addr;
} /* end H5FD_stdio_alloc() */
-
/*-------------------------------------------------------------------------
* Function: H5FD_stdio_get_eoa
*
@@ -636,7 +644,6 @@ H5FD_stdio_get_eoa(const H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type)
return file->eoa;
} /* end H5FD_stdio_get_eoa() */
-
/*-------------------------------------------------------------------------
* Function: H5FD_stdio_set_eoa
*
@@ -656,7 +663,7 @@ H5FD_stdio_get_eoa(const H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type)
static herr_t
H5FD_stdio_set_eoa(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, haddr_t addr)
{
- H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
+ H5FD_stdio_t *file = (H5FD_stdio_t *)_file;
/* Clear the error stack */
H5Eclear2(H5E_DEFAULT);
@@ -669,7 +676,6 @@ H5FD_stdio_set_eoa(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, haddr_t addr)
return 0;
}
-
/*-------------------------------------------------------------------------
* Function: H5FD_stdio_get_eof
*
@@ -691,7 +697,7 @@ H5FD_stdio_set_eoa(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, haddr_t addr)
static haddr_t
H5FD_stdio_get_eof(const H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type)
{
- const H5FD_stdio_t *file = (const H5FD_stdio_t *)_file;
+ const H5FD_stdio_t *file = (const H5FD_stdio_t *)_file;
/* Quiet the compiler */
type = type;
@@ -702,10 +708,9 @@ H5FD_stdio_get_eof(const H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type)
/* Quiet the compiler */
type = type;
- return(file->eof);
+ return (file->eof);
} /* end H5FD_stdio_get_eof() */
-
/*-------------------------------------------------------------------------
* Function: H5FD_stdio_get_handle
*
@@ -721,8 +726,8 @@ H5FD_stdio_get_eof(const H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type)
static herr_t
H5FD_stdio_get_handle(H5FD_t *_file, hid_t /*UNUSED*/ fapl, void **file_handle)
{
- H5FD_stdio_t *file = (H5FD_stdio_t *)_file;
- static const char *func = "H5FD_stdio_get_handle"; /* Function Name for error reporting */
+ H5FD_stdio_t * file = (H5FD_stdio_t *)_file;
+ static const char *func = "H5FD_stdio_get_handle"; /* Function Name for error reporting */
/* Quiet the compiler */
fapl = fapl;
@@ -731,13 +736,12 @@ H5FD_stdio_get_handle(H5FD_t *_file, hid_t /*UNUSED*/ fapl, void **file_handle)
H5Eclear2(H5E_DEFAULT);
*file_handle = &(file->fp);
- if(*file_handle == NULL)
+ if (*file_handle == NULL)
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "get handle failed", -1)
- return 0;
+ return 0;
} /* end H5FD_stdio_get_handle() */
-
/*-------------------------------------------------------------------------
* Function: H5FD_stdio_read
*
@@ -757,38 +761,36 @@ H5FD_stdio_get_handle(H5FD_t *_file, hid_t /*UNUSED*/ fapl, void **file_handle)
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_stdio_read(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxpl_id,
- haddr_t addr, size_t size, void /*OUT*/ *buf)
+H5FD_stdio_read(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxpl_id, haddr_t addr,
+ size_t size, void /*OUT*/ *buf)
{
- H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
- static const char *func = "H5FD_stdio_read"; /* Function Name for error reporting */
+ H5FD_stdio_t * file = (H5FD_stdio_t *)_file;
+ static const char *func = "H5FD_stdio_read"; /* Function Name for error reporting */
/* Quiet the compiler */
- type = type;
+ type = type;
dxpl_id = dxpl_id;
/* Clear the error stack */
H5Eclear2(H5E_DEFAULT);
/* Check for overflow */
- if (HADDR_UNDEF==addr)
- H5Epush_ret (func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1)
- if (REGION_OVERFLOW(addr, size))
- H5Epush_ret (func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1)
+ if (HADDR_UNDEF == addr)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed",
+ -1) if (REGION_OVERFLOW(addr, size))
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1)
- /* Check easy cases */
- if (0 == size)
- return 0;
+ /* Check easy cases */
+ if (0 == size) return 0;
if ((haddr_t)addr >= file->eof) {
memset(buf, 0, size);
return 0;
}
/* Seek to the correct file position. */
- if (!(file->op == H5FD_STDIO_OP_READ || file->op == H5FD_STDIO_OP_SEEK) ||
- file->pos != addr) {
+ if (!(file->op == H5FD_STDIO_OP_READ || file->op == H5FD_STDIO_OP_SEEK) || file->pos != addr) {
if (file_fseek(file->fp, (file_offset_t)addr, SEEK_SET) < 0) {
- file->op = H5FD_STDIO_OP_UNKNOWN;
+ file->op = H5FD_STDIO_OP_UNKNOWN;
file->pos = HADDR_UNDEF;
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "fseek failed", -1)
}
@@ -797,7 +799,7 @@ H5FD_stdio_read(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxpl
/* Read zeros past the logical end of file (physical is handled below) */
if (addr + size > file->eof) {
- size_t nbytes = (size_t) (addr + size - file->eof);
+ size_t nbytes = (size_t)(addr + size - file->eof);
memset((unsigned char *)buf + size - nbytes, 0, nbytes);
size -= nbytes;
}
@@ -806,26 +808,26 @@ H5FD_stdio_read(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxpl
* will advance the file position by N. If N is zero or an error
* occurs then the file position is undefined.
*/
- while(size > 0) {
+ while (size > 0) {
- size_t bytes_in = 0; /* # of bytes to read */
- size_t bytes_read = 0; /* # of bytes actually read */
- size_t item_size = 1; /* size of items in bytes */
+ size_t bytes_in = 0; /* # of bytes to read */
+ size_t bytes_read = 0; /* # of bytes actually read */
+ size_t item_size = 1; /* size of items in bytes */
- if(size > H5_STDIO_MAX_IO_BYTES_g)
+ if (size > H5_STDIO_MAX_IO_BYTES_g)
bytes_in = H5_STDIO_MAX_IO_BYTES_g;
else
bytes_in = size;
bytes_read = fread(buf, item_size, bytes_in, file->fp);
- if(0 == bytes_read && ferror(file->fp)) { /* error */
- file->op = H5FD_STDIO_OP_UNKNOWN;
+ if (0 == bytes_read && ferror(file->fp)) { /* error */
+ file->op = H5FD_STDIO_OP_UNKNOWN;
file->pos = HADDR_UNDEF;
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_READERROR, "fread failed", -1)
} /* end if */
- if(0 == bytes_read && feof(file->fp)) {
+ if (0 == bytes_read && feof(file->fp)) {
/* end of file but not end of format address space */
memset((unsigned char *)buf, 0, size);
break;
@@ -837,13 +839,12 @@ H5FD_stdio_read(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxpl
} /* end while */
/* Update the file position data. */
- file->op = H5FD_STDIO_OP_READ;
+ file->op = H5FD_STDIO_OP_READ;
file->pos = addr;
return 0;
}
-
/*-------------------------------------------------------------------------
* Function: H5FD_stdio_write
*
@@ -862,55 +863,55 @@ H5FD_stdio_read(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxpl
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_stdio_write(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxpl_id,
- haddr_t addr, size_t size, const void *buf)
+H5FD_stdio_write(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxpl_id, haddr_t addr,
+ size_t size, const void *buf)
{
- H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
- static const char *func = "H5FD_stdio_write"; /* Function Name for error reporting */
+ H5FD_stdio_t * file = (H5FD_stdio_t *)_file;
+ static const char *func = "H5FD_stdio_write"; /* Function Name for error reporting */
/* Quiet the compiler */
dxpl_id = dxpl_id;
- type = type;
+ type = type;
/* Clear the error stack */
H5Eclear2(H5E_DEFAULT);
/* Check for overflow conditions */
if (HADDR_UNDEF == addr)
- H5Epush_ret (func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1)
- if (REGION_OVERFLOW(addr, size))
- H5Epush_ret (func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1)
-
- /* Seek to the correct file position. */
- if ((file->op != H5FD_STDIO_OP_WRITE && file->op != H5FD_STDIO_OP_SEEK) ||
- file->pos != addr) {
- if (file_fseek(file->fp, (file_offset_t)addr, SEEK_SET) < 0) {
- file->op = H5FD_STDIO_OP_UNKNOWN;
- file->pos = HADDR_UNDEF;
- H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "fseek failed", -1)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed",
+ -1) if (REGION_OVERFLOW(addr, size))
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1)
+
+ /* Seek to the correct file position. */
+ if ((file->op != H5FD_STDIO_OP_WRITE && file->op != H5FD_STDIO_OP_SEEK) || file->pos != addr)
+ {
+ if (file_fseek(file->fp, (file_offset_t)addr, SEEK_SET) < 0) {
+ file->op = H5FD_STDIO_OP_UNKNOWN;
+ file->pos = HADDR_UNDEF;
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "fseek failed", -1)
+ }
+ file->pos = addr;
}
- file->pos = addr;
- }
/* Write the buffer. On successful return, the file position will be
* advanced by the number of bytes read. On failure, the file position is
* undefined.
*/
- while(size > 0) {
+ while (size > 0) {
- size_t bytes_in = 0; /* # of bytes to write */
- size_t bytes_wrote = 0; /* # of bytes written */
- size_t item_size = 1; /* size of items in bytes */
+ size_t bytes_in = 0; /* # of bytes to write */
+ size_t bytes_wrote = 0; /* # of bytes written */
+ size_t item_size = 1; /* size of items in bytes */
- if(size > H5_STDIO_MAX_IO_BYTES_g)
+ if (size > H5_STDIO_MAX_IO_BYTES_g)
bytes_in = H5_STDIO_MAX_IO_BYTES_g;
else
bytes_in = size;
bytes_wrote = fwrite(buf, item_size, bytes_in, file->fp);
- if(bytes_wrote != bytes_in || (0 == bytes_wrote && ferror(file->fp))) { /* error */
- file->op = H5FD_STDIO_OP_UNKNOWN;
+ if (bytes_wrote != bytes_in || (0 == bytes_wrote && ferror(file->fp))) { /* error */
+ file->op = H5FD_STDIO_OP_UNKNOWN;
file->pos = HADDR_UNDEF;
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fwrite failed", -1)
} /* end if */
@@ -924,7 +925,7 @@ H5FD_stdio_write(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxp
}
/* Update seek optimizing data. */
- file->op = H5FD_STDIO_OP_WRITE;
+ file->op = H5FD_STDIO_OP_WRITE;
file->pos = addr;
/* Update EOF if necessary */
@@ -934,7 +935,6 @@ H5FD_stdio_write(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxp
return 0;
}
-
/*-------------------------------------------------------------------------
* Function: H5FD_stdio_flush
*
@@ -954,8 +954,8 @@ H5FD_stdio_write(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxp
static herr_t
H5FD_stdio_flush(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id, hbool_t closing)
{
- H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
- static const char *func = "H5FD_stdio_flush"; /* Function Name for error reporting */
+ H5FD_stdio_t * file = (H5FD_stdio_t *)_file;
+ static const char *func = "H5FD_stdio_flush"; /* Function Name for error reporting */
/* Quiet the compiler */
dxpl_id = dxpl_id;
@@ -964,21 +964,20 @@ H5FD_stdio_flush(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id, hbool_t closing)
H5Eclear2(H5E_DEFAULT);
/* Only try to flush the file if we have write access */
- if(file->write_access) {
- if(!closing) {
- if(fflush(file->fp) < 0)
+ if (file->write_access) {
+ if (!closing) {
+ if (fflush(file->fp) < 0)
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fflush failed", -1)
- /* Reset last file I/O information */
- file->pos = HADDR_UNDEF;
+ /* Reset last file I/O information */
+ file->pos = HADDR_UNDEF;
file->op = H5FD_STDIO_OP_UNKNOWN;
} /* end if */
- } /* end if */
+ } /* end if */
return 0;
} /* end H5FD_stdio_flush() */
-
/*-------------------------------------------------------------------------
* Function: H5FD_stdio_truncate
*
@@ -997,11 +996,10 @@ H5FD_stdio_flush(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id, hbool_t closing)
*-------------------------------------------------------------------------
*/
static herr_t
-H5FD_stdio_truncate(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id,
- hbool_t /*UNUSED*/ closing)
+H5FD_stdio_truncate(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id, hbool_t /*UNUSED*/ closing)
{
- H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
- static const char *func = "H5FD_stdio_truncate"; /* Function Name for error reporting */
+ H5FD_stdio_t * file = (H5FD_stdio_t *)_file;
+ static const char *func = "H5FD_stdio_truncate"; /* Function Name for error reporting */
/* Quiet the compiler */
dxpl_id = dxpl_id;
@@ -1011,17 +1009,17 @@ H5FD_stdio_truncate(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id,
H5Eclear2(H5E_DEFAULT);
/* Only try to flush the file if we have write access */
- if(file->write_access) {
+ if (file->write_access) {
/* Makes sure that the true file size is the same as the end-of-address. */
- if(file->eoa != file->eof) {
+ if (file->eoa != file->eof) {
#ifdef H5_HAVE_WIN32_API
- LARGE_INTEGER li; /* 64-bit (union) integer for SetFilePointer() call */
- DWORD dwPtrLow; /* Low-order pointer bits from SetFilePointer()
- * Only used as an error code here.
- */
- DWORD dwError; /* DWORD error code from GetLastError() */
- BOOL bError; /* Boolean error flag */
+ LARGE_INTEGER li; /* 64-bit (union) integer for SetFilePointer() call */
+ DWORD dwPtrLow; /* Low-order pointer bits from SetFilePointer()
+ * Only used as an error code here.
+ */
+ DWORD dwError; /* DWORD error code from GetLastError() */
+ BOOL bError; /* Boolean error flag */
/* Reset seek offset to beginning of file, so that file isn't re-extended later */
rewind(file->fp);
@@ -1035,42 +1033,43 @@ H5FD_stdio_truncate(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id,
* from SetFilePointer(), we also need to check GetLastError().
*/
dwPtrLow = SetFilePointer(file->hFile, li.LowPart, &li.HighPart, FILE_BEGIN);
- if(INVALID_SET_FILE_POINTER == dwPtrLow) {
+ if (INVALID_SET_FILE_POINTER == dwPtrLow) {
dwError = GetLastError();
- if(dwError != NO_ERROR )
+ if (dwError != NO_ERROR)
H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_FILEOPEN, "unable to set file pointer", -1)
}
bError = SetEndOfFile(file->hFile);
- if(0 == bError)
- H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "unable to truncate/extend file properly", -1)
-#else /* H5_HAVE_WIN32_API */
+ if (0 == bError)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR,
+ "unable to truncate/extend file properly", -1)
+#else /* H5_HAVE_WIN32_API */
/* Reset seek offset to beginning of file, so that file isn't re-extended later */
rewind(file->fp);
/* Truncate file to proper length */
- if(-1 == file_ftruncate(file->fd, (file_offset_t)file->eoa))
- H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR, "unable to truncate/extend file properly", -1)
+ if (-1 == file_ftruncate(file->fd, (file_offset_t)file->eoa))
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_SEEKERROR,
+ "unable to truncate/extend file properly", -1)
#endif /* H5_HAVE_WIN32_API */
- /* Update the eof value */
- file->eof = file->eoa;
+ /* Update the eof value */
+ file->eof = file->eoa;
/* Reset last file I/O information */
file->pos = HADDR_UNDEF;
- file->op = H5FD_STDIO_OP_UNKNOWN;
+ file->op = H5FD_STDIO_OP_UNKNOWN;
} /* end if */
- } /* end if */
+ } /* end if */
else {
/* Double-check for problems */
- if(file->eoa > file->eof)
+ if (file->eoa > file->eof)
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_TRUNCATED, "eoa > eof!", -1)
} /* end else */
return 0;
} /* end H5FD_stdio_truncate() */
-
/*-------------------------------------------------------------------------
* Function: H5FD_stdio_lock
*
@@ -1090,9 +1089,9 @@ static herr_t
H5FD_stdio_lock(H5FD_t *_file, hbool_t rw)
{
#ifdef H5_HAVE_FLOCK
- H5FD_stdio_t *file = (H5FD_stdio_t*)_file; /* VFD file struct */
- int lock_flags; /* file locking flags */
- static const char *func = "H5FD_stdio_lock"; /* Function Name for error reporting */
+ H5FD_stdio_t * file = (H5FD_stdio_t *)_file; /* VFD file struct */
+ int lock_flags; /* file locking flags */
+ static const char *func = "H5FD_stdio_lock"; /* Function Name for error reporting */
/* Clear the error stack */
H5Eclear2(H5E_DEFAULT);
@@ -1103,20 +1102,21 @@ H5FD_stdio_lock(H5FD_t *_file, hbool_t rw)
lock_flags = rw ? LOCK_EX : LOCK_SH;
/* Place a non-blocking lock on the file */
- if(flock(file->fd, lock_flags | LOCK_NB) < 0) {
- if(ENOSYS == errno)
- H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL, "file locking disabled on this file system (use HDF5_USE_FILE_LOCKING environment variable to override)", -1)
- else
- H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL, "file lock failed", -1)
+ if (flock(file->fd, lock_flags | LOCK_NB) < 0) {
+ if (ENOSYS == errno)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL,
+ "file locking disabled on this file system (use HDF5_USE_FILE_LOCKING environment "
+ "variable to override)",
+ -1) else H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL, "file lock failed", -1)
} /* end if */
/* Flush the stream */
- if(fflush(file->fp) < 0)
+ if (fflush(file->fp) < 0)
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fflush failed", -1)
#endif /* H5_HAVE_FLOCK */
- return 0;
+ return 0;
} /* end H5FD_stdio_lock() */
/*-------------------------------------------------------------------------
@@ -1138,8 +1138,8 @@ static herr_t
H5FD_stdio_unlock(H5FD_t *_file)
{
#ifdef H5_HAVE_FLOCK
- H5FD_stdio_t *file = (H5FD_stdio_t*)_file; /* VFD file struct */
- static const char *func = "H5FD_stdio_unlock"; /* Function Name for error reporting */
+ H5FD_stdio_t * file = (H5FD_stdio_t *)_file; /* VFD file struct */
+ static const char *func = "H5FD_stdio_unlock"; /* Function Name for error reporting */
/* Clear the error stack */
H5Eclear2(H5E_DEFAULT);
@@ -1147,23 +1147,25 @@ H5FD_stdio_unlock(H5FD_t *_file)
assert(file);
/* Flush the stream */
- if(fflush(file->fp) < 0)
+ if (fflush(file->fp) < 0)
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fflush failed", -1)
- /* Place a non-blocking lock on the file */
- if(flock(file->fd, LOCK_UN) < 0) {
- if(ENOSYS == errno)
- H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL, "file locking disabled on this file system (use HDF5_USE_FILE_LOCKING environment variable to override)", -1)
- else
- H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL, "file unlock failed", -1)
- } /* end if */
+ /* Place a non-blocking lock on the file */
+ if (flock(file->fd, LOCK_UN) < 0)
+ {
+ if (ENOSYS == errno)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL,
+ "file locking disabled on this file system (use HDF5_USE_FILE_LOCKING "
+ "environment variable to override)",
+ -1) else H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL, "file unlock failed",
+ -1)
+ } /* end if */
#endif /* H5_HAVE_FLOCK */
return 0;
} /* end H5FD_stdio_unlock() */
-
#ifdef _H5private_H
/*
* This is not related to the functionality of the driver code.
@@ -1172,4 +1174,3 @@ H5FD_stdio_unlock(H5FD_t *_file)
*/
#error "Do not use HDF5 private definitions"
#endif
-