unix/fiss

lib/libutil.old/common.h in master
Repositories | Summary | Log | Files | LICENSE

common.h (846B) download


 1#pragma once
 2
 3#define SHIFT(n) (argc -= (n), argv += (n))
 4
 5#define THROW(condition, message, exitcode, ...)                    \
 6	{                                                               \
 7		if (condition) {                                            \
 8			fprint(1, "%s: " message ": %s\n",                      \
 9			       current_prog(), ##__VA_ARGS__, strerror(errno)); \
10			if (exitcode != -1)                                     \
11				exit(exitcode);                                     \
12		}                                                           \
13	}
14
15#define THROW_MIN(func, ...) THROW((func) == -1, __VA_ARGS__)
16
17#define THROW_NULL(func, ...) THROW((func) == NULL, __VA_ARGS__)
18
19#define FALLTHROUGH __attribute__((fallthrough))
20
21#define EXIT_SUCCESS 0
22#define EXIT_USER    100
23#define EXIT_TEMP    101
24#define EXIT_PERM    102