forked from hoshir/zebra
-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.c
77 lines (51 loc) · 1.29 KB
/
error.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
/*
File: error.c
Created: June 13, 1998
Modified: November 12, 2001
Author: Gunnar Andersson ([email protected])
Contents: The text-based error handler.
*/
#include "porting.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#ifndef _WIN32_WCE
#include <time.h>
#endif
#include "error.h"
#include "texts.h"
#if defined(_WIN32_WCE) || defined(_MSC_VER)
#include <windows.h>
void
fatal_error( const char *format, ... ) {
va_list arg_ptr;
char sError[128];
WCHAR wcsError[128];
va_start( arg_ptr, format );
vsprintf(sError, format, arg_ptr);
mbstowcs(wcsError, sError, 128);
OutputDebugString(wcsError);
MessageBox(NULL, wcsError, L"Fatal Error", MB_OK);
exit( EXIT_FAILURE );
}
#else /* not Windows CE */
void
fatal_error( const char *format, ... ) {
FILE *stream;
time_t timer;
va_list arg_ptr;
va_start( arg_ptr, format );
fprintf( stderr, "\n%s: ", FATAL_ERROR_TEXT );
vfprintf( stderr, format, arg_ptr );
va_end( arg_ptr );
stream = fopen( "zebra.err", "a" );
if ( stream != NULL ) {
time( &timer );
fprintf( stream, "%s @ %s\n ", FATAL_ERROR_TEXT, ctime( &timer ) );
va_start( arg_ptr, format );
vfprintf( stream, format, arg_ptr );
va_end( arg_ptr );
}
exit( EXIT_FAILURE );
}
#endif