From 72167387787e044994185d534caf2dbab103a851 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 15 Feb 2009 22:52:33 +0100 Subject: [PATCH] Implement exit_if_null using variadic macros, fix compilation --- include/util.h | 3 ++- src/font.c | 3 +-- src/util.c | 19 +------------------ 3 files changed, 4 insertions(+), 21 deletions(-) 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. * -- 2.39.5