Skip to content

Commit

Permalink
Cleans up POSIX/C bits in H5private.h (HDFGroup#804)
Browse files Browse the repository at this point in the history
* Cleans up POSIX/C bits in H5private.h

* Assume difftime exists (C89)
* Reorg AC_CHECK_HEADERS so headers are in alphabetical order
* Split off networking-related AC_CHECK_HEADERS
* Remove unused UNAME_CYGWIN from configure.ac
* Remove checks for unused sys/timeb.h
* Tidying pass over H5private.h HD prefix macros
* Tidy H5win32defs.h
* Add HD prefix to various scanf calls

* Committing clang-format changes

* Fixes to the alarm(2) code used in the tests to make Windows happy

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
derobins and github-actions[bot] committed Jun 30, 2021
1 parent b16dd46 commit f87219f
Show file tree
Hide file tree
Showing 15 changed files with 622 additions and 638 deletions.
2 changes: 0 additions & 2 deletions config/cmake/ConfigureChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ endif ()
# END of WINDOWS Hard code Values
# ----------------------------------------------------------------------

CHECK_FUNCTION_EXISTS (difftime ${HDF_PREFIX}_HAVE_DIFFTIME)

# Find the library containing clock_gettime()
if (MINGW OR NOT WINDOWS)
CHECK_FUNCTION_EXISTS (clock_gettime CLOCK_GETTIME_IN_LIBC)
Expand Down
3 changes: 0 additions & 3 deletions config/cmake/H5pubconf.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@
/* Define if Darwin or Mac OS X */
#cmakedefine H5_HAVE_DARWIN @H5_HAVE_DARWIN@

/* Define to 1 if you have the `difftime' function. */
#cmakedefine H5_HAVE_DIFFTIME @H5_HAVE_DIFFTIME@

/* Define if the direct I/O virtual file driver (VFD) should be compiled */
#cmakedefine H5_HAVE_DIRECT @H5_HAVE_DIRECT@

Expand Down
25 changes: 10 additions & 15 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1225,11 +1225,9 @@ AC_CHECK_LIB([dl], [dlopen])
##

## Unix
AC_CHECK_HEADERS([sys/resource.h sys/time.h unistd.h sys/ioctl.h sys/stat.h])
AC_CHECK_HEADERS([sys/socket.h sys/types.h sys/file.h])
AC_CHECK_HEADERS([features.h])
AC_CHECK_HEADERS([dirent.h])
AC_CHECK_HEADERS([netdb.h netinet/in.h arpa/inet.h])
AC_CHECK_HEADERS([dirent.h features.h unistd.h])
AC_CHECK_HEADERS([sys/file.h sys/ioctl.h sys/resource.h])
AC_CHECK_HEADERS([sys/stat.h sys/time.h sys/types.h])

## Darwin
AC_SUBST([H5_IS_DARWIN])
Expand All @@ -1242,20 +1240,17 @@ case $host_os in
esac

## Windows
## The winsock header is needed for gethostname
AC_CHECK_HEADERS([winsock2.h])
case "`uname`" in
CYGWIN*)
AC_CHECK_HEADERS([sys/timeb.h])
UNAME_CYGWIN="yes"
;;
MINGW*)
AC_CHECK_HEADERS([winsock2.h sys/timeb.h])
AC_HAVE_LIBRARY([ws2_32])
;;
*)
AC_CHECK_HEADERS([winsock2.h sys/timeb.h])
;;
esac

# Mirror VFD networking
AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h sys/socket.h])

## ----------------------------------------------------------------------
## Some platforms require that all symbols are resolved when a library
## is linked. We can use the -no-undefined flag to tell libtool that
Expand Down Expand Up @@ -2001,12 +1996,12 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
## NOTE: clock_gettime may require linking to the rt or posix4 library
## so we'll search for it before calling AC_CHECK_FUNCS.
AC_SEARCH_LIBS([clock_gettime], [rt posix4])
AC_CHECK_FUNCS([alarm clock_gettime difftime fcntl flock fork])
AC_CHECK_FUNCS([alarm asprintf clock_gettime fcntl flock fork])
AC_CHECK_FUNCS([gethostname getrusage gettimeofday])
AC_CHECK_FUNCS([lstat rand_r random setsysinfo])
AC_CHECK_FUNCS([siglongjmp sigsetjmp sigprocmask])
AC_CHECK_FUNCS([srandom strdup symlink])
AC_CHECK_FUNCS([tmpfile asprintf vasprintf waitpid])
AC_CHECK_FUNCS([tmpfile vasprintf waitpid])

