Commit | Line | Data |
---|---|---|
0458ed8c | 1 | /* |
9d16b343 | 2 | * Copyright (C) 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
0458ed8c | 3 | * |
9d16b343 | 4 | * SPDX-License-Identifier: LGPL-2.1-only |
0458ed8c | 5 | * |
0458ed8c JG |
6 | */ |
7 | ||
8 | #ifndef TEST_UTILS_H | |
9 | #define TEST_UTILS_H | |
10 | ||
2a69bf14 | 11 | #include <sys/types.h> |
3fd0ee48 JG |
12 | #include <unistd.h> |
13 | ||
729c1fec SM |
14 | #if defined(__cplusplus) |
15 | extern "C" { | |
16 | #endif | |
17 | ||
28f23191 JG |
18 | #if !defined(__GLIBC__) || \ |
19 | ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE)) | |
d23253ae FD |
20 | |
21 | /* | |
22 | * Version using XSI strerror_r. | |
23 | */ | |
0c818c97 SM |
24 | #define PERROR_NO_LOGGER(msg, args...) \ |
25 | do { \ | |
26 | char _perror_buf[200]; \ | |
27 | strerror_r(errno, _perror_buf, sizeof(_perror_buf)); \ | |
28 | fprintf(stderr, msg ": %s\n", ##args, _perror_buf); \ | |
d23253ae FD |
29 | } while (0); |
30 | #else | |
31 | /* | |
32 | * Version using GNU strerror_r, for linux with appropriate defines. | |
33 | */ | |
28f23191 JG |
34 | #define PERROR_NO_LOGGER(msg, args...) \ |
35 | do { \ | |
36 | char *_perror_buf; \ | |
37 | char _perror_tmp[200]; \ | |
38 | _perror_buf = strerror_r(errno, _perror_tmp, sizeof(_perror_tmp)); \ | |
39 | fprintf(stderr, msg ": %s\n", ##args, _perror_buf); \ | |
d23253ae FD |
40 | } while (0); |
41 | #endif | |
42 | ||
0458ed8c | 43 | int usleep_safe(useconds_t usec); |
b2047add FD |
44 | int create_file(const char *path); |
45 | int wait_on_file(const char *path); | |
2a69bf14 | 46 | int64_t elapsed_time_ns(struct timespec *t1, struct timespec *t2); |
729c1fec SM |
47 | #if defined(__cplusplus) |
48 | } | |
49 | #endif | |
50 | ||
0458ed8c | 51 | #endif /* TEST_UTILS_H */ |