From bd30200dac045ffced8d121c9603547da894776b Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Wed, 28 Jun 2023 16:46:53 -0700 Subject: [PATCH] Remove HD from protected POSIX calls These calls are non-C99 but protected by ifdefs and have no Windows equivalents: * HDalarm * HDasprintf * HDclock_gettime * HDfcntl * HDgethostname * HDgetrusage * HDsymlink --- src/H5private.h | 21 --------------------- src/H5system.c | 2 +- src/H5timer.c | 6 +++--- test/h5test.c | 2 +- test/links.c | 4 ++-- test/testframe.c | 4 ++-- testpar/t_mpi.c | 2 +- tools/lib/h5diff.c | 8 ++++---- tools/test/perform/iopipe.c | 28 ++++++++++++++-------------- 9 files changed, 28 insertions(+), 49 deletions(-) diff --git a/src/H5private.h b/src/H5private.h index 676fb22e1f5..ea28b5187d7 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -614,15 +614,9 @@ typedef off_t h5_stat_size_t; #ifndef HDaccess #define HDaccess(F, M) access(F, M) #endif -#ifndef HDalarm -#define HDalarm(N) alarm(N) -#endif #ifndef HDasctime #define HDasctime(T) asctime(T) #endif -#ifndef HDasprintf -#define HDasprintf asprintf /*varargs*/ -#endif #ifndef HDatexit #define HDatexit(F) atexit(F) #endif @@ -647,9 +641,6 @@ typedef off_t h5_stat_size_t; #ifndef HDclock #define HDclock() clock() #endif -#ifndef HDclock_gettime -#define HDclock_gettime(CID, TS) clock_gettime(CID, TS) -#endif #ifndef HDclose #define HDclose(F) close(F) #endif @@ -683,9 +674,6 @@ typedef off_t h5_stat_size_t; #ifndef HDfclose #define HDfclose(F) fclose(F) #endif -#ifndef HDfcntl -#define HDfcntl(F, C, ...) fcntl(F, C, __VA_ARGS__) -#endif #ifndef HDfdopen #define HDfdopen(N, S) fdopen(N, S) #endif @@ -793,15 +781,9 @@ H5_DLL H5_ATTR_CONST int Nflock(int fd, int operation); #ifndef HDgetenv #define HDgetenv(S) getenv(S) #endif -#ifndef HDgethostname -#define HDgethostname(N, L) gethostname(N, L) -#endif #ifndef HDgetpid #define HDgetpid() getpid() #endif -#ifndef HDgetrusage -#define HDgetrusage(X, S) getrusage(X, S) -#endif /* Don't define HDgets - gets() was deprecated in C99 and removed in C11 */ #ifdef HDgets @@ -1140,9 +1122,6 @@ H5_DLL H5_ATTR_CONST int Nflock(int fd, int operation); #ifndef HDstrtoumax #define HDstrtoumax(S, R, N) strtoumax(S, R, N) #endif -#ifndef HDsymlink -#define HDsymlink(F1, F2) symlink(F1, F2) -#endif #ifndef HDtime #define HDtime(T) time(T) #endif diff --git a/src/H5system.c b/src/H5system.c index 46fea7a29d9..8c0af5548b3 100644 --- a/src/H5system.c +++ b/src/H5system.c @@ -167,7 +167,7 @@ Pflock(int fd, int operation) flk.l_pid = 0; /* not used with set */ /* Lock or unlock */ - if (HDfcntl(fd, F_SETLK, &flk) < 0) + if (fcntl(fd, F_SETLK, &flk) < 0) return -1; return 0; diff --git a/src/H5timer.c b/src/H5timer.c index 89e4fd2cfdf..e1a97fe604a 100644 --- a/src/H5timer.c +++ b/src/H5timer.c @@ -191,7 +191,7 @@ H5_now_usec(void) { struct timespec ts; - HDclock_gettime(CLOCK_MONOTONIC, &ts); + clock_gettime(CLOCK_MONOTONIC, &ts); /* Cast all values in this expression to uint64_t to ensure that all intermediate * calculations are done in 64 bit, to prevent overflow */ @@ -240,7 +240,7 @@ H5_get_time(void) { struct timespec ts; - HDclock_gettime(CLOCK_MONOTONIC, &ts); + clock_gettime(CLOCK_MONOTONIC, &ts); ret_value = (double)ts.tv_sec + ((double)ts.tv_nsec / 1000000000.0); } #elif defined(H5_HAVE_GETTIMEOFDAY) @@ -295,7 +295,7 @@ H5__timer_get_timevals(H5_timevals_t *times /*in,out*/) { struct rusage res; - if (HDgetrusage(RUSAGE_SELF, &res) < 0) + if (getrusage(RUSAGE_SELF, &res) < 0) return -1; times->system = (double)res.ru_stime.tv_sec + ((double)res.ru_stime.tv_usec / 1.0E6); times->user = (double)res.ru_utime.tv_sec + ((double)res.ru_utime.tv_usec / 1.0E6); diff --git a/test/h5test.c b/test/h5test.c index a35d8bfdb02..d7a411648f1 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -958,7 +958,7 @@ h5_show_hostname(void) #endif #ifdef H5_HAVE_GETHOSTNAME - if (HDgethostname(hostname, (size_t)80) < 0) + if (gethostname(hostname, (size_t)80) < 0) printf(" gethostname failed\n"); else printf(" hostname=%s\n", hostname); diff --git a/test/links.c b/test/links.c index eda699e37db..a91186b6421 100644 --- a/test/links.c +++ b/test/links.c @@ -12519,7 +12519,7 @@ external_symlink(const char *env_h5_drvr, hid_t fapl, hbool_t new_format) /* Create symbolic link #1 in temporary directory #1 to file #2 in temporary directory #2 */ /* (i.e. tmp_links/sym1.h5 -> /tmp2_links/extlinks21B.h5) */ - if (HDsymlink(filename2b, SYMLINK1) < 0 && errno != EEXIST) + if (symlink(filename2b, SYMLINK1) < 0 && errno != EEXIST) TEST_ERROR; /* set up name for file #3 in temporary directory #2: "tmp2_links/extlinks21C" */ @@ -12533,7 +12533,7 @@ external_symlink(const char *env_h5_drvr, hid_t fapl, hbool_t new_format) /* Create symbolic link #2 in temporary directory #2 to file #4 in temporary directory #1 */ /* (i.e. tmp2_links/sym2.h5 -> /tmp_links/extlinks21D.h5) */ - if (HDsymlink(filename4b, SYMLINK2) < 0 && errno != EEXIST) + if (symlink(filename4b, SYMLINK2) < 0 && errno != EEXIST) TEST_ERROR; /* set up name for file #5 in temporary directory #1: "tmp_links/extlinks21E" */ diff --git a/test/testframe.c b/test/testframe.c index cd2947b1d1e..b69f42ea0df 100644 --- a/test/testframe.c +++ b/test/testframe.c @@ -646,7 +646,7 @@ TestAlarmOn(void) alarm_sec = (unsigned)HDstrtoul(env_val, (char **)NULL, 10); /* Set the number of seconds before alarm goes off */ - HDalarm((unsigned)alarm_sec); + alarm((unsigned)alarm_sec); #endif } @@ -656,6 +656,6 @@ TestAlarmOff(void) { #ifdef H5_HAVE_ALARM /* Set the number of seconds to zero */ - HDalarm(0); + alarm(0); #endif } diff --git a/testpar/t_mpi.c b/testpar/t_mpi.c index 48d0cc1a506..70a76ecdb32 100644 --- a/testpar/t_mpi.c +++ b/testpar/t_mpi.c @@ -455,7 +455,7 @@ test_mpio_1wMr(char *filename, int special_request) /* show the hostname so that we can tell where the processes are running */ if (VERBOSE_DEF) { #ifdef H5_HAVE_GETHOSTNAME - if (HDgethostname(hostname, sizeof(hostname)) < 0) { + if (gethostname(hostname, sizeof(hostname)) < 0) { printf("gethostname failed\n"); hostname[0] = '\0'; } diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c index cb3295f241d..442fb3e87c5 100644 --- a/tools/lib/h5diff.c +++ b/tools/lib/h5diff.c @@ -706,7 +706,7 @@ h5diff(const char *fname1, const char *fname2, const char *objname1, const char if (HDstrncmp(objname1, "/", 1) != 0) { #ifdef H5_HAVE_ASPRINTF /* Use the asprintf() routine, since it does what we're trying to do below */ - if (HDasprintf(&obj1fullname, "/%s", objname1) < 0) + if (asprintf(&obj1fullname, "/%s", objname1) < 0) H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "name buffer allocation failed"); #else /* H5_HAVE_ASPRINTF */ /* (malloc 2 more for "/" and end-of-line) */ @@ -725,7 +725,7 @@ h5diff(const char *fname1, const char *fname2, const char *objname1, const char if (HDstrncmp(objname2, "/", 1) != 0) { #ifdef H5_HAVE_ASPRINTF /* Use the asprintf() routine, since it does what we're trying to do below */ - if (HDasprintf(&obj2fullname, "/%s", objname2) < 0) + if (asprintf(&obj2fullname, "/%s", objname2) < 0) H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "name buffer allocation failed"); #else /* H5_HAVE_ASPRINTF */ /* (malloc 2 more for "/" and end-of-line) */ @@ -1182,7 +1182,7 @@ diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, hid_t file2_id, /* make full path for obj1 */ #ifdef H5_HAVE_ASPRINTF /* Use the asprintf() routine, since it does what we're trying to do below */ - if (HDasprintf(&obj1_fullpath, "%s%s", grp1_path, table->objs[i].name) < 0) { + if (asprintf(&obj1_fullpath, "%s%s", grp1_path, table->objs[i].name) < 0) { H5TOOLS_ERROR(H5DIFF_ERR, "name buffer allocation failed"); } #else /* H5_HAVE_ASPRINTF */ @@ -1200,7 +1200,7 @@ diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, hid_t file2_id, /* make full path for obj2 */ #ifdef H5_HAVE_ASPRINTF /* Use the asprintf() routine, since it does what we're trying to do below */ - if (HDasprintf(&obj2_fullpath, "%s%s", grp2_path, table->objs[i].name) < 0) { + if (asprintf(&obj2_fullpath, "%s%s", grp2_path, table->objs[i].name) < 0) { H5TOOLS_ERROR(H5DIFF_ERR, "name buffer allocation failed"); } #else /* H5_HAVE_ASPRINTF */ diff --git a/tools/test/perform/iopipe.c b/tools/test/perform/iopipe.c index 8d0daf0c79b..e77e2886612 100644 --- a/tools/test/perform/iopipe.c +++ b/tools/test/perform/iopipe.c @@ -167,7 +167,7 @@ main(void) /* Fill raw */ synchronize(); #ifdef H5_HAVE_GETRUSAGE - HDgetrusage(RUSAGE_SELF, &r_start); + getrusage(RUSAGE_SELF, &r_start); #endif t_start = H5_get_time(); fprintf(stderr, HEADING, "fill raw"); @@ -177,7 +177,7 @@ main(void) HDmemset(the_data, 0xAA, (size_t)(size[0] * size[1])); } #ifdef H5_HAVE_GETRUSAGE - HDgetrusage(RUSAGE_SELF, &r_stop); + getrusage(RUSAGE_SELF, &r_stop); #endif t_stop = H5_get_time(); HDputc('\n', stderr); @@ -190,7 +190,7 @@ main(void) /* Fill hdf5 */ synchronize(); #ifdef H5_HAVE_GETRUSAGE - HDgetrusage(RUSAGE_SELF, &r_start); + getrusage(RUSAGE_SELF, &r_start); #endif t_start = H5_get_time(); fprintf(stderr, HEADING, "fill hdf5"); @@ -201,7 +201,7 @@ main(void) assert(status >= 0); } #ifdef H5_HAVE_GETRUSAGE - HDgetrusage(RUSAGE_SELF, &r_stop); + getrusage(RUSAGE_SELF, &r_stop); #endif t_stop = H5_get_time(); HDputc('\n', stderr); @@ -214,7 +214,7 @@ main(void) /* Write the raw dataset */ synchronize(); #ifdef H5_HAVE_GETRUSAGE - HDgetrusage(RUSAGE_SELF, &r_start); + getrusage(RUSAGE_SELF, &r_start); #endif t_start = H5_get_time(); fprintf(stderr, HEADING, "out raw"); @@ -227,7 +227,7 @@ main(void) assert(n >= 0 && (size_t)n == (size[0] * size[1])); } #ifdef H5_HAVE_GETRUSAGE - HDgetrusage(RUSAGE_SELF, &r_stop); + getrusage(RUSAGE_SELF, &r_stop); #endif t_stop = H5_get_time(); HDputc('\n', stderr); @@ -240,7 +240,7 @@ main(void) /* Write the hdf5 dataset */ synchronize(); #ifdef H5_HAVE_GETRUSAGE - HDgetrusage(RUSAGE_SELF, &r_start); + getrusage(RUSAGE_SELF, &r_start); #endif t_start = H5_get_time(); fprintf(stderr, HEADING, "out hdf5"); @@ -251,7 +251,7 @@ main(void) assert(status >= 0); } #ifdef H5_HAVE_GETRUSAGE - HDgetrusage(RUSAGE_SELF, &r_stop); + getrusage(RUSAGE_SELF, &r_stop); #endif t_stop = H5_get_time(); HDputc('\n', stderr); @@ -264,7 +264,7 @@ main(void) /* Read the raw dataset */ synchronize(); #ifdef H5_HAVE_GETRUSAGE - HDgetrusage(RUSAGE_SELF, &r_start); + getrusage(RUSAGE_SELF, &r_start); #endif t_start = H5_get_time(); fprintf(stderr, HEADING, "in raw"); @@ -277,7 +277,7 @@ main(void) assert(n >= 0 && (size_t)n == (size[0] * size[1])); } #ifdef H5_HAVE_GETRUSAGE - HDgetrusage(RUSAGE_SELF, &r_stop); + getrusage(RUSAGE_SELF, &r_stop); #endif t_stop = H5_get_time(); HDputc('\n', stderr); @@ -290,7 +290,7 @@ main(void) /* Read the hdf5 dataset */ synchronize(); #ifdef H5_HAVE_GETRUSAGE - HDgetrusage(RUSAGE_SELF, &r_start); + getrusage(RUSAGE_SELF, &r_start); #endif t_start = H5_get_time(); fprintf(stderr, HEADING, "in hdf5"); @@ -301,7 +301,7 @@ main(void) assert(status >= 0); } #ifdef H5_HAVE_GETRUSAGE - HDgetrusage(RUSAGE_SELF, &r_stop); + getrusage(RUSAGE_SELF, &r_stop); #endif t_stop = H5_get_time(); HDputc('\n', stderr); @@ -319,7 +319,7 @@ main(void) assert(status >= 0); synchronize(); #ifdef H5_HAVE_GETRUSAGE - HDgetrusage(RUSAGE_SELF, &r_start); + getrusage(RUSAGE_SELF, &r_start); #endif t_start = H5_get_time(); fprintf(stderr, HEADING, "in hdf5 partial"); @@ -330,7 +330,7 @@ main(void) assert(status >= 0); } #ifdef H5_HAVE_GETRUSAGE - HDgetrusage(RUSAGE_SELF, &r_stop); + getrusage(RUSAGE_SELF, &r_stop); #endif t_stop = H5_get_time(); HDputc('\n', stderr);