LibGame v0.4.0
The LG Game Engine - Copyright (C) 2024-2026 ETMSoftware
Loading...
Searching...
No Matches
lg_error.h
1/*
2 * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2026
3 * All rights reserved
4 */
5
6#ifndef LG_ERROR_H
7#define LG_ERROR_H
8
9long long lg_log_time();
10
11/* Adding timestamps to error logs on Linux */
12/*
13 * TODO: it would be actually more correct to change:
14 * - TIME_FILE_LINE_FUNC_STR to TIME_FILE_LINE_FUNC
15 * and
16 * - TIME_FILE_LINE_FUNC_STR2 to TIME_FILE_LINE_FUNC_STR
17 * but:
18 * - There is already (uncorrectly) FILE_LINE_FUNC_STR in libetm.h
19 * which should be also changed
20 * - It's not working so far
21 */
22#ifndef ANDROID_V
23 #define TIME_FILE_LINE_FUNC_STR "%lld [%s: %d] %s(): ", lg_log_time(), __FILE__ , __LINE__, __func__
24 // STH WRONG HERE - #define TIME_FILE_LINE_FUNC_STR2 "[%lld %s: %d] %s(): %s", lg_log_time(), __FILE__ , __LINE__, __func__
25 #define INFO_ERR2(...) \
26 {\
27 fprintf(STD_ERR, TIME_FILE_LINE_FUNC_STR);\
28 fprintf(STD_ERR, __VA_ARGS__);\
29 fflush(STD_ERR);\
30 }
31#endif
32
33#define LG_ERR_CTX_FILE_MAXLEN 63
34#define LG_ERR_CTX_FUNC_MAXLEN 63
35#define LG_ERR_CTX_TXT_MAXLEN 1023
36#define LG_ERR_CTX_CODE_NA (-100000) /* Really not sure what to pick */
37#define LG_ERR_CTX_STR_MAXLEN 2048 /* Must contain all of the above - for snprintf() */
38#define LG_ERR_CTX_FORMAT "[%s: %d] %s(): %s (code = %d)"
39
40typedef struct {
41 char file[LG_ERR_CTX_FILE_MAXLEN + 1]; /* Not the full path */
42 unsigned int line;
43 char func[LG_ERR_CTX_FUNC_MAXLEN + 1];
44 char txt[LG_ERR_CTX_TXT_MAXLEN + 1];
45 int code;
47
48/* This is actually an almost duplicate of Libetm/error.h: struct ErrSt (code/str) */
49typedef struct {
50 int code;
51 const char *txt;
53
54enum {OOM_MALLOC2_TEST, OOM_MALLOC3_TEST, OOM_MALLOC3_TEST2, INVPTR_FREE2_TEST, INVPTR_FREE3_TEST, SEGFAULT_TEST, DIVBYZERO_TEST};
55
57
59
60void lg_set_error_context(const char *, unsigned int, const char *, const char *, int);
61
63
64const char *lg_get_full_error_context();
65
67
69
71
72#ifndef WIN32_V
73void sig_handler(int, siginfo_t *, void *);
74
75void set_sig_handler();
76
77extern void app_sig_handler(int, const char *);
78#endif
79
81
82void test_big_error(int);
83
84#endif /* LG_ERROR_H */
void set_sig_handler()
Definition lg_error.c:307
void lg_set_error_context(const char *file, unsigned int line, const char *func, const char *txt, int code)
Definition lg_error.c:143
const char * lg_get_full_error_context()
Definition lg_error.c:167
void lg_override_warning_timeout(int timeout)
Definition lg_error.c:115
void lg_clear_error_context()
Definition lg_error.c:180
int lg_get_error_context_code()
Definition lg_error.c:157
void sig_handler(int sig_num, siginfo_t *sig_info, void *context)
Definition lg_error.c:280
void test_big_error(int test)
Definition lg_error.c:387
void lg_print_out_error_codes()
Definition lg_error.c:365
long long lg_log_time()
Definition lg_error.c:131
void lg_reset_warning_timeout()
Definition lg_error.c:123
void lg_restore_error_context(LG_ErrorContext *err_ctx)
Definition lg_error.c:204
void lg_save_error_context(LG_ErrorContext *err_ctx)
Definition lg_error.c:196
Definition lg_error.h:40
Definition lg_error.h:49