-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.h
77 lines (64 loc) · 1.7 KB
/
common.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
74
75
76
77
/******************************************************
* tunelizador http
* common.h
*******************************************************/
#ifndef COMMON_H
#define COMMON_H
#include <errno.h>
/******************
* macros aux
*******************/
#define PROMPT "(unknown) "
// muestra error
#define ERR(...) { \
if (verbose) \
{ \
fprintf(stderr, PROMPT); \
fprintf(stderr, "%s * ", time_stamp()); \
fprintf(stderr, "error: %s, line: %d\n", __FILE__, __LINE__); \
fprintf(stderr, PROMPT); \
fprintf(stderr, "%s * ", time_stamp()); \
} \
fprintf(stderr, "error: "); \
fprintf(stderr, __VA_ARGS__); \
}
// muestra msg
#define MSG(...) if (verbose)\
{ \
printf(PROMPT); \
printf("%s * ", time_stamp()); \
printf(__VA_ARGS__); \
}
// msg error y sale
#define ABORT(...) { \
if (verbose) \
{ \
fprintf(stderr, PROMPT); \
fprintf(stderr, "%s * ", time_stamp()); \
fprintf(stderr, "abort: %s, line: %d\n", __FILE__, __LINE__); \
if (errno) \
{ \
fprintf(stderr, PROMPT); \
fprintf(stderr, "%s * ", time_stamp()); \
perror("abort"); \
} \
fprintf(stderr, PROMPT); \
fprintf(stderr, "%s * ", time_stamp()); \
} \
else perror("abort"); \
fprintf(stderr, "abort: "); \
fprintf(stderr, __VA_ARGS__); \
clean(); exit(-1); \
}
// ejecuta, si -1, sale
#define TRY(x) if ((x) == -1) ABORT("try\n");
/******************
* funciones auxiliares
*******************/
int is_closed(int sock);
void set_handlers();
int xrecv(int s, char *sbuf, int sz_sbuf, int timeout);
unsigned long crono();
void do_exit(int e);
char *time_stamp();
#endif