## VFD SWMR (move to main CHECK_FUNCS section at merge time)
AC_CHECK_FUNCS([sigtimedwait timespeccmp])
Expand Down
6 changes: 3 additions & 3 deletions hl/test/test_ds.c
Original file line number Diff line number Diff line change
Expand Up @@ -4964,12 +4964,12 @@ read_data(const char *fname, int ndims, hsize_t *dims, float **buf)
}

for (i = 0, nelms = 1; i < ndims; i++) {
if (fscanf(f, "%s %u", str, &j) && HDferror(f)) {
if (HDfscanf(f, "%s %u", str, &j) && HDferror(f)) {
HDprintf("fscanf error in file %s\n", data_file);
HDfclose(f);
return -1;
} /* end if */
if (fscanf(f, "%d", &n) < 0 && HDferror(f)) {
if (HDfscanf(f, "%d", &n) < 0 && HDferror(f)) {
HDprintf("fscanf error in file %s\n", data_file);
HDfclose(f);
return -1;
Expand All @@ -4987,7 +4987,7 @@ read_data(const char *fname, int ndims, hsize_t *dims, float **buf)
}

for (j = 0; j < nelms; j++) {
if (fscanf(f, "%f", &val) < 0 && HDferror(f)) {
if (HDfscanf(f, "%f", &val) < 0 && HDferror(f)) {
HDprintf("fscanf error in file %s\n", data_file);
HDfclose(f);
return -1;
Expand Down
24 changes: 12 additions & 12 deletions hl/test/test_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,11 @@ test_generate(void)
!
*/

if (fscanf(f, "%d %d %d", &imax, &jmax, &kmax) < 0 && HDferror(f)) {
if (HDfscanf(f, "%d %d %d", &imax, &jmax, &kmax) < 0 && HDferror(f)) {
HDprintf("fscanf error in file %s.\n", data_file);
goto out;
} /* end if */
if (fscanf(f, "%f %f %f", &valex, &xmin, &xmax) < 0 && HDferror(f)) {
if (HDfscanf(f, "%f %f %f", &valex, &xmin, &xmax) < 0 && HDferror(f)) {
HDprintf("fscanf error in file %s.\n", data_file);
goto out;
} /* end if */
Expand Down Expand Up @@ -615,7 +615,7 @@ test_generate(void)
goto out;

for (i = 0; i < n_elements; i++) {
if (fscanf(f, "%f ", &value) < 0 && HDferror(f)) {
if (HDfscanf(f, "%f ", &value) < 0 && HDferror(f)) {
HDprintf("fscanf error in file %s.\n", data_file);
goto out;
} /* end if */
Expand Down Expand Up @@ -779,32 +779,32 @@ read_data(const char *fname, /*IN*/
goto out;
}

if (fscanf(f, "%s", str) < 0 && HDferror(f)) {
if (HDfscanf(f, "%s", str) < 0 && HDferror(f)) {
HDprintf("fscanf error in file %s.\n", data_file);
goto out;
} /* end if */

if (fscanf(f, "%d", &color_planes) < 0 && HDferror(f)) {
if (HDfscanf(f, "%d", &color_planes) < 0 && HDferror(f)) {
HDprintf("fscanf error in file %s.\n", data_file);
goto out;
} /* end if */

if (fscanf(f, "%s", str) < 0 && HDferror(f)) {
if (HDfscanf(f, "%s", str) < 0 && HDferror(f)) {
HDprintf("fscanf error in file %s.\n", data_file);
goto out;
} /* end if */

if (fscanf(f, "%d", &h) < 0 && HDferror(f)) {
if (HDfscanf(f, "%d", &h) < 0 && HDferror(f)) {
HDprintf("fscanf error in file %s.\n", data_file);
goto out;
} /* end if */

if (fscanf(f, "%s", str) < 0 && HDferror(f)) {
if (HDfscanf(f, "%s", str) < 0 && HDferror(f)) {
HDprintf("fscanf error in file %s.\n", data_file);
goto out;
} /* end if */

if (fscanf(f, "%d", &w) < 0 && HDferror(f)) {
if (HDfscanf(f, "%d", &w) < 0 && HDferror(f)) {
HDprintf("fscanf error in file %s.\n", data_file);
goto out;
} /* end if */
Expand Down Expand Up @@ -838,7 +838,7 @@ read_data(const char *fname, /*IN*/

/* Read data elements */
for (i = 0; i < n_elements; i++) {
if (fscanf(f, "%d", &n) < 0 && HDferror(f)) {
if (HDfscanf(f, "%d", &n) < 0 && HDferror(f)) {
HDprintf("fscanf error in file %s.\n", data_file);
goto out;
} /* end if */
Expand Down Expand Up @@ -936,7 +936,7 @@ read_palette(const char *fname, rgb_t *palette, size_t palette_size)
return -1;
}

if (sscanf(buffer, "%u", &nentries) != 1) {
if (HDsscanf(buffer, "%u", &nentries) != 1) {
HDfclose(file);
return -1;
}
Expand All @@ -950,7 +950,7 @@ read_palette(const char *fname, rgb_t *palette, size_t palette_size)
/* read the palette entries */
for (u = 0; u < nentries; u++) {
/* extract the red, green and blue color components. */
if (fscanf(file, "%u %u %u", &red, &green, &blue) != 3) {
if (HDfscanf(file, "%u %u %u", &red, &green, &blue) != 3) {
HDfclose(file);
return -1;
}
Expand Down
26 changes: 13 additions & 13 deletions java/src/jni/h5util.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,23 +225,23 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_
case sizeof(float): {
float tmp_float = 0.0f;

sscanf(token, "%f", &tmp_float);
HDsscanf(token, "%f", &tmp_float);
HDmemcpy(cptr, &tmp_float, sizeof(float));
break;
}

case sizeof(double): {
double tmp_double = 0.0;

sscanf(token, "%lf", &tmp_double);
HDsscanf(token, "%lf", &tmp_double);
HDmemcpy(cptr, &tmp_double, sizeof(double));
break;
}
#if H5_SIZEOF_LONG_DOUBLE != 0 && H5_SIZEOF_LONG_DOUBLE != H5_SIZEOF_DOUBLE
case sizeof(long double): {
long double tmp_ldouble = 0.0;

sscanf(token, "%Lg", &tmp_ldouble);
HDsscanf(token, "%Lg", &tmp_ldouble);
HDmemcpy(cptr, &tmp_ldouble, sizeof(long double));
break;
}
Expand Down Expand Up @@ -289,11 +289,11 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_
signed char tmp_char = 0;

if (H5T_SGN_NONE == nsign) {
sscanf(token, "%hhu", &tmp_uchar);
HDsscanf(token, "%hhu", &tmp_uchar);
HDmemcpy(cptr, &tmp_uchar, sizeof(unsigned char));
}
else {
sscanf(token, "%hhd", &tmp_char);
HDsscanf(token, "%hhd", &tmp_char);
HDmemcpy(cptr, &tmp_char, sizeof(char));
}

Expand All @@ -305,11 +305,11 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_
short tmp_short = 0;

if (H5T_SGN_NONE == nsign) {
sscanf(token, "%hu", &tmp_ushort);
HDsscanf(token, "%hu", &tmp_ushort);
HDmemcpy(&tmp_ushort, cptr, sizeof(unsigned short));
}
else {
sscanf(token, "%hd", &tmp_short);
HDsscanf(token, "%hd", &tmp_short);
HDmemcpy(&tmp_short, cptr, sizeof(short));
}

Expand All @@ -321,11 +321,11 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_
int tmp_int = 0;

if (H5T_SGN_NONE == nsign) {
sscanf(token, "%u", &tmp_uint);
HDsscanf(token, "%u", &tmp_uint);
HDmemcpy(cptr, &tmp_uint, sizeof(unsigned int));
}
else {
sscanf(token, "%d", &tmp_int);
HDsscanf(token, "%d", &tmp_int);
HDmemcpy(cptr, &tmp_int, sizeof(int));
}

Expand All @@ -338,11 +338,11 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_
long tmp_long = 0;

if (H5T_SGN_NONE == nsign) {
sscanf(token, "%lu", &tmp_ulong);
HDsscanf(token, "%lu", &tmp_ulong);
HDmemcpy(cptr, &tmp_ulong, sizeof(unsigned long));
}
else {
sscanf(token, "%ld", &tmp_long);
HDsscanf(token, "%ld", &tmp_long);
HDmemcpy(cptr, &tmp_long, sizeof(long));
}

Expand All @@ -355,11 +355,11 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_
long long tmp_llong = 0;

if (H5T_SGN_NONE == nsign) {
sscanf(token, fmt_ullong, &tmp_ullong);
HDsscanf(token, fmt_ullong, &tmp_ullong);
HDmemcpy(cptr, &tmp_ullong, sizeof(unsigned long long));
}
else {
sscanf(token, fmt_llong, &tmp_llong);
HDsscanf(token, fmt_llong, &tmp_llong);
HDmemcpy(cptr, &tmp_llong, sizeof(long long));
}

Expand Down
Loading

0 comments on commit f87219f

Please sign in to comment.