66 lines
2.2 KiB
C
66 lines
2.2 KiB
C
#ifndef UTILS_H
|
|
#define UTILS_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
static const size_t VEC_MAX = SIZE_MAX / sizeof(int);
|
|
|
|
#define ERROR_LIST(X) \
|
|
X(SUCCESS, 0, "No Errors Found") \
|
|
X(ERR_ALLOC_FAIL, (1u << 0), "Alloc :- Failed to allocate") \
|
|
X(ERR_VEC_NULL, (1u << 1), "Vector :- Given vector is null") \
|
|
X(ERR_BUF_NULL, (1u << 2), "Buffer :- NULL") \
|
|
X(ERR_SIZE_ZERO, (1u << 3), \
|
|
"Size :- Size is or is less than 0 or invalid") \
|
|
X(ERR_OUT_OF_BOUNDS, (1u << 4), "Bounds:- Value is out of bounds") \
|
|
X(ERR_DOUBLE_BUF, (1u << 5), \
|
|
"Buffer :- Both buffers are copies of each other") \
|
|
X(ERR_SIZE_OVERFLOW, (1u << 6), \
|
|
"Max :- Vector Max value is overloaded") \
|
|
X(ERR_ORIGIN_UNALTERABLE, (1u << 7), \
|
|
"Origin :- Origin is non-null and cannot be overridden") \
|
|
X(ERR_STR_NULL, (1u << 8), "String :- String is null value") \
|
|
X(ERR_ERR_T_NULL, (1u << 9), "ERR_T :- Passed error is null")
|
|
|
|
typedef enum
|
|
{
|
|
#define X(name, val, desc) name = (val),
|
|
ERROR_LIST(X)
|
|
#undef X
|
|
} ERROR_CODES;
|
|
|
|
/* NOTE
|
|
* Value is the return value for functions like _vec_char_capacity
|
|
* Err is the unsigned bit range for all the errors tracked
|
|
* origin is a string for where the bug started and IS CHANGED ONLY WHEN NULL
|
|
* */
|
|
|
|
typedef struct
|
|
{
|
|
unsigned int flags;
|
|
char* origin; // Where the main bug started
|
|
} err_t;
|
|
|
|
#define ERR_T_INIT { .flags = 0, .origin = NULL }
|
|
#define VEC_INIT \
|
|
{ .array = NULL, .size = 0, .capacity = 0, .max_size = VEC_MAX }
|
|
|
|
void
|
|
vec_print_errs(const err_t err);
|
|
|
|
void
|
|
vec_print_bits(unsigned int num);
|
|
|
|
size_t
|
|
__origin_override(err_t* status, char* str);
|
|
|
|
__attribute__((overloadable)) size_t
|
|
__null_check(const float* ptr, err_t* status);
|
|
|
|
#define LOG(msg) printf("LOG: %s\n", msg) /**< Print log message*/
|
|
#define DEBUG(msg) printf("DEBUG: %s\n", msg) /**< Print debug message*/
|
|
#define find_len(arr) (sizeof(arr) / sizeof((arr)[0]))
|
|
|
|
#endif
|