1 // Error handling routines, and global structures
2 // Copyright (C) 2000 Core Technologies.
3
4 // This file is part of e93.
5 //
6 // e93 is free software; you can redistribute it and/or modify
7 // it under the terms of the e93 LICENSE AGREEMENT.
8 //
9 // e93 is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // e93 LICENSE AGREEMENT for more details.
13 //
14 // You should have received a copy of the e93 LICENSE AGREEMENT
15 // along with e93; see the file "LICENSE.TXT".
16
17 #include "includes.h"
18
19 static char
20 errorTraceBuffer[2][1024]; // ping-pong error trace buffers
21 static unsigned int
22 errorTraceIndex;
23
SetError(const char * format,...)24 void SetError(const char *format,...)
25 // Add error description to the start of the error trace buffer
26 {
27 va_list
28 args;
29 char
30 tempBuffer[1024];
31
32 va_start(args,format);
33 if(errorTraceBuffer[errorTraceIndex][0]) // see if something already in the buffer
34 {
35 vsnprintf(tempBuffer,sizeof(tempBuffer),format,args); // make temp string
36 snprintf(&errorTraceBuffer[errorTraceIndex^1][0],sizeof(errorTraceBuffer[0]),"%s; %s",tempBuffer,&errorTraceBuffer[errorTraceIndex][0]); // make the string
37 errorTraceIndex^=1; // flip to the other buffer
38 }
39 else
40 {
41 vsnprintf(&errorTraceBuffer[errorTraceIndex][0],sizeof(errorTraceBuffer[0]),format,args); // build string directly into error buffer
42 }
43 va_end(args);
44 }
45
SetStdCLibError()46 void SetStdCLibError()
47 // When an error occurs within a standard C library function, call this
48 // and it will turn the standard C library information into an extended library
49 // error
50 {
51 SetError("%s",strerror(errno));
52 }
53
GetErrorTrace()54 const char *GetErrorTrace()
55 // Return a pointer to the error trace string.
56 {
57 return(&errorTraceBuffer[errorTraceIndex][0]);
58 }
59
ClearErrorTrace()60 void ClearErrorTrace()
61 // Clear the error trace
62 {
63 errorTraceBuffer[0][0]='\0'; // clear out the error trace buffer
64 errorTraceIndex=0;
65 }
66
UnInitErrors()67 void UnInitErrors()
68 // Undo whatever InitErrors did.
69 {
70 }
71
InitErrors()72 bool InitErrors()
73 // Initialize the error handling code.
74 // If there is a problem return false.
75 // If false is returned, it is NOT legal to call GetError to find out what failed,
76 // You just have to report that the initialization failed.
77 {
78 ClearErrorTrace();
79 return(true);
80 }
81
82