summaryrefslogtreecommitdiffstats
path: root/src/H5system.c
diff options
context:
space:
mode:
authorDana Robinson <43805+derobins@users.noreply.github.com>2021-08-17 19:55:18 (GMT)
committerGitHub <noreply@github.com>2021-08-17 19:55:18 (GMT)
commitc0ef1fd6de3ff20cc8fc49c05ca71254c784bea6 (patch)
treefb2bdf05e276e3614b3b5c343447cd82f4e6718b /src/H5system.c
parent2bca2ca6f1ef1b60bb8541413c5f2e68ff5549d3 (diff)
downloadhdf5-c0ef1fd6de3ff20cc8fc49c05ca71254c784bea6.zip
hdf5-c0ef1fd6de3ff20cc8fc49c05ca71254c784bea6.tar.gz
hdf5-c0ef1fd6de3ff20cc8fc49c05ca71254c784bea6.tar.bz2
Reverts PR 906 and 907 due to binary compatibility issues (#918)
Diffstat (limited to 'src/H5system.c')
-rw-r--r--src/H5system.c212
1 files changed, 16 insertions, 196 deletions
diff --git a/src/H5system.c b/src/H5system.c
index 56110ea..144e0bc 100644
--- a/src/H5system.c
+++ b/src/H5system.c
@@ -487,7 +487,7 @@ Wsetenv(const char *name, const char *value, int overwrite)
return (int)_putenv_s(name, value);
} /* end Wsetenv() */
-#ifdef H5_HAVE_WIN32_API
+#ifdef H5_HAVE_WINSOCK2_H
#pragma comment(lib, "advapi32.lib")
#endif
@@ -572,12 +572,12 @@ char *
Wgetlogin(void)
{
-#ifdef H5_HAVE_WIN32_API
+#ifdef H5_HAVE_WINSOCK2_H
DWORD bufferCount = WloginBuffer_count;
if (GetUserName(Wlogin_buffer, &bufferCount) != 0)
return (Wlogin_buffer);
else
-#endif
+#endif /* H5_HAVE_WINSOCK2_H */
return NULL;
}
@@ -964,7 +964,10 @@ done:
* Note that commodity hardware is probably going to have a
* resolution of milliseconds, not nanoseconds.
*
- * Return: void
+ * Return: SUCCEED/FAIL
+ *
+ * Programmer: Quincey Koziol
+ * October 01, 2016
*--------------------------------------------------------------------------
*/
void
@@ -973,40 +976,21 @@ H5_nanosleep(uint64_t nanosec)
FUNC_ENTER_NOAPI_NOINIT_NOERR
#ifdef H5_HAVE_WIN32_API
- DWORD dwMilliseconds = (DWORD)HDceil(nanosec / 1.0e6);
- DWORD ignore;
- /* Windows can't sleep at a ns resolution. Best we can do is ~1 ms. We
- * don't care about the return value since the second parameter
- * (bAlertable) is FALSE, so it will always be zero.
+ /* On Windows, Sleep() is in milliseconds. Passing 0 to Sleep()
+ * causes the thread to relinquish the rest of its time slice.
*/
- ignore = SleepEx(dwMilliseconds, FALSE);
+ Sleep(nanosec / (1000 * 1000));
#else
+ {
+ struct timespec sleeptime; /* Struct to hold time to sleep */
- const uint64_t nanosec_per_sec = 1000 * 1000 * 1000;
- struct timespec sleeptime; /* Struct to hold time to sleep */
-
- /* Set up time to sleep
- *
- * Assuming ILP32 or LP64 or wider architecture, (long)operand
- * satisfies 0 <= operand < nanosec_per_sec < LONG_MAX.
- *
- * It's harder to be sure that we don't overflow time_t.
- */
- sleeptime.tv_sec = (time_t)(nanosec / nanosec_per_sec);
- sleeptime.tv_nsec = (long)(nanosec % nanosec_per_sec);
+ /* Set up time to sleep */
+ sleeptime.tv_sec = 0;
+ sleeptime.tv_nsec = (long)nanosec;
- /* Sleep for up to `sleeptime` and, in the event of an interruption,
- * save the unslept time back to `sleeptime`.
- */
- while (HDnanosleep(&sleeptime, &sleeptime) == -1) {
- /* If we were just interrupted, sleep for the remaining time.
- * Otherwise, the error was essentially impossible, so just stop
- * sleeping.
- */
- if (errno != EINTR)
- break;
+ HDnanosleep(&sleeptime, NULL);
}
#endif
@@ -1058,167 +1042,3 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5_expand_windows_env_vars() */
#endif /* H5_HAVE_WIN32_API */
-
-/* Global variables */
-int H5_opterr = 1; /* Get_option prints errors if this is on */
-int H5_optind = 1; /* Token pointer */
-const char *H5_optarg; /* Flag argument (or value) */
-
-/*-------------------------------------------------------------------------
- * Function: H5_get_option
- *
- * Purpose: Determine the command-line options a user specified. We can
- * accept both short and long type command-lines.
- *
- * Return: Success: The short valued "name" of the command line
- * parameter or EOF if there are no more
- * parameters to process.
- *
- * Failure: A question mark.
- *-------------------------------------------------------------------------
- */
-int
-H5_get_option(int argc, const char **argv, const char *opts, const struct h5_long_options *l_opts)
-{
- static int sp = 1; /* character index in current token */
- int optopt = '?'; /* option character passed back to user */
-
- if (sp == 1) {
- /* check for more flag-like tokens */
- if (H5_optind >= argc || argv[H5_optind][0] != '-' || argv[H5_optind][1] == '\0') {
- return EOF;
- }
- else if (HDstrcmp(argv[H5_optind], "--") == 0) {
- H5_optind++;
- return EOF;
- }
- }
-
- if (sp == 1 && argv[H5_optind][0] == '-' && argv[H5_optind][1] == '-') {
- /* long command line option */
- int i;
- const char ch = '=';
- char * arg = HDstrdup(&argv[H5_optind][2]);
- size_t arg_len = 0;
-
- H5_optarg = strchr(&argv[H5_optind][2], ch);
- arg_len = HDstrlen(&argv[H5_optind][2]);
- if (H5_optarg) {
- arg_len -= HDstrlen(H5_optarg);
- H5_optarg++; /* skip the equal sign */
- }
- arg[arg_len] = 0;
-
- for (i = 0; l_opts && l_opts[i].name; i++) {
- if (HDstrcmp(arg, l_opts[i].name) == 0) {
- /* we've found a matching long command line flag */
- optopt = l_opts[i].shortval;
-
- if (l_opts[i].has_arg != no_arg) {
- if (H5_optarg == NULL) {
- if (l_opts[i].has_arg != optional_arg) {
- if (H5_optind < (argc - 1))
- if (argv[H5_optind + 1][0] != '-')
- H5_optarg = argv[++H5_optind];
- }
- else if (l_opts[i].has_arg == require_arg) {
- if (H5_opterr)
- HDfprintf(stderr, "%s: option required for \"--%s\" flag\n", argv[0], arg);
-
- optopt = '?';
- }
- }
- }
- else {
- if (H5_optarg) {
- if (H5_opterr)
- HDfprintf(stderr, "%s: no option required for \"%s\" flag\n", argv[0], arg);
-
- optopt = '?';
- }
- }
- break;
- }
- }
-
- if (l_opts[i].name == NULL) {
- /* exhausted all of the l_opts we have and still didn't match */
- if (H5_opterr)
- HDfprintf(stderr, "%s: unknown option \"%s\"\n", argv[0], arg);
-
- optopt = '?';
- }
-
- H5_optind++;
- sp = 1;
-
- HDfree(arg);
- }
- else {
- register char *cp; /* pointer into current token */
-
- /* short command line option */
- optopt = argv[H5_optind][sp];
-
- if (optopt == ':' || (cp = HDstrchr(opts, optopt)) == 0) {
- if (H5_opterr)
- HDfprintf(stderr, "%s: unknown option \"%c\"\n", argv[0], optopt);
-
- /* if no chars left in this token, move to next token */
- if (argv[H5_optind][++sp] == '\0') {
- H5_optind++;
- sp = 1;
- }
- return '?';
- }
-
- if (*++cp == ':') {
- /* if a value is expected, get it */
- if (argv[H5_optind][sp + 1] != '\0') {
- /* flag value is rest of current token */
- H5_optarg = &argv[H5_optind++][sp + 1];
- }
- else if (++H5_optind >= argc) {
- if (H5_opterr)
- HDfprintf(stderr, "%s: value expected for option \"%c\"\n", argv[0], optopt);
-
- optopt = '?';
- }
- else {
- /* flag value is next token */
- H5_optarg = argv[H5_optind++];
- }
-
- sp = 1;
- }
- /* wildcard argument */
- else if (*cp == '*') {
- /* check the next argument */
- H5_optind++;
- /* we do have an extra argument, check if not last */
- if ((H5_optind + 1) < argc) {
- if (argv[H5_optind][0] != '-') {
- H5_optarg = argv[H5_optind++];
- }
- else {
- H5_optarg = NULL;
- }
- }
- else {
- H5_optarg = NULL;
- }
- }
- else {
- /* set up to look at next char in token, next time */
- if (argv[H5_optind][++sp] == '\0') {
- /* no more in current token, so setup next token */
- H5_optind++;
- sp = 1;
- }
- H5_optarg = NULL;
- }
- }
-
- /* return the current flag character found */
- return optopt;
-}