diff options
author | David Young <dyoung@hdfgroup.org> | 2020-02-17 16:47:29 (GMT) |
---|---|---|
committer | David Young <dyoung@hdfgroup.org> | 2020-02-17 16:47:29 (GMT) |
commit | 47b79b7422c91e53ae5d87bcda45d52798a64fb6 (patch) | |
tree | e00ad2dc80ba285fb12d7dfa1a7be7402c0f28e6 /test | |
parent | fa2b89c6b0c894915f12a1df594ef8c427adbc2d (diff) | |
parent | b4697f969295245840350e17d75d92a0fdd7e7a9 (diff) | |
download | hdf5-47b79b7422c91e53ae5d87bcda45d52798a64fb6.zip hdf5-47b79b7422c91e53ae5d87bcda45d52798a64fb6.tar.gz hdf5-47b79b7422c91e53ae5d87bcda45d52798a64fb6.tar.bz2 |
Merge pull request #2369 in HDFFV/hdf5 from ~DYOUNG/vs2010:develop to develop
Merged per discussion with Elena.
* commit 'b4697f969295245840350e17d75d92a0fdd7e7a9':
Use HD prefix.
Delete unhelpful comment per Jordan's question.
Make sure that H5TS_thread_id() is available as either a function or a macro in all configurations.
Provide local copies of err(3)- and errx(3)-alike functions for Visual Studio compatibility.
Provide C99/POSIX.1 format strings PRI[doux]{8,16,32,64,MAX,PTR} on systems that are missing <inttypes.h>.
Diffstat (limited to 'test')
-rw-r--r-- | test/thread_id.c | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/test/thread_id.c b/test/thread_id.c index 9b289fa..af36625 100644 --- a/test/thread_id.c +++ b/test/thread_id.c @@ -18,7 +18,6 @@ * 3 No two threads share an ID during their lifetimes. * 4 A thread's ID is available for reuse as soon as it is joined. */ -#include <err.h> /* * Include required headers. This file tests internal library functions, @@ -26,11 +25,42 @@ */ #include "testhdf5.h" +static void my_errx(int, const char *, ...) H5_ATTR_FORMAT(printf, 2, 3); + +static void +my_errx(int code, const char *fmt, ...) +{ + va_list ap; + + (void)HDfprintf(stderr, "thread_id: "); + HDva_start(ap, fmt); + (void)HDvfprintf(stderr, fmt, ap); + HDva_end(ap); + (void)HDfputc('\n', stderr); + HDexit(code); +} + #if defined(H5_HAVE_THREADSAFE) && !defined(H5_HAVE_WIN_THREADS) +static void my_err(int, const char *, ...) H5_ATTR_FORMAT(printf, 2, 3); + +static void +my_err(int code, const char *fmt, ...) +{ + va_list ap; + int errno_copy = errno; + + (void)HDfprintf(stderr, "thread_id: "); + HDva_start(ap, fmt); + (void)HDvfprintf(stderr, fmt, ap); + HDva_end(ap); + (void)HDfprintf(stderr, ": %s\n", HDstrerror(errno_copy)); + HDexit(code); +} + #define threads_failure(_call, _result) do { \ - errx(EXIT_FAILURE, "%s.%d: " #_call ": %s", __func__, \ - __LINE__, strerror(_result)); \ + my_errx(EXIT_FAILURE, "%s.%d: " #_call ": %s", __func__, \ + __LINE__, HDstrerror(_result)); \ } while (false) #define NTHREADS 5 @@ -52,13 +82,13 @@ atomic_printf(const char *fmt, ...) va_end(ap); if (nprinted == -1) - err(EXIT_FAILURE, "%s.%d: vsnprintf", __func__, __LINE__); + my_err(EXIT_FAILURE, "%s.%d: vsnprintf", __func__, __LINE__); else if (nprinted >= (ssize_t)sizeof(buf)) - errx(EXIT_FAILURE, "%s.%d: vsnprintf overflowed", __func__, __LINE__); + my_errx(EXIT_FAILURE, "%s.%d: vsnprintf overflowed", __func__, __LINE__); nwritten = write(STDOUT_FILENO, buf, (size_t)nprinted); if (nwritten < nprinted) { - errx(EXIT_FAILURE, "%s.%d: write error or short write", + my_errx(EXIT_FAILURE, "%s.%d: write error or short write", __func__, __LINE__); } } @@ -114,7 +144,7 @@ main(void) * mutex, etc. */ if (H5open() != SUCCEED) - errx(EXIT_FAILURE, "%s.%d: H5open failed", __func__, __LINE__); + my_errx(EXIT_FAILURE, "%s.%d: H5open failed", __func__, __LINE__); if ((rc = pthread_mutex_init(&used_lock, NULL)) == -1) threads_failure(pthread_mutex_init, rc); @@ -144,7 +174,7 @@ main(void) for (i = 0; i < NTHREADS; i++) { if (!used[i]) // access synchronized by thread create/join - errx(EXIT_FAILURE, "thread ID %d did not run.", i + 1); + my_errx(EXIT_FAILURE, "thread ID %d did not run.", i + 1); } } if ((rc = pthread_barrier_destroy(&barrier)) != 0) |