aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/log.h
blob: ea9aacb1ad36daefb8df9cc33a0f7dbdf7fff768 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#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__);                         \
		fprintf(stderr, __VA_ARGS__);                                                      \
	}

#define print_log(...) printf(__VA_ARGS__)

#endif