diff options
author | quou <quou@disroot.org> | 2024-06-01 12:19:16 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-06-01 12:20:17 +1000 |
commit | ea7cd94f7aeb177618db3907a6c86b7252e018f0 (patch) | |
tree | e972f9cf590ef756c2e41f3eac5b03e16db08300 /std_printers.c |
Initial commit.
Diffstat (limited to 'std_printers.c')
-rw-r--r-- | std_printers.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/std_printers.c b/std_printers.c new file mode 100644 index 0000000..abb111a --- /dev/null +++ b/std_printers.c @@ -0,0 +1,56 @@ +#include <stdarg.h> +#include <stdio.h> +#include <unistd.h> + +extern int fileno(FILE*); + +void print(const char* fmt, ...) { + va_list args; + va_start(args, fmt); + vfprintf(stdout, fmt, args); + va_end(args); +} + +void print_err(const char* fmt, ...) { + va_list args; + va_start(args, fmt); + + if (isatty(fileno(stderr))) { + fprintf(stderr, "\033[31;31m"); + } + + vfprintf(stderr, fmt, args); + + if (isatty(fileno(stderr))) { + fprintf(stderr, "\033[0m"); + } + + va_end(args); +} + +void print_war(const char* fmt, ...) { + va_list args; + va_start(args, fmt); + + if (isatty(fileno(stderr))) { + fprintf(stderr, "\033[31;35m"); + } + + vfprintf(stderr, fmt, args); + + if (isatty(fileno(stderr))) { + fprintf(stderr, "\033[0m"); + } + + va_end(args); +} + +void pbreak(Error code) { +#if defined(DEBUG) && defined(plat_x86) + __asm__("int3;"); + (void)code; +#else + exit(code); +#endif +} + |