From a9fefff6203de210093ad23da89cd77c7f61db0f Mon Sep 17 00:00:00 2001 From: David Young Date: Tue, 21 Jul 2020 10:18:43 -0500 Subject: Add evsnprintf for printing a `va_list` to a buffer or aborting the program on an overflow or other error. --- test/vfd_swmr_common.c | 15 +++++++++++---- test/vfd_swmr_common.h | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/test/vfd_swmr_common.c b/test/vfd_swmr_common.c index 036308a..7b1b550 100644 --- a/test/vfd_swmr_common.c +++ b/test/vfd_swmr_common.c @@ -34,14 +34,11 @@ static const hid_t badhid = H5I_INVALID_HID; int verbosity = 2; void -esnprintf(char *buf, size_t bufsz, const char *fmt, ...) +evsnprintf(char *buf, size_t bufsz, const char *fmt, va_list ap) { 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__); @@ -50,6 +47,16 @@ esnprintf(char *buf, size_t bufsz, const char *fmt, ...) } void +esnprintf(char *buf, size_t bufsz, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + evsnprintf(buf, bufsz, fmt, ap); + va_end(ap); +} + +void dbgf(int level, const char *fmt, ...) { va_list ap; diff --git a/test/vfd_swmr_common.h b/test/vfd_swmr_common.h index c6916e6..39572a0 100644 --- a/test/vfd_swmr_common.h +++ b/test/vfd_swmr_common.h @@ -18,6 +18,7 @@ /* Headers */ /***********/ +#include #include "h5test.h" /**********/ @@ -97,6 +98,7 @@ H5TEST_DLL void await_signal(hid_t); 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 void evsnprintf(char *, size_t, const char *, va_list); H5TEST_DLL void esnprintf(char *, size_t, const char *, ...) H5_ATTR_FORMAT(printf, 3, 4); -- cgit v0.12