Implement exit_if_null using variadic macros, fix compilation
This commit is contained in:
19
src/util.c
19
src/util.c
@ -21,6 +21,7 @@
|
||||
#include "data.h"
|
||||
#include "table.h"
|
||||
#include "layout.h"
|
||||
#include "util.h"
|
||||
|
||||
int min(int a, int b) {
|
||||
return (a < b ? a : b);
|
||||
@ -30,24 +31,6 @@ int max(int a, int b) {
|
||||
return (a > b ? a : b);
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks if pointer is NULL and exits the whole program, printing a message to stdout
|
||||
* before with the given format (see printf())
|
||||
*
|
||||
*/
|
||||
void exit_if_null(void *pointer, char *fmt, ...) {
|
||||
va_list args;
|
||||
|
||||
if (pointer != NULL)
|
||||
return;
|
||||
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Prints the message (see printf()) to stderr, then exits the program.
|
||||
*
|
||||
|
Reference in New Issue
Block a user