-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.h
73 lines (64 loc) · 2.31 KB
/
scripts.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
72
73
#if !defined(UTIL_SCRIPTS_SCRIPTS_H)
#define UTIL_SCRIPTS_SCRIPTS_H
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <estats/estats.h>
#define Chk(x) \
do { \
err = (x); \
if (err != NULL) { \
goto Cleanup; \
} \
} while (0)
/* we need a different macro that does not go to Cleanup, but just to the end of the loop */
#define Chk2(x) \
do { \
err = (x); \
if (err != NULL) { \
printf(" ... saw error \"%s\" (error code %d) at %s:%d in function %s (\"%s\")\n", \
estats_error_get_message(err), \
estats_error_get_number(err), \
__FILE__, \
__LINE__, \
__FUNCTION__, \
estats_error_get_extra(err)); \
estats_error_free(&err); \
goto Continue; \
} \
} while (0)
/* we need a different macro that does not go to Cleanup, but just to the end of the loop */
#define Chk2Ign(x) \
do { \
err = (x); \
if (err != NULL) { \
estats_error_free(&err); \
goto Continue; \
} \
} while (0)
#define ChkIgn(x) \
do { \
err = (x); \
if (err != NULL) { \
estats_error_free(&err); \
goto Cleanup; \
} \
} while (0)
#define SWAP(x, y) \
do { \
typeof(x) tmp; \
tmp = x; \
x = y; \
y = tmp; \
} while (0)
#define PRINT_AND_FREE(err) \
do { \
estats_error_print(stderr, err); \
estats_error_free(&err); \
} while (0)
#endif /* !defined(UTIL_SCRIPTS_SCRIPTS_H) */