aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/log.h
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-08-26 06:53:49 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2022-08-26 07:15:45 +0200
commit964f8f40639453ddb42aa3d2aea9e1519b2d74cb (patch)
tree65c4e809a514d6a6fba4e2dfdb7df117e5e40e6c /src/log.h
parentfix pthread error handling (diff)
downloadcimple-964f8f40639453ddb42aa3d2aea9e1519b2d74cb.tar.gz
cimple-964f8f40639453ddb42aa3d2aea9e1519b2d74cb.zip
fix macros
do { ... } while (0) is objectively better: https://stackoverflow.com/q/1067226/514684
Diffstat (limited to 'src/log.h')
-rw-r--r--src/log.h16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/log.h b/src/log.h
index ea9aacb..33e3040 100644
--- a/src/log.h
+++ b/src/log.h
@@ -10,30 +10,30 @@
#define CONCAT(a, b) CONCAT_INNER(a, b)
#define print_errno(s) \
- { \
+ do { \
fprintf(stderr, "%s(%d): ", basename(__FILE__), __LINE__); \
perror(s); \
- }
+ } while (0)
#define pthread_print_errno(var, s) \
- { \
+ do { \
errno = var; \
print_errno(s); \
var = -var; \
- }
+ } while (0)
#define pthread_check(expr, s) \
- { \
+ do { \
int CONCAT(ret, __LINE__) = expr; \
if (CONCAT(ret, __LINE__)) \
pthread_print_errno(CONCAT(ret, __LINE__), s); \
- }
+ } while (0)
#define print_error(...) \
- { \
+ do { \
fprintf(stderr, "%s(%d): ", basename(__FILE__), __LINE__); \
fprintf(stderr, __VA_ARGS__); \
- }
+ } while (0)
#define print_log(...) printf(__VA_ARGS__)