-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvas-internal.h
71 lines (56 loc) · 1.87 KB
/
vas-internal.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef VAS_INTERNAL_H_
#define VAS_INTERNAL_H_
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#include <errno.h>
#ifndef TEMP_FAILURE_RETRY
#define TEMP_FAILURE_RETRY(expression) do { \
long _ret; \
retry: \
_ret = (long)(expression); \
if (_ret == -1 && errno == EINTR) \
goto retry; \
} while (0);
#endif
#endif
#ifdef __GNUC__
#define likely(cond) __builtin_expect((cond), 1)
#define unlikely(cond) __builtin_expect((cond), 0)
#else
#define likely(cond) cond
#define unlikely(cond) cond
#endif
#define TOSTR_(arg) #arg
#define TOSTR(arg) TOSTR_(arg)
#define require(cond, label) \
do { \
if (unlikely(!(cond))) { \
fprintf(stderr, "failed at %s:%d\n", __FILE__, __LINE__); \
goto label; \
} \
} while (0)
#define vas_exit abort
#define vas_die_on(cond) do { if (cond) vas_exit(); } while (0)
/* strerror isn't thread-safe and strerror_r isn't C89 */
#define vas_report_on(cond, msg) do { \
vas_seterror(); \
if (cond) { \
fputs(__FILE__ ":" TOSTR(__LINE__) ": ", stderr); \
vas_perror(msg); \
} \
} while(0)
#define vas_report(msg) vas_report_on(vas_report_cond, msg)
#if HAVE_LIBPID_H
#include <libpid.h>
#elif HAVE__GETPID
#include <process.h>
#define pid_self _getpid
#elif HAVE_GETPID
#include <sys/types.h>
#include <unistd.h>
#define pid_self getpid
#endif
#endif