diff options
author | David Young <dyoung@hdfgroup.org> | 2020-04-28 13:35:12 (GMT) |
---|---|---|
committer | David Young <dyoung@hdfgroup.org> | 2020-04-28 13:35:12 (GMT) |
commit | 4e48041a136beef974097a7e4683b308097af84e (patch) | |
tree | a269a6f3d41ae368d88bd39e94a2319a4d50c97c | |
parent | d16006c45d7d574e8a8f530cc3f4dbd1f3e7e25e (diff) | |
download | hdf5-4e48041a136beef974097a7e4683b308097af84e.zip hdf5-4e48041a136beef974097a7e4683b308097af84e.tar.gz hdf5-4e48041a136beef974097a7e4683b308097af84e.tar.bz2 |
Move fetch_env_ulong() from vfd_swmr.c to vfd_swmr_common.c for eventual
reuse by the zoo writer.
-rw-r--r-- | test/vfd_swmr.c | 30 | ||||
-rw-r--r-- | test/vfd_swmr_common.c | 29 | ||||
-rw-r--r-- | test/vfd_swmr_common.h | 2 |
3 files changed, 32 insertions, 29 deletions
diff --git a/test/vfd_swmr.c b/test/vfd_swmr.c index 96c9cf7..e235db9 100644 --- a/test/vfd_swmr.c +++ b/test/vfd_swmr.c @@ -21,6 +21,7 @@ #include "bsdqueue.h" #include "h5test.h" +#include "vfd_swmr_common.h" /* * This file needs to access private information from the H5F package. @@ -2635,35 +2636,6 @@ error: #define _arraycount(_a) (sizeof(_a)/sizeof(_a[0])) #endif -/* Fetch a variable from the environment and parse it for unsigned long - * content. Return 0 if the variable is not present, -1 if it is present - * but it does not parse and compare less than `limit`, 1 if it's present, - * parses, and is in-bounds. - */ -static int -fetch_env_ulong(const char *varname, unsigned long limit, unsigned long *valp) -{ - char *end; - unsigned long ul; - char *tmp; - - if ((tmp = getenv(varname)) == NULL) - return 0; - - errno = 0; - ul = strtoul(tmp, &end, 0); - if ((ul == ULONG_MAX && errno != 0) || end == tmp || *end != '\0') { - fprintf(stderr, "could not parse %s: %s\n", varname, strerror(errno)); - return -1; - } - if (ul > limit) { - fprintf(stderr, "%s (%lu) out of range\n", varname, ul); - return -1; - } - *valp = ul; - return 1; -} - static unsigned test_shadow_index_lookup(void) { diff --git a/test/vfd_swmr_common.c b/test/vfd_swmr_common.c index 7afd984..c79610d 100644 --- a/test/vfd_swmr_common.c +++ b/test/vfd_swmr_common.c @@ -191,3 +191,32 @@ vfd_swmr_create_fapl(bool writer, bool only_meta_pages, bool use_vfd_swmr) } return fapl; } + +/* Fetch a variable from the environment and parse it for unsigned long + * content. Return 0 if the variable is not present, -1 if it is present + * but it does not parse and compare less than `limit`, 1 if it's present, + * parses, and is in-bounds. + */ +int +fetch_env_ulong(const char *varname, unsigned long limit, unsigned long *valp) +{ + char *end; + unsigned long ul; + char *tmp; + + if ((tmp = getenv(varname)) == NULL) + return 0; + + errno = 0; + ul = strtoul(tmp, &end, 0); + if ((ul == ULONG_MAX && errno != 0) || end == tmp || *end != '\0') { + fprintf(stderr, "could not parse %s: %s\n", varname, strerror(errno)); + return -1; + } + if (ul > limit) { + fprintf(stderr, "%s (%lu) out of range\n", varname, ul); + return -1; + } + *valp = ul; + return 1; +} diff --git a/test/vfd_swmr_common.h b/test/vfd_swmr_common.h index 8eb7143..cd36cc3 100644 --- a/test/vfd_swmr_common.h +++ b/test/vfd_swmr_common.h @@ -98,6 +98,8 @@ H5TEST_DLL hid_t vfd_swmr_create_fapl(bool, bool, bool); H5TEST_DLL void dbgf(int, const char *, ...) H5_ATTR_FORMAT(printf, 2, 3); +H5TEST_DLL int fetch_env_ulong(const char *, unsigned long, unsigned long *); + #ifdef __cplusplus } #endif |