-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdebug.h
57 lines (49 loc) · 2.01 KB
/
debug.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
#ifndef _DEBUG_H
#define _DEBUG_H
#include <cstdio>
#include <ctime>
#include <cstring>
#include "platform.h"
#include <unistd.h>
#include <fcntl.h>
#define USE_STDOUT false
#define PRINTOUT(x) \
{ \
SAVE_ERROR(save_error_var); \
int fh=USE_STDOUT?1:open(LOGFILE,O_WRONLY|O_APPEND); \
if (fh==-1) printf("ERROR: in open, fh==-1 => errno=%d\n", errno); \
time_t t=time(NULL); \
char tt[100]; \
strcpy(tt,ctime(&t)); \
tt[strlen(tt)-1]='\0'; \
write(fh,tt,(unsigned int)strlen(tt)); \
write(fh,": ",2); \
char str_buf[1000]; \
x; \
write(fh,str_buf,(unsigned int)strlen(str_buf)); \
if(!USE_STDOUT) \
{ \
close(fh); \
} \
RESTORE_ERROR(save_error_var); \
}
#define DEBUG0RAW(x) \
{ \
SAVE_ERROR(save_error_var); \
int fh=USE_STDOUT?1:open(LOGFILE,O_WRONLY|O_APPEND); \
char str_buf[1000]; \
x; \
write(fh,str_buf,(unsigned int)strlen(str_buf)); \
if(!USE_STDOUT) \
{ \
close(fh); \
} \
RESTORE_ERROR(save_error_var); \
}
#define DEBUG0(x) PRINTOUT(x)
#define DEBUG10(x) PRINTOUT(x)
#define DEBUG20(x) PRINTOUT(x)
//#define DEBUG30(x) PRINTOUT(x)
#define DEBUG30(x)
#define REPORT_HOOK(x) PRINTOUT(sprintf(str_buf,"SAL: IN HOOK %s\n", (x)))
#endif // _DEBUG_H