summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2021-03-25 07:57:21 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2021-03-25 07:57:21 (GMT)
commit2cf9bed55281db81dda891435535d34b4f8bbec3 (patch)
treedf16ca92642f378bac219abc654d216bcea2fcc7
parent1dbb83aabd9404f4b626e19193b7472a653ed8f5 (diff)
downloadhdf5-2cf9bed55281db81dda891435535d34b4f8bbec3.zip
hdf5-2cf9bed55281db81dda891435535d34b4f8bbec3.tar.gz
hdf5-2cf9bed55281db81dda891435535d34b4f8bbec3.tar.bz2
Brings Windows file locking from develop
-rw-r--r--src/H5system.c61
-rw-r--r--src/H5timer.c10
-rw-r--r--src/H5win32defs.h63
3 files changed, 48 insertions, 86 deletions
diff --git a/src/H5system.c b/src/H5system.c
index 8577912..65053ab 100644
--- a/src/H5system.c
+++ b/src/H5system.c
@@ -717,8 +717,8 @@ H5_make_time(struct tm *tm)
* VS 2015 is removed, with _get_timezone replacing it.
*/
long timezone = 0;
-#endif /* defined(H5_HAVE_VISUAL_STUDIO) && (_MSC_VER >= 1900) */
- time_t ret_value; /* Return value */
+#endif /* defined(H5_HAVE_VISUAL_STUDIO) && (_MSC_VER >= 1900) */
+ time_t ret_value = 0; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -962,40 +962,43 @@ Wgetlogin(void)
*-------------------------------------------------------------------------
*/
int
-Wflock(int H5_ATTR_UNUSED fd, int H5_ATTR_UNUSED operation)
+Wflock(int fd, int operation)
{
-/* This is a no-op while we implement a Win32 VFD */
-#if 0
-int
-Wflock(int fd, int operation) {
-
- HANDLE hFile;
- DWORD dwFlags = LOCKFILE_FAIL_IMMEDIATELY;
- DWORD dwReserved = 0;
- /* MAXDWORD for entire file */
- DWORD nNumberOfBytesToLockLow = MAXDWORD;
- DWORD nNumberOfBytesToLockHigh = MAXDWORD;
- /* Must initialize OVERLAPPED struct */
- OVERLAPPED overlapped = {0};
+ HANDLE hFile;
+ DWORD dwFlags = LOCKFILE_FAIL_IMMEDIATELY;
+ DWORD dwReserved = 0;
+ /* MAXDWORD locks the entire file */
+ DWORD nNumberOfBytesToLockLow = MAXDWORD;
+ DWORD nNumberOfBytesToLockHigh = MAXDWORD;
+ /* Must initialize OVERLAPPED struct */
+ OVERLAPPED overlapped = {0};
/* Get Windows HANDLE */
- hFile = _get_osfhandle(fd);
+ if (INVALID_HANDLE_VALUE == (hFile = (HANDLE)_get_osfhandle(fd)))
+ return -1;
/* Convert to Windows flags */
- if(operation & LOCK_EX)
+ if (operation & LOCK_EX)
dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
/* Lock or unlock */
- if(operation & LOCK_UN)
- if(0 == UnlockFileEx(hFile, dwReserved, nNumberOfBytesToLockLow,
- nNumberOfBytesToLockHigh, &overlapped))
- return -1;
- else
- if(0 == LockFileEx(hFile, dwFlags, dwReserved, nNumberOfBytesToLockLow,
- nNumberOfBytesToLockHigh, &overlapped))
+ if (operation & LOCK_UN) {
+ if (0 ==
+ UnlockFileEx(hFile, dwReserved, nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh, &overlapped)) {
+ /* Attempting to unlock an already unlocked file will fail and this can happen
+ * in H5Fstart_swmr_write(). For now, just ignore the "error" (error code: 0x9e / 158).
+ */
+ if (GetLastError() != 158)
+ return -1;
+ }
+ }
+ else {
+ if (0 == LockFileEx(hFile, dwFlags, dwReserved, nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh,
+ &overlapped))
return -1;
-#endif /* 0 */
+ }
+
return 0;
} /* end Wflock() */
@@ -1013,7 +1016,7 @@ Wflock(int fd, int operation) {
*
*-------------------------------------------------------------------------
*/
-const wchar_t *
+wchar_t *
H5_get_utf16_str(const char *s)
{
int nwchars = -1; /* Length of the UTF-16 buffer */
@@ -1109,7 +1112,7 @@ int
Wremove_utf8(const char *path)
{
wchar_t *wpath = NULL; /* UTF-16 version of the path */
- int ret;
+ int ret = -1;
/* Convert the input UTF-8 path to UTF-16 */
if (NULL == (wpath = H5_get_utf16_str(path)))
@@ -1262,7 +1265,7 @@ done:
herr_t
H5_combine_path(const char *path1, const char *path2, char **full_name /*out*/)
{
- size_t path1_len; /* length of path1 */
+ size_t path1_len = 0; /* length of path1 */
size_t path2_len; /* length of path2 */
herr_t ret_value = SUCCEED; /* Return value */
diff --git a/src/H5timer.c b/src/H5timer.c
index 61f8b67..ac3a01e 100644
--- a/src/H5timer.c
+++ b/src/H5timer.c
@@ -14,7 +14,7 @@
/*-------------------------------------------------------------------------
* Created: H5timer.c
* Aug 21 2006
- * Quincey Koziol <koziol@hdfgroup.org>
+ * Quincey Koziol
*
* Purpose: Internal, platform-independent 'timer' support routines.
*
@@ -582,10 +582,10 @@ H5_timer_get_time_string(double seconds)
char *s; /* output string */
/* Used when the time is greater than 59 seconds */
- double days;
- double hours;
- double minutes;
- double remainder_sec;
+ double days = 0.0;
+ double hours = 0.0;
+ double minutes = 0.0;
+ double remainder_sec = 0.0;
/* Extract larger time units from count of seconds */
if (seconds > (double)60.0F) {
diff --git a/src/H5win32defs.h b/src/H5win32defs.h
index 0aadecb..0617643 100644
--- a/src/H5win32defs.h
+++ b/src/H5win32defs.h
@@ -11,59 +11,18 @@
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-/* Programmer: Scott Wegner
- * June 3, 2008
- *
- * Purpose: This file is used to map HDF macros to Windows functions. This
+/* Purpose: This file is used to map HDF macros to Windows functions. This
* should get included H5private mappings, so as to override them.
* Any macro not mapped here, however, will receive a similar mapping
* inside H5private.h
*
*/
-#ifndef H5_HAVE_INTTYPES_H
-/* The following definitions should be suitable for 64-bit Windows, which is
- * LLP64, and for 32-bit Windows, which is ILP32. Those are the only
- * platforms where <inttypes.h> is likely to be missing. VS2015 and later
- * *may* provide these definitions.
- */
-#ifdef _WIN64
-#define PRIdPTR "lld"
-#define PRIoPTR "llo"
-#define PRIuPTR "llu"
-#define PRIxPTR "llx"
-#else /* _WIN64 */
-#define PRIdPTR "ld"
-#define PRIoPTR "lo"
-#define PRIuPTR "lu"
-#define PRIxPTR "lx"
-#endif /* _WIN64 */
-#define PRId8 "d"
-#define PRIo8 "o"
-#define PRIu8 "u"
-#define PRIx8 "x"
-#define PRId16 "d"
-#define PRIo16 "o"
-#define PRIu16 "u"
-#define PRIx16 "x"
-#define PRId32 "d"
-#define PRIo32 "o"
-#define PRIu32 "u"
-#define PRIx32 "x"
-#define PRId64 "lld"
-#define PRIo64 "llo"
-#define PRIu64 "llu"
-#define PRIx64 "llx"
-#define PRIdMAX "lld"
-#define PRIoMAX "llo"
-#define PRIuMAX "llu"
-#define PRIxMAX "llx"
-#endif
-
-/*
- * _MSC_VER = 1900 VS2015
- * _MSC_VER = 1800 VS2013
- * _MSC_VER = 1700 VS2012
+/* _MSC_VER = 192x VS2019
+ * _MSC_VER = 191x VS2017
+ * _MSC_VER = 1900 VS2015
+ * _MSC_VER = 1800 VS2013
+ * _MSC_VER = 1700 VS2012
*/
#ifdef H5_HAVE_WIN32_API
@@ -112,7 +71,7 @@ typedef __int64 h5_stat_size_t;
#ifdef H5_HAVE_VISUAL_STUDIO
/*
- * The (void*) cast just avoids a compiler warning in H5_HAVE_VISUAL_STUDIO
+ * The (void*) cast just avoids a compiler warning in MSVC
*/
#define HDmemset(X, C, Z) memset((void *)(X), C, Z)
@@ -131,10 +90,10 @@ H5_DLL int Wsetenv(const char *name, const char *value, int overwrite);
H5_DLL int Wflock(int fd, int operation);
H5_DLL char * Wgetlogin(void);
H5_DLL herr_t H5_expand_windows_env_vars(char **env_var);
-H5_DLL const wchar_t *H5_get_utf16_str(const char *s);
-H5_DLL int Wopen_utf8(const char *path, int oflag, ...);
-H5_DLL int Wremove_utf8(const char *path);
-H5_DLL int H5_get_win32_times(H5_timevals_t *tvs);
+H5_DLL wchar_t *H5_get_utf16_str(const char *s);
+H5_DLL int Wopen_utf8(const char *path, int oflag, ...);
+H5_DLL int Wremove_utf8(const char *path);
+H5_DLL int H5_get_win32_times(H5_timevals_t *tvs);
#ifdef __cplusplus
}
#endif /* __cplusplus */