Implement exit_if_null using variadic macros, fix compilation
This commit is contained in:
parent
57f631b7a7
commit
7216738778
|
@ -15,9 +15,10 @@
|
|||
#ifndef _UTIL_H
|
||||
#define _UTIL_H
|
||||
|
||||
#define exit_if_null(pointer, ...) { if (pointer == NULL) die(__VA_ARGS__); }
|
||||
|
||||
int min(int a, int b);
|
||||
int max(int a, int b);
|
||||
void exit_if_null(void *pointer, char *fmt, ...);
|
||||
void die(char *fmt, ...);
|
||||
void *smalloc(size_t size);
|
||||
char *sstrdup(const char *str);
|
||||
|
|
|
@ -42,10 +42,9 @@ i3Font *load_font(xcb_connection_t *connection, const char *pattern) {
|
|||
info_cookie = xcb_list_fonts_with_info(connection, 1, strlen(pattern), pattern);
|
||||
|
||||
check_error(connection, font_cookie, "Could not open font");
|
||||
check_error(connection, info_cookie, "Could not get font information");
|
||||
|
||||
/* Get information (height/name) for this font */
|
||||
xcb_list_fonts_with_info_reply_t *reply = xcb_list_fonts_with_info_reply(connection, cookie, NULL);
|
||||
xcb_list_fonts_with_info_reply_t *reply = xcb_list_fonts_with_info_reply(connection, info_cookie, NULL);
|
||||
exit_if_null(reply, "Could not load font \"%s\"\n", pattern);
|
||||
|
||||
if (asprintf(&(new->name), "%.*s", xcb_list_fonts_with_info_name_length(reply),
|
||||
|
|
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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue