1 // Copyright (2013) Jann Horn <jann@thejh.net>
3 // This file contains stuff for making error-handling easier.
7 #define GENERIC_ERROR \
8 "unexpected generic failure of some kind"
10 PUBLIC_FN void xperror(const char *s, int show_errno) JH_ATTR_NORETURN {
11 if (!s) s=GENERIC_ERROR;
15 fprintf(stderr, "%s\n", s);
20 PUBLIC_FN void *fail_on_npointer(void *p, char *msg, int show_errno) {
21 if (!p) xperror(msg, show_errno);
25 HEADER #define CHK_PTR(p, msg, show_errno) ( \
27 HEADER fail_on_npointer((p), (msg), (show_errno)) \
30 PUBLIC_FN int fail_on_neg(int n, char *msg, int show_errno) {
31 if ((n)<0) xperror(msg, show_errno);