diff options
author | Dana Robinson <derobins@hdfgroup.org> | 2017-04-28 22:13:22 (GMT) |
---|---|---|
committer | Dana Robinson <derobins@hdfgroup.org> | 2017-04-28 22:13:22 (GMT) |
commit | 734aebc39538039c6e81db63edd68eb3a2029cd2 (patch) | |
tree | a97a60916799024ba2646e7770ded47320d444c4 /src | |
parent | d3b664b6a79508d78974a347a9d450e72defb76b (diff) | |
download | hdf5-734aebc39538039c6e81db63edd68eb3a2029cd2.zip hdf5-734aebc39538039c6e81db63edd68eb3a2029cd2.tar.gz hdf5-734aebc39538039c6e81db63edd68eb3a2029cd2.tar.bz2 |
Rework of the POSIX file open permissions and macros to clean up
HDopen() calls.
Also fixed a minor const warning in the core VFD.
Diffstat (limited to 'src')
-rw-r--r-- | src/H5Defl.c | 4 | ||||
-rw-r--r-- | src/H5FDcore.c | 10 | ||||
-rw-r--r-- | src/H5FDdirect.c | 2 | ||||
-rw-r--r-- | src/H5FDlog.c | 2 | ||||
-rw-r--r-- | src/H5FDsec2.c | 2 | ||||
-rw-r--r-- | src/H5private.h | 21 | ||||
-rw-r--r-- | src/H5win32defs.h | 5 |
7 files changed, 18 insertions, 28 deletions
diff --git a/src/H5Defl.c b/src/H5Defl.c index 93bf2b2..ebe7689 100644 --- a/src/H5Defl.c +++ b/src/H5Defl.c @@ -288,7 +288,7 @@ H5D__efl_read(const H5O_efl_t *efl, const H5D_t *dset, haddr_t addr, size_t size HGOTO_ERROR(H5E_EFL, H5E_OVERFLOW, FAIL, "external file address overflowed") if(H5_combine_path(dset->shared->extfile_prefix, efl->slot[u].name, &full_name) < 0) HGOTO_ERROR(H5E_EFL, H5E_NOSPACE, FAIL, "can't build external file name") - if((fd = HDopen(full_name, O_RDONLY, H5_POSIX_OPEN_MODE_0000)) < 0) + if((fd = HDopen(full_name, O_RDONLY)) < 0) HGOTO_ERROR(H5E_EFL, H5E_CANTOPENFILE, FAIL, "unable to open external raw data file") if(HDlseek(fd, (HDoff_t)(efl->slot[u].offset + (HDoff_t)skip), SEEK_SET) < 0) HGOTO_ERROR(H5E_EFL, H5E_SEEKERROR, FAIL, "unable to seek in external raw data file") @@ -380,7 +380,7 @@ H5D__efl_write(const H5O_efl_t *efl, const H5D_t *dset, haddr_t addr, size_t siz HGOTO_ERROR(H5E_EFL, H5E_OVERFLOW, FAIL, "external file address overflowed") if(H5_combine_path(dset->shared->extfile_prefix, efl->slot[u].name, &full_name) < 0) HGOTO_ERROR(H5E_EFL, H5E_NOSPACE, FAIL, "can't build external file name") - if((fd = HDopen(full_name, O_CREAT | O_RDWR, H5_POSIX_OPEN_MODE_0666)) < 0) { + if((fd = HDopen(full_name, O_CREAT | O_RDWR, H5_POSIX_CREATE_MODE_RW)) < 0) { if(HDaccess(full_name, F_OK) < 0) HGOTO_ERROR(H5E_EFL, H5E_CANTOPENFILE, FAIL, "external raw data file does not exist") else diff --git a/src/H5FDcore.c b/src/H5FDcore.c index 6c22f69..43d5894 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -598,7 +598,7 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr { int o_flags; H5FD_core_t *file = NULL; - H5FD_core_fapl_t *fa = NULL; + const H5FD_core_fapl_t *fa = NULL; H5P_genplist_t *plist; /* Property list pointer */ #ifdef H5_HAVE_WIN32_API struct _BY_HANDLE_FILE_INFORMATION fileinfo; @@ -620,7 +620,7 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr HDassert(H5P_DEFAULT != fapl_id); if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list") - if(NULL == (fa = (H5FD_core_fapl_t *)H5P_peek_driver_info(plist))) + if(NULL == (fa = (const H5FD_core_fapl_t *)H5P_peek_driver_info(plist))) HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, NULL, "bad VFL driver info") /* Build the open flags */ @@ -638,7 +638,7 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr ((file_image_info.buffer == NULL) && (file_image_info.size == 0))); HDmemset(&sb, 0, sizeof(sb)); if((file_image_info.buffer != NULL) && !(H5F_ACC_CREAT & flags)) { - if(HDopen(name, o_flags, H5_POSIX_OPEN_MODE_0666) >= 0) + if(HDopen(name, o_flags, H5_POSIX_CREATE_MODE_RW) >= 0) HGOTO_ERROR(H5E_FILE, H5E_FILEEXISTS, NULL, "file already exists") /* If backing store is requested, create and stat the file @@ -646,7 +646,7 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr * technically an open. */ if(fa->backing_store) { - if((fd = HDopen(name, o_flags | O_CREAT, H5_POSIX_OPEN_MODE_0666)) < 0) + if((fd = HDopen(name, o_flags | O_CREAT, H5_POSIX_CREATE_MODE_RW)) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to create file") if(HDfstat(fd, &sb) < 0) HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, NULL, "unable to fstat file") @@ -656,7 +656,7 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr * store is off is when the backing_store flag is off and H5F_ACC_CREAT is * on. */ else if(fa->backing_store || !(H5F_ACC_CREAT & flags)) { - if((fd = HDopen(name, o_flags, H5_POSIX_OPEN_MODE_0666)) < 0) + if((fd = HDopen(name, o_flags, H5_POSIX_CREATE_MODE_RW)) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file") if(HDfstat(fd, &sb) < 0) HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, NULL, "unable to fstat file") diff --git a/src/H5FDdirect.c b/src/H5FDdirect.c index 79a5e8a..060947e 100644 --- a/src/H5FDdirect.c +++ b/src/H5FDdirect.c @@ -487,7 +487,7 @@ H5FD_direct_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxadd o_flags |= O_DIRECT; /* Open the file */ - if ((fd=HDopen(name, o_flags, H5_POSIX_OPEN_MODE_0666))<0) + if ((fd = HDopen(name, o_flags, H5_POSIX_CREATE_MODE_RW))<0) HSYS_GOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file") if (HDfstat(fd, &sb)<0) diff --git a/src/H5FDlog.c b/src/H5FDlog.c index 6e5a57b..bccf3cc 100644 --- a/src/H5FDlog.c +++ b/src/H5FDlog.c @@ -520,7 +520,7 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) HDgettimeofday(&timeval_start, NULL); #endif /* H5_HAVE_GETTIMEOFDAY */ /* Open the file */ - if((fd = HDopen(name, o_flags, H5_POSIX_OPEN_MODE_0666)) < 0) { + if((fd = HDopen(name, o_flags, H5_POSIX_CREATE_MODE_RW)) < 0) { int myerrno = errno; HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file: name = '%s', errno = %d, error message = '%s', flags = %x, o_flags = %x", name, myerrno, HDstrerror(myerrno), flags, (unsigned)o_flags); diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c index 71657b6..3bbf592 100644 --- a/src/H5FDsec2.c +++ b/src/H5FDsec2.c @@ -341,7 +341,7 @@ H5FD_sec2_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) o_flags |= O_EXCL; /* Open the file */ - if((fd = HDopen(name, o_flags, H5_POSIX_OPEN_MODE_0666)) < 0) { + if((fd = HDopen(name, o_flags, H5_POSIX_CREATE_MODE_RW)) < 0) { int myerrno = errno; HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file: name = '%s', errno = %d, error message = '%s', flags = %x, o_flags = %x", name, myerrno, HDstrerror(myerrno), flags, (unsigned)o_flags); } /* end if */ diff --git a/src/H5private.h b/src/H5private.h index fc15e99..ca4ebcf 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -495,22 +495,13 @@ # define H5_POSIX_MAX_IO_BYTES SSIZET_MAX #endif -/* POSIX I/O mode used as the fourth parameter to open/_open +/* POSIX I/O mode used as the third parameter to open/_open * when creating a new file (O_CREAT is set). - * - * It's a little awkward to put the Unix file permissions - * in the symbol name, but that is what is most important - * and we only need the symbol to handle Windows' less-capable - * system. */ #if defined(H5_HAVE_WIN32_API) -# define H5_POSIX_OPEN_MODE_0666 (_S_IREAD | _S_IWRITE) -# define H5_POSIX_OPEN_MODE_0644 _S_IREAD -# define H5_POSIX_OPEN_MODE_0000 0 +# define H5_POSIX_CREATE_MODE_RW (_S_IREAD | _S_IWRITE) #else -# define H5_POSIX_OPEN_MODE_0666 0666 -# define H5_POSIX_OPEN_MODE_0644 0644 -# define H5_POSIX_OPEN_MODE_0000 0000 +# define H5_POSIX_CREATE_MODE_RW 0666 #endif /* @@ -1135,11 +1126,7 @@ typedef off_t h5_stat_size_t; #define HDnanosleep(N, O) nanosleep(N, O) #endif /* HDnanosleep */ #ifndef HDopen - #ifdef _O_BINARY - #define HDopen(S,F,M) open(S,F|_O_BINARY,M) - #else - #define HDopen(S,F,M) open(S,F,M) - #endif + #define HDopen(F,...) open(F,__VA_ARGS__) #endif /* HDopen */ #ifndef HDopendir #define HDopendir(S) opendir(S) diff --git a/src/H5win32defs.h b/src/H5win32defs.h index 771b6fc..97f7179 100644 --- a/src/H5win32defs.h +++ b/src/H5win32defs.h @@ -50,8 +50,11 @@ typedef __int64 h5_stat_size_t; /* _O_BINARY must be set in Windows to avoid CR-LF <-> LF EOL * transformations when performing I/O. Note that this will * produce Unix-style text files, though. + * + * Also note that the variadic macro is using a VC++ extension + * where the comma is dropped if nothing is passed to the ellipsis. */ -#define HDopen(S,F,M) _open(S,F|_O_BINARY,M) +#define HDopen(S,F,...) _open(S, F | _O_BINARY, __VA_ARGS__) #define HDread(F,M,Z) _read(F,M,Z) #define HDrmdir(S) _rmdir(S) #define HDsetvbuf(F,S,M,Z) setvbuf(F,S,M,(Z>1?Z:2)) |