-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.cpp
More file actions
34 lines (33 loc) · 753 Bytes
/
log.cpp
File metadata and controls
34 lines (33 loc) · 753 Bytes
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
// log.cpp - diagnostic logging
//
#include "windows.h"
#include "log.h"
#include <stdio.h>
#include <stdarg.h>
#include <new>
void Log(const char* fmt, ...)
{
static char buffer[8192], *bufptr=buffer;
va_list arg_ptr;
va_start( arg_ptr, fmt );
if (_vsnprintf(buffer, sizeof buffer, fmt, arg_ptr) < 0) {
// presumably buffer overflow
const int BIGSIZE = 65536;
bufptr = new char[BIGSIZE];
if (!bufptr) {
throw std::bad_alloc();
}
if (_vsnprintf(bufptr, BIGSIZE, fmt, arg_ptr) < 0) {
delete[] bufptr;
throw "CodeGenerator::emitf buffer overflow";
}
}
fputs(bufptr, stderr);
#ifdef _WIN32
OutputDebugString(bufptr);
#endif
if (bufptr != buffer) {
delete[] bufptr;
}
va_end(arg_ptr);
}