From: Michael Stapelberg Date: Sun, 15 Feb 2009 21:52:33 +0000 (+0100) Subject: Implement exit_if_null using variadic macros, fix compilation X-Git-Tag: 3.a~176 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=72167387787e044994185d534caf2dbab103a851;p=i3%2Fi3 Implement exit_if_null using variadic macros, fix compilation --- diff --git a/include/util.h b/include/util.h index a5be61b3..0bc3903c 100644 --- a/include/util.h +++ b/include/util.h @@ -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); diff --git a/src/font.c b/src/font.c index c3057c55..624c20ac 100644 --- a/src/font.c +++ b/src/font.c @@ -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), diff --git a/src/util.c b/src/util.c index 8bbc145c..f7e71d15 100644 --- a/src/util.c +++ b/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. *