From 4e48041a136beef974097a7e4683b308097af84e Mon Sep 17 00:00:00 2001 From: David Young Date: Tue, 28 Apr 2020 08:35:12 -0500 Subject: Move fetch_env_ulong() from vfd_swmr.c to vfd_swmr_common.c for eventual reuse by the zoo writer. --- test/vfd_swmr.c | 30 +----------------------------- test/vfd_swmr_common.c | 29 +++++++++++++++++++++++++++++ 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 -- cgit v0.12