clean up error header to not use modifiers on each implementation

implementaitons do not need modifiers if the definition already has
these.
Also move the comments to be above the implementations, rather than
behind the definitions.
This commit is contained in:
Quinn
2025-04-14 14:39:44 +02:00
committed by Quinn
parent 76e3547313
commit 7c4ba05eee

View File

@@ -10,11 +10,11 @@
#define ERROR_BUF_SIZE 128
atrb_nonnull(1) atrb_format(printf, 1, 2) static inline void debug(char const*, ...); // prints a '\n' suffixed debug msg to stdout with a maximum buf size of @ref ERROR_BUF_SIZE
atrb_nonnull(1) atrb_format(printf, 1, 2) static inline void info(char const*, ...); // prints a '\n' suffixed info msg to stdout with a maximum buf size of @ref ERROR_BUF_SIZE
atrb_nonnull(1) atrb_format(printf, 1, 2) static inline void warn(char const*, ...); // prints a '\n' suffixed warn msg to stderr with a maximum buf size of @ref ERROR_BUF_SIZE
atrb_nonnull(1) atrb_format(printf, 1, 2) static inline void error(char const*, ...); // prints a '\n' suffixed error msg to stderr with a maximum buf size of @ref ERROR_BUF_SIZE
atrb_nonnull(1) atrb_format(printf, 1, 2) noreturn static inline void fatal(char const*, ...); // prints a '\n' suffixed fatal msg to stderr with a maximum buf size of @ref ERROR_BUF_SIZE and immediately aborts execution
atrb_nonnull(1) atrb_format(printf, 1, 2) static inline void debug(char const*, ...);
atrb_nonnull(1) atrb_format(printf, 1, 2) static inline void info(char const*, ...);
atrb_nonnull(1) atrb_format(printf, 1, 2) static inline void warn(char const*, ...);
atrb_nonnull(1) atrb_format(printf, 1, 2) static inline void error(char const*, ...);
atrb_nonnull(1) atrb_format(printf, 1, 2) noreturn static inline void fatal(char const*, ...);
// macro to write fmt vardiac args to buf
#define WRITE_VA_ARGS(buf, fmt) \
@@ -25,31 +25,36 @@ atrb_nonnull(1) atrb_format(printf, 1, 2) noreturn static inline void fatal(char
va_end(args); \
};
static inline void debug(char const* restrict fmt, ...) {
// prints a '\n' suffixed debug msg to stdout with a maximum buf size of @ref ERROR_BUF_SIZE
void debug(char const* restrict fmt, ...) {
char buf[ERROR_BUF_SIZE] = {0};
WRITE_VA_ARGS(buf, fmt);
printf("\033[95mD: \"%s\"\033[0m\n", buf); // reduced parameter use by not using fprintf
}
static inline void info(char const* fmt, ...) {
// prints a '\n' suffixed info msg to stdout with a maximum buf size of @ref ERROR_BUF_SIZE
void info(char const* fmt, ...) {
char buf[ERROR_BUF_SIZE] = {0};
WRITE_VA_ARGS(buf, fmt);
printf("I: \"%s\"\n", buf);
}
static inline void warn(char const* fmt, ...) {
// prints a '\n' suffixed warn msg to stderr with a maximum buf size of @ref ERROR_BUF_SIZE
void warn(char const* fmt, ...) {
char buf[ERROR_BUF_SIZE] = {0};
WRITE_VA_ARGS(buf, fmt);
fprintf(stderr, "\033[93mW: \"%s\"\033[0m\n", buf);
}
static inline void error(char const* fmt, ...) {
// prints a '\n' suffixed error msg to stderr with a maximum buf size of @ref ERROR_BUF_SIZE
void error(char const* fmt, ...) {
char buf[ERROR_BUF_SIZE] = {0};
WRITE_VA_ARGS(buf, fmt);
fprintf(stderr, "\033[91mE: \"%s\"\033[0m\n", buf);
}
static inline void fatal(char const* fmt, ...) {
// prints a '\n' suffixed fatal msg to stderr with a maximum buf size of @ref ERROR_BUF_SIZE and immediately aborts execution
void fatal(char const* fmt, ...) {
char buf[ERROR_BUF_SIZE] = {0};
WRITE_VA_ARGS(buf, fmt);
fprintf(stderr, "\033[101mF: \"%s\"\033[0m\n", buf);