oas/src/error.h
omicron af66790cff Clean up error definitions, location and expose them in the headers
- Exposes all errors in the header file so any user of the api can test
   for the specific error conditions
 - Mark all static error pointers as const
 - Move generic errors into error.h
 - Name all errors err_modulename_* for errors that belong to a specific
   module and err_* for generic errors.
2025-04-05 01:37:04 +02:00

27 lines
559 B
C

#ifndef INCLUDE_SRC_ERROR_H_
#define INCLUDE_SRC_ERROR_H_
#include <stdlib.h>
typedef struct error {
char *message;
bool is_heap_allocated;
} error_t;
error_t *errorf(const char *fmt, ...);
static inline void error_free(error_t *err) {
if (err == nullptr)
return;
if (!err->is_heap_allocated)
return;
free(err->message);
free(err);
}
/* Some global errors */
extern error_t *const err_allocation_failed;
extern error_t *const err_eof;
extern error_t *const err_unknown_read_failure;
#endif // INCLUDE_SRC_ERROR_H_