aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/log.h
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-08-26 06:51:36 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2022-08-26 07:15:45 +0200
commit03223398b38c550533fb8579b599fa84716d41c4 (patch)
tree923debb1480997f17f353bb40ed6f0557265bb17 /src/log.h
parentworker: allow graceful shutdowns (diff)
downloadcimple-03223398b38c550533fb8579b599fa84716d41c4.tar.gz
cimple-03223398b38c550533fb8579b599fa84716d41c4.zip
fix pthread error handling
pthread functions return positive error codes.
Diffstat (limited to 'src/log.h')
-rw-r--r--src/log.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/log.h b/src/log.h
index 03e8856..ea9aacb 100644
--- a/src/log.h
+++ b/src/log.h
@@ -1,16 +1,34 @@
#ifndef __LOG_H__
#define __LOG_H__
+#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
+#define CONCAT_INNER(a, b) a##b
+#define CONCAT(a, b) CONCAT_INNER(a, b)
+
#define print_errno(s) \
{ \
fprintf(stderr, "%s(%d): ", basename(__FILE__), __LINE__); \
perror(s); \
}
+#define pthread_print_errno(var, s) \
+ { \
+ errno = var; \
+ print_errno(s); \
+ var = -var; \
+ }
+
+#define pthread_check(expr, s) \
+ { \
+ int CONCAT(ret, __LINE__) = expr; \
+ if (CONCAT(ret, __LINE__)) \
+ pthread_print_errno(CONCAT(ret, __LINE__), s); \
+ }
+
#define print_error(...) \
{ \
fprintf(stderr, "%s(%d): ", basename(__FILE__), __LINE__); \