blob: 7f5af2a681e73b262847c56255cf324a6efb9af3 (
plain)
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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#define DEBUGIFY
#include "debugify.h"
#define REDIRECT
static FILE *fout=NULL;
static char fname[128];
static int file_cnt=0; /* count number of open files */
void puts_dbg(const char *data)
{
FILE *fdbg;
fdbg=fopen("dbg.log","a+");
if (fdbg==NULL)
return;
fprintf(fdbg,data);
fclose(fdbg);
}
/* Can't easily get the message back to gdb... write to a log instead. */
void fputs_dbg (const char *data, FILE * fakestream)
{
#ifdef REDIRECT
puts_dbg(data);
#else /* REDIRECT */
//CIOLogView_output (s);
if (fakestream==stdout || fakestream==stderr || fakestream==NULL)
{
if (fout==NULL)
{
for (file_cnt=0; file_cnt<20; file_cnt++)
{
sprintf(fname,"dbg%d.log",file_cnt);
if ((fout=fopen(fname),"r")!=NULL)
fclose(fout);
else
break;
}
fout=fopen(fname,"w");
if (fout==NULL)
return;
}
fakestream=fout;
}
fprintf(fakestream,data);
fflush(fakestream);
#endif /* REDIRECT */
}
void printf_dbg(const char* format,...)
{
va_list args;
char buf[256];
va_start (args, format);
vsprintf (buf, format, args);
puts_dbg(buf);
va_end (args);
}
|