11 #define p_debug(str, ...) \
12 perr(PD, 0, "%s: " str, __func__ , __VA_ARGS__)
14 #define p_debug(str, ...) do {const char *s = __VA_ARGS__} while (0)
17 #define always_assert(condition) \
20 perr(PFE, 1, "%s:%d: Assertion failed: " # condition, \
21 __FILE__, __LINE__); \
25 #define assert(condition) \
28 perr(PFE, 0, "%s:%d: Assertion failed: " # condition, \
29 __FILE__, __LINE__); \
32 #define assert(condition) do { } while (0)
35 #define PERR_BUF_SIZE 2048
36 #define HOSTNAME_BUF_SIZE 100
38 /* Compiler-specific stuff */
39 #define VAR_MAY_BE_UNUSED(x) ((void)(x))
42 * Function prototypes and extern definitions
45 /* Perr fatal error, error, information, warning, debug */
46 enum perr_type { PFE = 1, PE = 0, PI = -1, PW = -2, PD = -3 };
48 void init_perr(char *prog_name);
49 void perr_func(int type, int want_errno, char *fmt, ...)
50 __attribute__ ((format (printf, 3, 4)));
52 /* No inline form of perr can be used, since it is variadic (See gcc manual) */
54 #define __fmt2(fmt0, arg0, arg1, fmt1, ...) fmt0 fmt1 "%s", arg0, arg1, __VA_ARGS__
57 #define perr(type, want_errno, ...) \
58 perr_func(type, want_errno, \
59 __fmt2("%s: %d: ", __func__, __LINE__, __VA_ARGS__, ""))
61 #define perr(type, want_errno, ...) \
64 perr_func(type, want_errno, \
65 __fmt2("%s: %d: ", __func__, __LINE__, __VA_ARGS__, "")); \
69 /* String manipulation */
70 size_t strlcpy(char *dst, const char *src, size_t siz);
71 size_t strlcat(char *dst, const char *src, size_t siz);
73 #endif /* _COMMON_H */