mirror of
https://github.com/swaywm/sway.git
synced 2025-11-05 13:29:51 -05:00
added sway_assert function
returns false on a failed assertion in release mode and raises SIGABRT in debug mode
This commit is contained in:
parent
feb0195341
commit
faccaf6112
3 changed files with 24 additions and 5 deletions
22
sway/log.c
22
sway/log.c
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue