summaryrefslogtreecommitdiffstats
path: root/test/vfd_swmr_common.c
diff options
context:
space:
mode:
authorDavid Young <dyoung@hdfgroup.org>2020-05-06 19:44:59 (GMT)
committerDavid Young <dyoung@hdfgroup.org>2020-05-06 19:44:59 (GMT)
commit696173c28488d13ab85464531c9c52fd12d7ae89 (patch)
tree368c33997a2e84bee1eee4deed6024978d959c4e /test/vfd_swmr_common.c
parentc07a958e1d047bbe33e544a322720843ae3cfce4 (diff)
downloadhdf5-696173c28488d13ab85464531c9c52fd12d7ae89.zip
hdf5-696173c28488d13ab85464531c9c52fd12d7ae89.tar.gz
hdf5-696173c28488d13ab85464531c9c52fd12d7ae89.tar.bz2
Add esnprintf that prints to the given buffer, observing the given
buffer size, using vsnprintf(3), but exits with err(3)/errx(3) if the buffer is too small or if vsnprintf returns < 0.
Diffstat (limited to 'test/vfd_swmr_common.c')
-rw-r--r--test/vfd_swmr_common.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/vfd_swmr_common.c b/test/vfd_swmr_common.c
index 7db2bba..252d6d7 100644
--- a/test/vfd_swmr_common.c
+++ b/test/vfd_swmr_common.c
@@ -34,6 +34,22 @@ static const hid_t badhid = H5I_INVALID_HID;
int verbosity = 2;
void
+esnprintf(char *buf, size_t bufsz, const char *fmt, ...)
+{
+ int rc;
+ va_list ap;
+
+ va_start(ap, fmt);
+ rc = vsnprintf(buf, bufsz, fmt, ap);
+ va_end(ap);
+
+ if (rc < 0)
+ err(EXIT_FAILURE, "%s: vsnprintf", __func__);
+ else if (rc >= bufsz)
+ errx(EXIT_FAILURE, "%s: buffer too small", __func__);
+}
+
+void
dbgf(int level, const char *fmt, ...)
{
va_list ap;