コード例 #1
0
ファイル: SCEError.c プロジェクト: has70/utils
/**
 * \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;
}
コード例 #2
0
ファイル: SCEError.c プロジェクト: has70/utils
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);
}
コード例 #3
0
ファイル: SCEError.c プロジェクト: has70/utils
/**
 * \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);
    }
}
コード例 #4
0
ファイル: SCEError.c プロジェクト: has70/utils
/**
 * \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 ? '.' : ':'));
    }
}
コード例 #5
0
ファイル: SCEError.c プロジェクト: scengine/utils
/**
 * \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--;
    }
}
コード例 #6
0
ファイル: SCEError.c プロジェクト: has70/utils
/**
 * \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);
}
コード例 #7
0
ファイル: SCEError.c プロジェクト: has70/utils
/**
 * \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");
}
コード例 #8
0
ファイル: SCEError.c プロジェクト: has70/utils
/**
 * \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);
}
コード例 #9
0
ファイル: SCEError.c プロジェクト: has70/utils
/**
 * \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);
}