]>
Commit | Line | Data |
---|---|---|
46aded9a MT |
1 | /* |
2 | libloc - A library to determine the location of someone on the Internet | |
3 | ||
4 | Copyright (C) 2017 IPFire Development Team <info@ipfire.org> | |
5 | ||
6 | This library is free software; you can redistribute it and/or | |
7 | modify it under the terms of the GNU Lesser General Public | |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
10 | ||
11 | This library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | */ | |
16 | ||
17 | #ifndef LIBLOC_PRIVATE_H | |
18 | #define LIBLOC_PRIVATE_H | |
19 | ||
20 | #include <stdbool.h> | |
21 | #include <syslog.h> | |
22 | ||
23 | #include <loc/libloc.h> | |
24 | ||
25 | static inline void __attribute__((always_inline, format(printf, 2, 3))) | |
26 | loc_log_null(struct loc_ctx *ctx, const char *format, ...) {} | |
27 | ||
28 | #define loc_log_cond(ctx, prio, arg...) \ | |
29 | do { \ | |
30 | if (loc_get_log_priority(ctx) >= prio) \ | |
31 | loc_log(ctx, prio, __FILE__, __LINE__, __FUNCTION__, ## arg); \ | |
32 | } while (0) | |
33 | ||
34 | #ifdef ENABLE_DEBUG | |
35 | # define DEBUG(ctx, arg...) loc_log_cond(ctx, LOG_DEBUG, ## arg) | |
36 | #else | |
37 | # define DEBUG(ctx, arg...) loc_log_null(ctx, ## arg) | |
38 | #endif | |
39 | ||
40 | #define INFO(ctx, arg...) loc_log_cond(ctx, LOG_INFO, ## arg) | |
41 | #define ERROR(ctx, arg...) loc_log_cond(ctx, LOG_ERR, ## arg) | |
42 | ||
43 | #ifndef HAVE_SECURE_GETENV | |
44 | # ifdef HAVE___SECURE_GETENV | |
45 | # define secure_getenv __secure_getenv | |
46 | # else | |
47 | # error neither secure_getenv nor __secure_getenv is available | |
48 | # endif | |
49 | #endif | |
50 | ||
51 | #define LOC_EXPORT __attribute__ ((visibility("default"))) | |
52 | ||
53 | void loc_log(struct loc_ctx *ctx, | |
54 | int priority, const char *file, int line, const char *fn, | |
55 | const char *format, ...) __attribute__((format(printf, 6, 7))); | |
56 | ||
57 | #endif |