LibGame v0.4.0
The LG Game Engine - Copyright (C) 2024-2026 ETMSoftware
Loading...
Searching...
No Matches
error.h
1/*
2 * libetm / error.h - Copyright (C) Emmanuel Thomas-Maurin 2008-2026
4 *
5 * - Error handling -
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef INC_LIBETM_ERROR_H
22#define INC_LIBETM_ERROR_H
23
24typedef struct {
25 const int code;
26 const char *str;
27} ErrSt;
28
29/* All libetm error values */
30
31/* Exactly matching this enum and ErrSt array below doesn't matter anymore. */
32typedef enum {
33 LIBETM_OK,
34
35 /* str_mem.c */
36 OUT_OF_MEMORY,
37 ZERO_RQ_SIZE,
38 NEG_RQ_SIZE,
39 NULL_DEST,
40 SRC_EQ_DEST,
41 STR_OVERLAP,
42 NULL_POINTER_FREE,
43 RNDSTR_UNKNOWN_MODE,
44
45 /* tcp_socket.c */
46 TCP_SOCK_ERROR,
47 TCP_SOCK_CANT_CONNECT,
48 TCP_SOCK_SHOULD_BE_CLOSED,
49 SELECT_ERROR,
50 SELECT_TIMED_OUT,
51 SELECT_TRUE,
52 SELECT_FALSE,
53 TCP_SEND_ERROR,
54 TCP_RECV_ERROR,
55
56 CONNECTION_CLOSED_BY_SERVER,
57
58 /* win32_specific.c */
59#ifdef WIN32_V
60 WIN32_ERROR,
61 WIN32REGKEY_NOT_FOUND,
62 WIN32REGKEY_CREATE_ERROR,
63 WIN32REGKEY_SAVE_ERROR,
64 WIN32REGKEY_OTHER_ERROR,
65#endif
66
67 /* Used by applications to enum error codes above this one. */
68 LIBETM_LASTERRORCODE
69} libetm_error_code;
70
71/* Exactly matching this ErrSt array and enum above doesn't matter anymore. */
72static const ErrSt lib_error[] = {
73 {LIBETM_OK, "OK"},
74
75 /* str_mem.c */
76 {OUT_OF_MEMORY, "Out of memory"},
77 {ZERO_RQ_SIZE, "Zero requested size"},
78 {NEG_RQ_SIZE, "Negative requested size"},
79 {NULL_DEST, "Null destination string"},
80 {SRC_EQ_DEST, "Source string = destination string"},
81 {STR_OVERLAP, "Strings overlap"},
82 {NULL_POINTER_FREE, "Attempting to free a null pointer"},
83 {RNDSTR_UNKNOWN_MODE, "Generate random string: Unknown mode"},
84
85 /* tcp_socket.c */
86 {TCP_SOCK_ERROR, "TCP socket error"},
87 {TCP_SOCK_CANT_CONNECT, "TCP socket error: Can't connect"},
88 {TCP_SOCK_SHOULD_BE_CLOSED, "TCP socket error: Should be closed"},
89 {SELECT_ERROR, "Select error"},
90 {SELECT_TIMED_OUT, "Select error: Timed out"},
91 {SELECT_TRUE, "(Not an error) select TRUE"},
92 {SELECT_FALSE, "(Not an error) select FALSE"},
93 {TCP_SEND_ERROR, "TCP send error"},
94 {TCP_RECV_ERROR, "TCP recv error"},
95 {CONNECTION_CLOSED_BY_SERVER, "Connection closed by server"},
96
97 /* win32_specific.c */
98#ifdef WIN32_V
99 {WIN32_ERROR, "Win32 error"},
100 {WIN32REGKEY_NOT_FOUND, "Can't find win32 registry key"},
101 {WIN32REGKEY_CREATE_ERROR, "Can't create win32 registry key"},
102 {WIN32REGKEY_SAVE_ERROR, "Can't save win32 registry key"},
103 {WIN32REGKEY_OTHER_ERROR, "Win32 registry key error (undetermined)"},
104#endif
105
106 /* Used by applications to enum error codes above this one. */
107 {LIBETM_LASTERRORCODE, "Libetm last enumerated error code"}
108};
109
110const char *error_str_from_error_code(const ErrSt [], int, int);
111
112const char *libetm_error_str(libetm_error_code);
113
114/*
115 * In-application-defined CRITICAL ERROR handler prototype.
116 * Error code from application should enum above LIBETM_LASTERRORCODE.
117 * (See error_handler_example.c.)
118 */
119int big_error(int, const char *, ...);
120
121/*
122 * In-application-defined WARNING handler prototype.
123 * Error code from application should enum above LIBETM_LASTERRORCODE.
124 * (See error_handler_example.c.)
125 */
126void warning(int, const char *, ...);
127
128/*
129 * This will call big_error() function defined in application.
130 */
131int big_error_in_lib(libetm_error_code, const char *);
132
133/*
134 * This will call warning() function defined in application.
135 */
136/* Unused/useless so far... */
137void warning_in_lib(int, libetm_error_code, const char *);
138
140#endif /* INC_LIBETM_ERROR_H */
const char * error_str_from_error_code(const ErrSt e_a[], int n_el, int e_c)
Definition error.c:40
const char * libetm_error_str(libetm_error_code e_c)
Definition error.c:57
void warning_in_lib(int wait, libetm_error_code e_c, const char *str)
Definition error.c:90
void dump_libetm_error_codes()
Definition error.c:100
int big_error_in_lib(libetm_error_code e_c, const char *str)
Definition error.c:74
void warning(int block, const char *format,...)
Definition lg_error.c:83
int big_error(int big_error_code, const char *format,...)
Definition lg_error.c:45
Definition error.h:24