2 * Copyright 2012 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following
13 * disclaimer in the documentation and/or other materials
14 * provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
29 * The views and conclusions contained in the software and
30 * documentation are those of the authors and should not be
31 * interpreted as representing official policies, either expressed
32 * or implied, of GRNET S.A.
45 #define p_debug(str, ...) \
46 perr(PD, 0, "%s: " str, __func__ , __VA_ARGS__)
48 #define p_debug(str, ...) do {const char *s = __VA_ARGS__} while (0)
51 #define always_assert(condition) \
54 perr(PFE, 1, "%s:%d: Assertion failed: " # condition, \
55 __FILE__, __LINE__); \
59 #define assert(condition) \
62 perr(PFE, 0, "%s:%d: Assertion failed: " # condition, \
63 __FILE__, __LINE__); \
66 #define assert(condition) do { } while (0)
69 #define PERR_BUF_SIZE 2048
70 #define HOSTNAME_BUF_SIZE 100
72 /* Compiler-specific stuff */
73 #define VAR_MAY_BE_UNUSED(x) ((void)(x))
76 * Function prototypes and extern definitions
79 /* Perr fatal error, error, information, warning, debug */
80 enum perr_type { PFE = 1, PE = 0, PI = -1, PW = -2, PD = -3 };
82 void init_perr(char *prog_name);
83 void perr_func(int type, int want_errno, char *fmt, ...)
84 __attribute__ ((format (printf, 3, 4)));
86 /* No inline form of perr can be used, since it is variadic (See gcc manual) */
88 #define __fmt2(fmt0, arg0, arg1, fmt1, ...) fmt0 fmt1 "%s", arg0, arg1, __VA_ARGS__
91 #define perr(type, want_errno, ...) \
92 perr_func(type, want_errno, \
93 __fmt2("%s: %d: ", __func__, __LINE__, __VA_ARGS__, ""))
95 #define perr(type, want_errno, ...) \
98 perr_func(type, want_errno, \
99 __fmt2("%s: %d: ", __func__, __LINE__, __VA_ARGS__, "")); \
103 /* String manipulation */
104 size_t strlcpy(char *dst, const char *src, size_t siz);
105 size_t strlcat(char *dst, const char *src, size_t siz);
107 #endif /* _COMMON_H */