1 // Copyright (2013) Jann Horn <jann@thejh.net>
2 // This code is licensed under the AGPLv3.
4 // This file contains stuff for making error-handling easier.
8 #define GENERIC_ERROR \
9 "unexpected generic failure of some kind"
11 PUBLIC_FN void xperror(const char *s, int show_errno) {
12 if (!s) s=GENERIC_ERROR;
16 fprintf(stderr, "%s\n", s);
21 PUBLIC_FN void *fail_on_npointer(void *p, char *msg, int show_errno) {
22 if (!p) xperror(msg, show_errno);
26 HEADER #define CHK_PTR(p, msg, show_errno) ( \
28 HEADER fail_on_npointer((p), (msg), (show_errno)) \
31 PUBLIC_FN int fail_on_neg(int n, char *msg, int show_errno) {
32 if ((n)<0) xperror(msg, show_errno);