Debian Codegraph @

src/common/common.h

raw symbols SCIP
1 /*
2 Authors:
3 Pavel Březina <[email protected]>
4
5 Copyright (C) 2017 Red Hat
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef _COMMON_H_
22 #define _COMMON_H_
23
24 #include "config.h"
25
26 #include <stdlib.h>
27 #include <stdarg.h>
28
29 #include "errno_t.h"
30 #include "gettext.h"
31 #include "authselect.h"
32
33 #define _(s) gettext(s)
34
35 /* Wrappers around malloc and realloc to allocate zero-filled
36 * memory and provide type safety. */
37
38 #define malloc_zero(type) \
39 (type *) calloc(1, sizeof(type))
40
41 #define malloc_zero_array(type, num) \
42 (type *) calloc((num), sizeof(type))
43
44 #ifdef HAVE_REALLOCARRAY
45 #define realloc_array(ptr, type, num) \
46 (type *) reallocarray((ptr), (num), sizeof(type))
47 #else
48 #define realloc_array(ptr, type, num) \
49 (type *) realloc((ptr), sizeof(type)*(num))
50 #endif
51
52 /* Debugging facility. */
53
54 void set_debug_fn(authselect_debug_fn fn, void *pvt);
55
56 void debug(enum authselect_debug level,
57 const char *file,
58 unsigned long line,
59 const char *function,
60 const char *fmt,
61 ...);
62
63 #define INFO(fmt, ...) \
64 debug(AUTHSELECT_INFO, __FILE__, __LINE__, __FUNCTION__, \
65 gettext(fmt), ## __VA_ARGS__)
66
67 #define WARN(fmt, ...) \
68 debug(AUTHSELECT_WARNING, __FILE__, __LINE__, __FUNCTION__, \
69 gettext(fmt), ## __VA_ARGS__)
70
71 #define ERROR(fmt, ...) \
72 debug(AUTHSELECT_ERROR, __FILE__, __LINE__, __FUNCTION__, \
73 gettext(fmt), ## __VA_ARGS__)
74
75 /* Wrapper around aprintf to simplify error handling. */
76 char *format(const char *fmt, ...);
77 char *vaformat(const char *fmt, va_list va);
78
79 #endif /* _COMMON_H_ */