summaryrefslogtreecommitdiffstats
path: root/src/H5FDdirect.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2013-05-21 17:30:54 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2013-05-21 17:30:54 (GMT)
commit424a41f878b9ac91f9411dcabc1b8358c7634ea1 (patch)
tree5361a19a29d57982f7db4e9c5206c6c45bc1cbca /src/H5FDdirect.c
parent7a3f473c04684c756c5398878b8b715320af94c1 (diff)
downloadhdf5-424a41f878b9ac91f9411dcabc1b8358c7634ea1.zip
hdf5-424a41f878b9ac91f9411dcabc1b8358c7634ea1.tar.gz
hdf5-424a41f878b9ac91f9411dcabc1b8358c7634ea1.tar.bz2
[svn-r23713] Description:
Clean up warnings, switch library code to use Standard C/POSIX wrapper macros, remove internal calls to API routines, update checkapi and checkposix scripts. Tested on: Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN Big-Endian Linux/64 (ostrich)
Diffstat (limited to 'src/H5FDdirect.c')
-rw-r--r--src/H5FDdirect.c90
1 files changed, 31 insertions, 59 deletions
diff --git a/src/H5FDdirect.c b/src/H5FDdirect.c
index 9715bc1..079554d 100644
--- a/src/H5FDdirect.c
+++ b/src/H5FDdirect.c
@@ -104,36 +104,8 @@ typedef struct H5FD_direct_t {
} H5FD_direct_t;
/*
- * This driver supports systems that have the lseek64() function by defining
- * some macros here so we don't have to have conditional compilations later
- * throughout the code.
- *
- * file_offset_t: The datatype for file offsets, the second argument of
- * the lseek() or lseek64() call.
- *
- * file_seek: The function which adjusts the current file position,
- * either lseek() or lseek64().
- */
-/* adding for windows NT file system support. */
-
-#ifdef H5_HAVE_LSEEK64
-# define file_offset_t off64_t
-# define file_seek lseek64
-# define file_truncate ftruncate64
-#elif defined (H5_HAVE_WIN32_API)
-# /*MSVC*/
-# define file_offset_t __int64
-# define file_seek _lseeki64
-# define file_truncate _chsize
-#else
-# define file_offset_t off_t
-# define file_seek lseek
-# define file_truncate HDftruncate
-#endif
-
-/*
* These macros check for overflow of various quantities. These macros
- * assume that file_offset_t is signed and haddr_t and size_t are unsigned.
+ * assume that HDoff_t is signed and haddr_t and size_t are unsigned.
*
* ADDR_OVERFLOW: Checks whether a file address of type `haddr_t'
* is too large to be represented by the second argument
@@ -146,13 +118,13 @@ typedef struct H5FD_direct_t {
* which can be addressed entirely by the second
* argument of the file seek function.
*/
-#define MAXADDR (((haddr_t)1<<(8*sizeof(file_offset_t)-1))-1)
+#define MAXADDR (((haddr_t)1<<(8*sizeof(HDoff_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))
+ (HDoff_t)((A)+(Z))<(HDoff_t)(A))
/* Prototypes */
static herr_t H5FD_direct_term(void);
@@ -454,7 +426,7 @@ H5FD_direct_fapl_copy(const void *_old_fa)
FUNC_ENTER_NOAPI_NOINIT_NOERR
- assert(new_fa);
+ HDassert(new_fa);
/* Copy the general information */
HDmemcpy(new_fa, old_fa, sizeof(H5FD_direct_fapl_t));
@@ -500,7 +472,7 @@ H5FD_direct_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxadd
FUNC_ENTER_NOAPI_NOINIT
/* Sanity check on file offsets */
- assert(sizeof(file_offset_t)>=sizeof(size_t));
+ HDassert(sizeof(HDoff_t)>=sizeof(size_t));
/* Check arguments */
if (!name || !*name)
@@ -568,26 +540,26 @@ H5FD_direct_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxadd
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, NULL, "HDposix_memalign failed")
if(o_flags & O_CREAT) {
- if(write(file->fd, (void*)buf1, sizeof(int))<0) {
- if(write(file->fd, (void*)buf2, file->fa.fbsize)<0)
+ if(HDwrite(file->fd, (void*)buf1, sizeof(int))<0) {
+ if(HDwrite(file->fd, (void*)buf2, file->fa.fbsize)<0)
HGOTO_ERROR(H5E_FILE, H5E_WRITEERROR, NULL, "file system may not support Direct I/O")
else
file->fa.must_align = TRUE;
} else {
file->fa.must_align = FALSE;
- file_truncate(file->fd, (file_offset_t)0);
+ HDftruncate(file->fd, (HDoff_t)0);
}
} else {
- if(read(file->fd, (void*)buf1, sizeof(int))<0) {
- if(read(file->fd, (void*)buf2, file->fa.fbsize)<0)
+ if(HDread(file->fd, (void*)buf1, sizeof(int))<0) {
+ if(HDread(file->fd, (void*)buf2, file->fa.fbsize)<0)
HGOTO_ERROR(H5E_FILE, H5E_READERROR, NULL, "file system may not support Direct I/O")
else
file->fa.must_align = TRUE;
} else {
if(o_flags & O_RDWR) {
- if(file_seek(file->fd, (file_offset_t)0, SEEK_SET) < 0)
+ if(HDlseek(file->fd, (HDoff_t)0, SEEK_SET) < 0)
HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, NULL, "unable to seek to proper position")
- if(write(file->fd, (void *)buf1, sizeof(int))<0)
+ if(HDwrite(file->fd, (void *)buf1, sizeof(int))<0)
file->fa.must_align = TRUE;
else
file->fa.must_align = FALSE;
@@ -911,8 +883,8 @@ H5FD_direct_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, ha
FUNC_ENTER_NOAPI_NOINIT
- assert(file && file->pub.cls);
- assert(buf);
+ HDassert(file && file->pub.cls);
+ HDassert(buf);
/* Check for overflow conditions */
if (HADDR_UNDEF==addr)
@@ -941,7 +913,7 @@ H5FD_direct_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, ha
if(!_must_align || ((addr%_fbsize==0) && (size%_fbsize==0) && ((size_t)buf%_boundary==0))) {
/* Seek to the correct location */
if ((addr!=file->pos || OP_READ!=file->op) &&
- file_seek(file->fd, (file_offset_t)addr, SEEK_SET)<0)
+ HDlseek(file->fd, (HDoff_t)addr, SEEK_SET)<0)
HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position")
/* Read the aligned data in file first, being careful of interrupted
* system calls and partial results. */
@@ -956,8 +928,8 @@ H5FD_direct_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, ha
HDmemset(buf, 0, size);
break;
}
- assert(nbytes>=0);
- assert((size_t)nbytes<=size);
+ HDassert(nbytes>=0);
+ HDassert((size_t)nbytes<=size);
H5_CHECK_OVERFLOW(nbytes,ssize_t,size_t);
size -= (size_t)nbytes;
H5_CHECK_OVERFLOW(nbytes,ssize_t,haddr_t);
@@ -980,7 +952,7 @@ H5FD_direct_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, ha
/* look for the aligned position for reading the data */
HDassert(!(((addr / _fbsize) * _fbsize) % _fbsize));
- if(file_seek(file->fd, (file_offset_t)((addr / _fbsize) * _fbsize),
+ if(HDlseek(file->fd, (HDoff_t)((addr / _fbsize) * _fbsize),
SEEK_SET) < 0)
HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position")
@@ -1099,8 +1071,8 @@ H5FD_direct_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, h
FUNC_ENTER_NOAPI_NOINIT
- assert(file && file->pub.cls);
- assert(buf);
+ HDassert(file && file->pub.cls);
+ HDassert(buf);
/* Check for overflow conditions */
if (HADDR_UNDEF==addr)
@@ -1129,7 +1101,7 @@ H5FD_direct_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, h
if(!_must_align || ((addr%_fbsize==0) && (size%_fbsize==0) && ((size_t)buf%_boundary==0))) {
/* Seek to the correct location */
if ((addr!=file->pos || OP_WRITE!=file->op) &&
- file_seek(file->fd, (file_offset_t)addr, SEEK_SET)<0)
+ HDlseek(file->fd, (HDoff_t)addr, SEEK_SET)<0)
HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position")
while (size>0) {
@@ -1138,8 +1110,8 @@ H5FD_direct_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, h
} while (-1==nbytes && EINTR==errno);
if (-1==nbytes) /* error */
HSYS_GOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed")
- assert(nbytes>0);
- assert((size_t)nbytes<=size);
+ HDassert(nbytes>0);
+ HDassert((size_t)nbytes<=size);
H5_CHECK_OVERFLOW(nbytes,ssize_t,size_t);
size -= (size_t)nbytes;
H5_CHECK_OVERFLOW(nbytes,ssize_t,haddr_t);
@@ -1165,7 +1137,7 @@ H5FD_direct_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, h
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "HDposix_memalign failed")
/* look for the right position for reading or writing the data */
- if(file_seek(file->fd, (file_offset_t)write_addr, SEEK_SET) < 0)
+ if(HDlseek(file->fd, (HDoff_t)write_addr, SEEK_SET) < 0)
HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position")
p3 = buf;
@@ -1207,8 +1179,8 @@ H5FD_direct_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, h
/* Seek to the last block, for reading */
HDassert(!((write_addr + write_size - _fbsize) % _fbsize));
- if(file_seek(file->fd,
- (file_offset_t)(write_addr + write_size - _fbsize),
+ if(HDlseek(file->fd,
+ (HDoff_t)(write_addr + write_size - _fbsize),
SEEK_SET) < 0)
HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position")
} /* end if */
@@ -1218,7 +1190,7 @@ H5FD_direct_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, h
if(p1) {
HDassert(!(read_size % _fbsize));
do {
- nbytes = read(file->fd, p1, read_size);
+ nbytes = HDread(file->fd, p1, read_size);
} while (-1==nbytes && EINTR==errno);
if (-1==nbytes) /* error */
@@ -1245,7 +1217,7 @@ H5FD_direct_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, h
/*look for the aligned position for writing the data*/
HDassert(!(write_addr % _fbsize));
- if(file_seek(file->fd, (file_offset_t)write_addr, SEEK_SET) < 0)
+ if(HDlseek(file->fd, (HDoff_t)write_addr, SEEK_SET) < 0)
HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position")
/*
@@ -1317,7 +1289,7 @@ H5FD_direct_truncate(H5FD_t *_file, hid_t UNUSED dxpl_id, hbool_t UNUSED closing
FUNC_ENTER_NOAPI_NOINIT
- assert(file);
+ HDassert(file);
/* Extend the file to make sure it's large enough */
if (file->eoa!=file->eof) {
@@ -1335,7 +1307,7 @@ H5FD_direct_truncate(H5FD_t *_file, hid_t UNUSED dxpl_id, hbool_t UNUSED closing
if(SetEndOfFile((HANDLE)filehandle)==0)
HGOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to extend file properly")
#else /* H5_HAVE_WIN32_API */
- if (-1==file_truncate(file->fd, (file_offset_t)file->eoa))
+ if (-1==HDftruncate(file->fd, (HDoff_t)file->eoa))
HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to extend file properly")
#endif /* H5_HAVE_WIN32_API */
@@ -1350,7 +1322,7 @@ H5FD_direct_truncate(H5FD_t *_file, hid_t UNUSED dxpl_id, hbool_t UNUSED closing
/*Even though eof is equal to eoa, file is still truncated because Direct I/O
*write introduces some extra data for alignment.
*/
- if (-1==file_truncate(file->fd, (file_offset_t)file->eof))
+ if (-1==HDftruncate(file->fd, (HDoff_t)file->eof))
HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to extend file properly")
}