/
utils.h
43 lines (35 loc) · 1.04 KB
/
utils.h
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
41
42
43
#ifndef __UTILS_H__
#define __UTILS_H__
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <syslog.h>
extern int utils_debug;
extern int utils_syslog;
#define log_debug(fmt, args...) \
do { \
if (utils_debug) { \
printf("DEBUG(%s:%i|%s): " fmt "\n", __FILE__, __LINE__, __FUNCTION__, ##args); \
if (utils_syslog) syslog(LOG_DEBUG, "DEBUG(%s:%i|%s): " fmt, __FILE__, __LINE__, __FUNCTION__, ##args); \
} \
} while (0);
#define log_info(fmt, args...) \
do { \
fprintf(stderr, "Notice: " fmt "\n", ##args); \
if (utils_syslog) syslog(LOG_INFO, fmt, ##args); \
} while (0);
#define log_error(fmt, args...) \
do { \
fprintf(stderr, "Error: " fmt " (%s)\n", ##args, strerror(errno)); \
if (utils_syslog) syslog(LOG_ERR, fmt, ##args); \
} while (0);
#define timespec_diff(start, end, diff) \
do { \
if (end.tv_sec > start.tv_sec) \
*(diff) = ((end.tv_sec - start.tv_sec) * 1000000000llu) \
+ end.tv_nsec - start.tv_nsec; \
else \
*(diff) = end.tv_nsec - start.tv_nsec; \
} while (0);
int knet_fdset_cloexec(int fd);
#endif