diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-18 17:44:00 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-18 17:44:00 -0400 |
commit | 443ae9b89e9e1534407c2dd273a4e47ddb3610c7 (patch) | |
tree | 174fb2183b500ef9f622dab0cff43d7616730016 /sway | |
parent | 5b6e48987204c0d2298dda2d9b30b4208abdd8d5 (diff) | |
parent | faccaf6112d923533512e1dd868ec4bf0d30e1b5 (diff) | |
download | sway-443ae9b89e9e1534407c2dd273a4e47ddb3610c7.tar.xz |
Merge pull request #72 from minus7/assert
added sway_assert function
Diffstat (limited to 'sway')
-rw-r--r-- | sway/log.c | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -4,6 +4,7 @@ #include <stdlib.h> #include <fcntl.h> #include <unistd.h> +#include <signal.h> int colored = 1; int v = 0; @@ -32,7 +33,7 @@ void sway_log_colors(int mode) { colored = (mode == 1) ? 1 : 0; } -void sway_abort(char *format, ...) { +void sway_abort(const char *format, ...) { fprintf(stderr, "ERROR: "); va_list args; va_start(args, format); @@ -42,7 +43,7 @@ void sway_abort(char *format, ...) { exit(1); } -void sway_log(int verbosity, char* format, ...) { +void sway_log(int verbosity, const char* format, ...) { if (verbosity <= v) { int c = verbosity; if (c > sizeof(verbosity_colors) / sizeof(char *)) { @@ -64,3 +65,20 @@ void sway_log(int verbosity, char* format, ...) { fprintf(stderr, "\n"); } } + +bool sway_assert(bool condition, const char* format, ...) { + if (condition) { + return true; + } + +#ifndef NDEBUG + raise(SIGABRT); +#endif + + va_list args; + va_start(args, format); + sway_log(L_ERROR, format, args); + va_end(args); + + return false; +} |