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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/*
* function: Miscellaneous functions for aacDECdrop
*
* This program is distributed under the GNU General Public License, version 2.
* A copy of this license is included with this source.
*
* Copyright (C) 2002 John Edwards
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include "misc.h"
static char *_filename;
void (*error_handler)(const char *fmt, ...) = error_dialog;
/*
* Set the current input file name.
*/
void set_filename(char *filename)
{
_filename = filename;
}
/*
* Display an error dialog, possibly adding system error information.
*/
void error_dialog(const char *fmt, ...)
{
va_list ap;
char msgbuf[1024];
char *bufp = msgbuf;
/* A really rough sanity check to protect against blatant buffer overrun */
if (strlen(fmt) > 750)
{
sprintf(msgbuf, "%s %s", "<buffer overflow> ", fmt);
}
else
{
if (_filename != NULL && strlen(_filename) < 255)
{
sprintf(msgbuf, "%s: ", _filename);
bufp += strlen(msgbuf);
}
va_start(ap, fmt);
vsprintf(bufp, fmt, ap);
va_end(ap);
if (errno != 0)
{
bufp = msgbuf + strlen(msgbuf);
sprintf(bufp, " error is %s (%d)", strerror(errno), errno);
errno = 0;
}
}
MessageBox(NULL, msgbuf, "Error", 0);
}
void log_error(const char *fmt, ...)
{
va_list ap;
FILE *fp;
char msgbuf[1024];
char *bufp = msgbuf;
/* A really rough sanity check to protect against blatant buffer overrun */
if (strlen(fmt) > 750)
{
sprintf(msgbuf, "%s %s", "<buffer overflow> ", fmt);
}
else
{
if (_filename != NULL && strlen(_filename) < 255)
{
sprintf(msgbuf, "%s : ", _filename);
bufp += strlen(msgbuf);
}
va_start(ap, fmt);
vsprintf(bufp, fmt, ap);
va_end(ap);
if (errno != 0)
{
bufp = msgbuf + strlen(msgbuf);
sprintf(bufp, " error is: %s (%d)", strerror(errno), errno);
errno = 0;
}
}
va_start(ap, fmt);
if ((fp = fopen("oggdrop.log", "a")) == (FILE *)NULL)
return;
fprintf(fp, "%s\n", msgbuf);
fflush(fp);
fclose(fp);
va_end(ap);
}
void set_use_dialogs(int use_dialogs)
{
if (!use_dialogs)
error_handler = error_dialog;
else
error_handler = log_error;
}
/******************************** end of misc.c ********************************/
|