Use errx() instead of an own die() function
This commit is contained in:
parent
e6198ad6c8
commit
1befbb2a50
@ -9,12 +9,14 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
|
#include <err.h>
|
||||||
|
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
|
|
||||||
#ifndef _UTIL_H
|
#ifndef _UTIL_H
|
||||||
#define _UTIL_H
|
#define _UTIL_H
|
||||||
|
|
||||||
|
#define die(...) errx(EXIT_FAILURE, __VA_ARGS__);
|
||||||
#define exit_if_null(pointer, ...) { if (pointer == NULL) die(__VA_ARGS__); }
|
#define exit_if_null(pointer, ...) { if (pointer == NULL) die(__VA_ARGS__); }
|
||||||
#define STARTS_WITH(string, needle) (strncasecmp(string, needle, strlen(needle)) == 0)
|
#define STARTS_WITH(string, needle) (strncasecmp(string, needle, strlen(needle)) == 0)
|
||||||
#define CIRCLEQ_NEXT_OR_NULL(head, elm, field) (CIRCLEQ_NEXT(elm, field) != CIRCLEQ_END(head) ? \
|
#define CIRCLEQ_NEXT_OR_NULL(head, elm, field) (CIRCLEQ_NEXT(elm, field) != CIRCLEQ_END(head) ? \
|
||||||
@ -50,12 +52,6 @@ int max(int a, int b);
|
|||||||
*/
|
*/
|
||||||
void slog(char *fmt, ...);
|
void slog(char *fmt, ...);
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints the message (see printf()) to stderr, then exits the program.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void die(char *fmt, ...) __attribute__((__noreturn__));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Safe-wrapper around malloc which exits if malloc returns NULL (meaning that
|
* Safe-wrapper around malloc which exits if malloc returns NULL (meaning that
|
||||||
* there is no more memory available)
|
* there is no more memory available)
|
||||||
|
18
src/util.c
18
src/util.c
@ -62,20 +62,6 @@ void slog(char *fmt, ...) {
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Prints the message (see printf()) to stderr, then exits the program.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void die(char *fmt, ...) {
|
|
||||||
va_list args;
|
|
||||||
|
|
||||||
va_start(args, fmt);
|
|
||||||
vfprintf(stderr, fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The s* functions (safe) are wrappers around malloc, strdup, …, which exits if one of
|
* The s* functions (safe) are wrappers around malloc, strdup, …, which exits if one of
|
||||||
* the called functions returns NULL, meaning that there is no more memory available
|
* the called functions returns NULL, meaning that there is no more memory available
|
||||||
@ -83,13 +69,13 @@ void die(char *fmt, ...) {
|
|||||||
*/
|
*/
|
||||||
void *smalloc(size_t size) {
|
void *smalloc(size_t size) {
|
||||||
void *result = malloc(size);
|
void *result = malloc(size);
|
||||||
exit_if_null(result, "Error: out of memory (malloc(%d))\n", size);
|
exit_if_null(result, "Error: out of memory (malloc(%zd))\n", size);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *scalloc(size_t size) {
|
void *scalloc(size_t size) {
|
||||||
void *result = calloc(size, 1);
|
void *result = calloc(size, 1);
|
||||||
exit_if_null(result, "Error: out of memory (calloc(%d))\n", size);
|
exit_if_null(result, "Error: out of memory (calloc(%zd))\n", size);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user