/** * \brief Gets the error code */ int SCE_Error_GetCode (void) { SCE_SError *error = NULL; SCE_SErrorLog *l = SCE_Error_GetLog (); error = &l->errors[l->current]; return error->code; }
void SCE_Error_LogSrcMsg (const char *fmt, ...) { va_list args; SCE_SError *error = NULL; SCE_SErrorLog *l = SCE_Error_GetLog (); error = &l->errors[l->current]; va_start (args, fmt); vsnprintf (error->msg, SCE_MAX_ERROR_MSG_LEN, fmt, args); va_end (args); }
/** * \brief Adds an error source in the current error backtrace. * \param file file where the error occured * \param func func where the error occured * \param line line where the error occured */ void SCE_Error_LogSrc (const char *file, const char *func, unsigned int line) { SCE_SError *error = NULL; SCE_SErrorLog *l = SCE_Error_GetLog (); l->current++; if (l->current < SCE_BACKTRACE_DEPTH) { error = &l->errors[l->current]; error->line = line; strncpy (error->file, file, SCE_MAX_ERROR_INFO_LEN); if (func) strncpy (error->func, func, SCE_MAX_ERROR_INFO_LEN); } }
/** * \brief Soft version of SCE_Error_Out() * \sa SCE_Error_Out() */ void SCE_Error_SoftOut (void) { size_t i = 0; SCE_SError *errors = NULL; SCE_SErrorLog *l = SCE_Error_GetLog (); errors = l->errors; fprintf (stream, "error:\n"); for (i = l->current; i >= 0; i--) { /* only if there is a message available */ if (errors[i].msg[0]) fprintf (stream, " %s%c\n", errors[i].msg, (i == 0 ? '.' : ':')); } }
/** * \brief Adds an error source in the current error backtrace. * \param file file where the error occured * \param func func where the error occured * \param line line where the error occured */ void SCE_Error_LogSrc (const char *file, const char *func, unsigned int line) { SCE_SError *error = NULL; SCE_SErrorLog *l = SCE_Error_GetLog (); l->current++; if (l->current < SCE_BACKTRACE_DEPTH) { error = &l->errors[l->current]; error->line = line; strncpy (error->file, file, SCE_MAX_ERROR_INFO_LEN); if (func) strncpy (error->func, func, SCE_MAX_ERROR_INFO_LEN); } else { SCEE_SendMsg ("logging too much source: %s:%d in %s\n", file, line, func); l->current--; } }
/** * \brief Set error data into \c error * \param file File where the error occured * \param func Function where the error occured * \param line Line where the error occured * \param code Error code */ void SCE_Error_Log (const char *file, const char *func, unsigned int line, int code) { SCE_SError *error = NULL; SCE_SErrorLog *l = SCE_Error_GetLog (); error = l->errors; if (error->code != SCE_NO_ERROR) { SCEE_SendMsg ("SCEError: warning: an error is already logged " "for this thread, consider it erased:\n"); SCEE_Out (); } l->current = 0; error->date = time (NULL); error->line = line; error->code = code; strncpy (error->file, file, SCE_MAX_ERROR_INFO_LEN); if (func) strncpy (error->func, func, SCE_MAX_ERROR_INFO_LEN); SCE_Error_GetCodeMsg (error->code, error->msg, SCE_MAX_ERROR_MSG_LEN); }
/** * \brief Prints the error to the log stream. * * Prints the error in the log stream. This function * prints the backtrace of the error. */ void SCE_Error_Out (void) { const struct tm *time_info = NULL; char date[32] = {0}; int i = 0; SCE_SError *errors = NULL; SCE_SErrorLog *l = SCE_Error_GetLog (); errors = l->errors; time_info = gmtime (&errors[0].date); SCE_Time_MakeString (date, time_info); fprintf (stream, "\n[log %s]\n", date); for (i = l->current; i >= 0; i--) { fprintf (stream, "%s%s:%s (%d): %s%c\n", (i == l->current ? "error: " : " from: "), errors[i].file, errors[i].func, errors[i].line, errors[i].msg, (i == 0 ? '.' : ':')); } fprintf (stream, "[end log]\n"); }
/** * \brief Is any error logged in? */ int SCE_Error_HaveError (void) { SCE_SErrorLog *l = SCE_Error_GetLog (); return (l->errors[0].code != SCE_NO_ERROR); }
/** * \brief Clear error manager * * This function just erases current error, if any. */ void SCE_Error_Clear (void) { SCE_SErrorLog *l = SCE_Error_GetLog (); SCE_Error_InitLog (l); }