infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
error.c
Go to the documentation of this file.
1
22#include <infix/infix.h>
23#include <stdarg.h>
24#include <string.h>
25
26// Use the same thread-local storage mechanism as the test harness for consistency.
27#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
28#define INFIX_TLS _Thread_local
29#elif defined(__GNUC__) || defined(__clang__)
30#define INFIX_TLS __thread
31#elif defined(_MSC_VER)
32#define INFIX_TLS __declspec(thread)
33#else
34#define INFIX_TLS
35#endif
36
37// The thread-local variable that stores the last error.
39
51
58 long system_code,
59 const char * msg) {
64 if (msg) {
65 strncpy(g_infix_last_error.message, msg, sizeof(g_infix_last_error.message) - 1);
67 }
68 else
70}
71
83
void _infix_set_error(infix_error_category_t category, infix_error_code_t code, size_t position)
Sets the thread-local error details for a library-internal error.
Definition error.c:44
void _infix_set_system_error(infix_error_category_t category, infix_error_code_t code, long system_code, const char *msg)
Sets the thread-local error details for an error originating from the OS.
Definition error.c:56
void _infix_clear_error(void)
Resets the thread-local error state. Called at the start of every public API function.
Definition error.c:76
static INFIX_TLS infix_error_details_t g_infix_last_error
Definition error.c:38
#define INFIX_TLS
Definition error.c:34
infix_error_code_t
Specific error codes providing detailed information about a failure.
Definition infix.h:1055
infix_error_details_t infix_get_last_error(void)
Public API function to retrieve the last error.
Definition error.c:87
infix_error_category_t
Broad categories for errors that can occur in the library.
Definition infix.h:1039
@ INFIX_CODE_SUCCESS
The operation completed successfully.
Definition infix.h:1057
@ INFIX_CATEGORY_NONE
No error.
Definition infix.h:1040
Declarations for internal-only functions, types, and constants.
A structure holding detailed information about the last error that occurred on the current thread.
Definition infix.h:1093
size_t position
For parser errors, the 0-based index in the input string where the error occurred.
Definition infix.h:1096
infix_error_category_t category
The general category of the error.
Definition infix.h:1094
char message[256]
For descriptive strings (dlerror(), etc.)
Definition infix.h:1098
long system_error_code
For OS-level errors (errno, GetLastError())
Definition infix.h:1097
infix_error_code_t code
The specific error code.
Definition infix.h:1095