diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2022-08-26 06:51:36 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2022-08-26 07:15:45 +0200 |
commit | 03223398b38c550533fb8579b599fa84716d41c4 (patch) | |
tree | 923debb1480997f17f353bb40ed6f0557265bb17 /src/log.h | |
parent | worker: allow graceful shutdowns (diff) | |
download | cimple-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.h | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -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__); \ |