src/util.h: GUARD_ERRNO macro
[vlock.git] / src / util.h
blobeebd9461ad1acf3e8717b749f16582e52f3e2376
1 /* util.h -- header for utility routines for vlock,
2 * the VT locking program for linux
4 * This program is copyright (C) 2007 Frank Benkstein, and is free
5 * software which is freely distributable under the terms of the
6 * GNU General Public License version 2, included as the file COPYING in this
7 * distribution. It is NOT public domain software, and any
8 * redistribution not permitted by the GNU General Public License is
9 * expressly forbidden without prior written permission from
10 * the author.
14 #include <stddef.h>
16 struct timespec;
18 /* Parse the given string (interpreted as seconds) into a
19 * timespec. On error NULL is returned. The caller is responsible
20 * to free the result. The string may be NULL, in which case NULL
21 * is returned, too. */
22 struct timespec *parse_seconds(const char *s);
24 void fatal_error(const char *format, ...)
25 __attribute__((noreturn, format(printf, 1, 2)));
26 void fatal_error_free(char *errmsg)
27 __attribute__((noreturn));
28 void fatal_perror(const char *errmsg)
29 __attribute__((noreturn));
31 void *ensure_malloc(size_t);
32 void *ensure_calloc(size_t, size_t);
33 void *ensure_realloc(void *, size_t);
34 void *ensure_not_null(void *, const char *);
36 #define STRERROR (errno ? strerror(errno) : "Unknown error")
38 #define GUARD_ERRNO(expr) \
39 do { \
40 int __errsv = errno; expr; errno = __errsv; \
41 } while (0)