-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.c
65 lines (55 loc) · 1.05 KB
/
log.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "input.h"
#include "log.h"
extern int
logInfo(const char *format, ...)
{
#if (defined DEBUG && defined LOG_INFO)
int res;
va_list vl;
va_start(vl, format);
res = vfprintf(stdout, format, vl);
va_end(vl);
return res;
#else
return 0;
#endif
}
extern int
logError(const char *format, ...)
{
#if (defined DEBUG && defined LOG_ERROR)
int res, len;
char *fmt;
va_list vl;
va_start(vl, format);
len = strlen(format);
fmt = (char *) malloc(11 + len);
memcpy(fmt, "[Error > ", 9);
memcpy(fmt + 9, format, len);
memcpy(fmt + 9 + len, "\r\n", 2);
fmt[10 + len] = '\0';
res = vfprintf(stderr, fmt, vl);
va_end(vl);
return res;
#else
return 0;
#endif
}
extern int
flogError(FILE *file, const char *format, ...)
{
#if (defined DEBUG && defined LOG_ERROR)
int res;
va_list vl;
va_start(vl, format);
res = vfprintf(file, format, vl);
va_end(vl);
return res;
#else
return 0;
#endif
}