// Error handling routines, and global structures // Copyright (C) 2000 Core Technologies. // This file is part of e93. // // e93 is free software; you can redistribute it and/or modify // it under the terms of the e93 LICENSE AGREEMENT. // // e93 is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // e93 LICENSE AGREEMENT for more details. // // You should have received a copy of the e93 LICENSE AGREEMENT // along with e93; see the file "LICENSE.TXT". #include "includes.h" static char errorTraceBuffer[2][1024]; // ping-pong error trace buffers static unsigned int errorTraceIndex; void SetError(const char *format,...) // Add error description to the start of the error trace buffer { va_list args; char tempBuffer[1024]; va_start(args,format); if(errorTraceBuffer[errorTraceIndex][0]) // see if something already in the buffer { vsnprintf(tempBuffer,sizeof(tempBuffer),format,args); // make temp string snprintf(&errorTraceBuffer[errorTraceIndex^1][0],sizeof(errorTraceBuffer[0]),"%s; %s",tempBuffer,&errorTraceBuffer[errorTraceIndex][0]); // make the string errorTraceIndex^=1; // flip to the other buffer } else { vsnprintf(&errorTraceBuffer[errorTraceIndex][0],sizeof(errorTraceBuffer[0]),format,args); // build string directly into error buffer } va_end(args); } void SetStdCLibError() // When an error occurs within a standard C library function, call this // and it will turn the standard C library information into an extended library // error { SetError("%s",strerror(errno)); } const char *GetErrorTrace() // Return a pointer to the error trace string. { return(&errorTraceBuffer[errorTraceIndex][0]); } void ClearErrorTrace() // Clear the error trace { errorTraceBuffer[0][0]='\0'; // clear out the error trace buffer errorTraceIndex=0; } void UnInitErrors() // Undo whatever InitErrors did. { } bool InitErrors() // Initialize the error handling code. // If there is a problem return false. // If false is returned, it is NOT legal to call GetError to find out what failed, // You just have to report that the initialization failed. { ClearErrorTrace(); return(true); }