LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_error.c File Reference

Functions

int big_error (int big_error_code, const char *format,...)
 
void warning (int block, const char *format,...)
 
long long lg_log_time ()
 
void lg_set_error_context (const char *file, unsigned int line, const char *func, const char *txt, int code)
 
int lg_get_error_context_code ()
 
const char * lg_get_full_error_context ()
 
void lg_clear_error_context ()
 
void lg_save_error_context (LG_ErrorContext *err_ctx)
 
void lg_restore_error_context (LG_ErrorContext *err_ctx)
 
int lg_push_error_context (LG_ErrorContext *err_ctx)
 
LG_ErrorContextlg_pop_error_context ()
 
void * malloc2_plus (size_t size, const char *file, unsigned int line, const char *func)
 
void free2_plus (void *mem, const char *file, unsigned int line, const char *func)
 
int mkdir_plus (const char *path, mode_t mode, const char *file, unsigned int line, const char *func)
 
FILE * fopen_plus (const char *path, const char *mode, const char *file, unsigned int line, const char *func)
 
void sig_handler (int sig_num, siginfo_t *sig_info, void *context)
 
void set_sig_handler ()
 
void test_big_error (int test)
 

Detailed Description

 === Errors handling ===

 Mem alloc funcs:
 - malloc3()
 - free3()

 TODO: complete the doc

Function Documentation

◆ big_error()

int big_error ( int  big_error_code,
const char *  format,
  ... 
)

This func's prototype is in libetm/error.h. This func is not defined in Libetm but in application and it handles CRITICAL ERRORS from both Libetm and application.

    NUA:

    "*** CRITICAL ERROR ***"
    if (big_error_code > LIBETM_LASTERRORCODE && big_error_code <= LG_LASTERRORCODE) {
            bla bla
    } else if (big_error_code >  LG_LASTERRORCODE) {
            bla bla
    }

◆ warning()

void warning ( int  block,
const char *  format,
  ... 
)

This func's prototype is in libetm/error.h. This func is not defined in Libetm but in application and it handles WARNINGS from both Libetm and application.

Will popup and wait for WARNING_TIMEOUT ms if no_block == TRUE, then close. Otherwise, will block until an appropriate keyboard/mouse action happens.

You can use BLOCK/NO_BLOCK helpers.

◆ lg_log_time()

long long lg_log_time ( )

Log time

◆ lg_set_error_context()

void lg_set_error_context ( const char *  file,
unsigned int  line,
const char *  func,
const char *  txt,
int  code 
)

Set error context

Trying to find a way to trace back error origin

◆ lg_get_error_context_code()

int lg_get_error_context_code ( )

Get error context code

◆ lg_get_full_error_context()

const char* lg_get_full_error_context ( )

Get full error context code

◆ lg_clear_error_context()

void lg_clear_error_context ( )

Clear error context

◆ lg_save_error_context()

void lg_save_error_context ( LG_ErrorContext err_ctx)

Save error context

◆ lg_restore_error_context()

void lg_restore_error_context ( LG_ErrorContext err_ctx)

Restore error context

◆ lg_push_error_context()

int lg_push_error_context ( LG_ErrorContext err_ctx)

Push error context

◆ lg_pop_error_context()

LG_ErrorContext* lg_pop_error_context ( )

Pop error context

◆ malloc2_plus()

void* malloc2_plus ( size_t  size,
const char *  file,
unsigned int  line,
const char *  func 
)

This is experimental - invoked by malloc3() macro

Test with malloc3((size_t)1024 * (size_t)(1024 * 1024 * 1024)), ie requiring 1 TiB of mem

◆ free2_plus()

void free2_plus ( void *  mem,
const char *  file,
unsigned int  line,
const char *  func 
)

This is experimental - invoked by free3() macro

◆ mkdir_plus()

int mkdir_plus ( const char *  path,
mode_t  mode,
const char *  file,
unsigned int  line,
const char *  func 
)

This is experimental - invoked by mkdir_2() macro

=== BUGGY SO NOT USED SO FAR ===

◆ fopen_plus()

FILE* fopen_plus ( const char *  path,
const char *  mode,
const char *  file,
unsigned int  line,
const char *  func 
)

This is experimental - invoked by fopen_2() macro

=== BUGGY SO NOT USED SO FAR ===

◆ sig_handler()

void sig_handler ( int  sig_num,
siginfo_t *  sig_info,
void *  context 
)

Set up the Unix signals handler

 Unix signals (from signal(7) man page)
 LG_BUSERR       // SIGBUS  Bus error (bad memory access)
 LG_FPE          // SIGFPE  Floating-point exception
 LG_ILL          // SIGILL  Illegal Instruction
 LG_SEGFAULT     // SIGSEGV Invalid memory reference

◆ set_sig_handler()

void set_sig_handler ( )

Handling a few Unix signals

◆ test_big_error()

void test_big_error ( int  test)

Testing big_error()