-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcedebug.c
85 lines (65 loc) · 1.53 KB
/
cedebug.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// cedebug.c
//
// Time-stamp: <04/04/02 08:42:36 [email protected]>
#include "celib.h"
int __xcetrace = 0;
HANDLE __xcetracefile;
void
XCETrace(const char *fmt, ...)
{
char buf[1024];
wchar_t wbuf[1024];
int len;
va_list ap;
if(!__xcetrace)
return;
#if 1
len = sprintf(buf, "T%08x: ", GetCurrentThreadId());
#else
len = sprintf(buf, "%08d:%08x: ", GetTickCount(), GetCurrentProcessId());
#endif
va_start(ap, fmt);
vsprintf(buf + len, fmt, ap);
strcat(buf, "\r\n");
if(__xcetracefile)
{
DWORD dwWritten;
SetFilePointer(__xcetracefile, 0, NULL, FILE_END);
WriteFile(__xcetracefile, buf, strlen(buf), &dwWritten, NULL);
FlushFileBuffers(__xcetracefile);
}
else
{
MultiByteToWideChar(CP_ACP, 0, buf, -1, wbuf, 1024);
OutputDebugStringW(wbuf);
}
}
void
XCETraceW(const wchar_t *fmt, ...)
{
wchar_t buf[1024];
va_list ap;
if(!__xcetrace)
return;
va_start(ap, fmt);
vswprintf(buf, fmt, ap);
wcscat(buf, L"\r\n");
OutputDebugStringW(buf);
}
#undef CreateFileW
void
XCEOpenTraceFile(char *fname)
{
wchar_t wfname[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, fname, -1, wfname, COUNTOF(wfname));
__xcetracefile = CreateFileW(wfname, GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS,
0, NULL);
if(__xcetracefile == (HANDLE) -1)
{
__xcetracefile = 0;
return;
}
SetFilePointer(__xcetracefile, 0, NULL, FILE_END);
}