summaryrefslogtreecommitdiffstats
path: root/test/vfd_swmr_common.c
diff options
context:
space:
mode:
authorDavid Young <dyoung@hdfgroup.org>2020-04-28 13:35:12 (GMT)
committerDavid Young <dyoung@hdfgroup.org>2020-04-28 13:35:12 (GMT)
commit4e48041a136beef974097a7e4683b308097af84e (patch)
treea269a6f3d41ae368d88bd39e94a2319a4d50c97c /test/vfd_swmr_common.c
parentd16006c45d7d574e8a8f530cc3f4dbd1f3e7e25e (diff)
downloadhdf5-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.
Diffstat (limited to 'test/vfd_swmr_common.c')
-rw-r--r--test/vfd_swmr_common.c29
1 files changed, 29 insertions, 0 deletions
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;
+}