Nagios
4.3.4
Dev docs for Nagios core and neb-module hackers
lib
lnag-utils.h
Go to the documentation of this file.
1
#ifndef LIBNAGIOS_LNAG_UTILS_H_INCLUDED
2
#define LIBNAGIOS_LNAG_UTILS_H_INCLUDED
3
4
#include <unistd.h>
/* for sysconf() */
5
#include <stdlib.h>
/* for rand() */
6
7
/**
8
* @file lnag-utils.h
9
* @brief libnagios helper and compatibility macros that lack a "real" home.
10
*
11
* This is the home of random macros that must be present for compilation
12
* to succeed but are missing on some platforms.
13
*
14
* @{
15
*/
16
17
#define NAGIOS_MKVERSION(a, b, c) \
18
(((a) * 10000) + ((b) * 100) + (c))
19
20
#ifdef __cplusplus
21
/** C++ compatibility macro that avoids confusing indentation programs */
22
# define NAGIOS_BEGIN_DECL extern "C" {
23
/**
24
* Use at end of header file declarations to obtain C++ compatibility
25
* ... without confusing indentation programs
26
*/
27
# define NAGIOS_END_DECL }
28
#else
29
/** C++ compatibility macro that avoids confusing indentation programs */
30
# define NAGIOS_BEGIN_DECL
/* nothing */
31
/** C++ compatibility macro that avoid confusing indentation programs */
32
# define NAGIOS_END_DECL
/* more of nothing */
33
#endif
34
35
#ifndef NODOXY
/* doxy comments are useless here */
36
# ifndef __GNUC__
37
# define GCC_VERSION 0
38
# define __attribute__(x)
/* nothing */
39
# else
40
# ifdef __GNUC_PATCHLEVEL__
41
# define GCC_VERSION NAGIOS_MKVERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
42
# else
43
# define GCC_VERSION NAGIOS_MKVERSION(__GNUC__, __GNUC_MINOR__, 0)
44
# endif
/* __GNUC_PATCHLEVEL__ */
45
# endif
/* __GNUC__ */
46
#endif
/* NODOXY */
47
48
#if GCC_VERSION >= NAGIOS_MKVERSION(4, 5, 0)
49
# define NAGIOS_DEPRECATED(version, hint) \
50
__attribute__((deprecated("This function will be removed in Nagios v" #version ". Please use " #hint " instead")))
51
#else
52
/** Macro for alerting module authors to function deprecation */
53
# define NAGIOS_DEPRECATED(version, hint) \
54
__attribute__((deprecated))
55
#endif
56
57
/*
58
* These macros are widely used throughout Nagios
59
*/
60
#define OK 0
/**< Indicates successful function call in Nagios */
61
#define ERROR -2
/**< Non-successful function call in Nagios */
62
63
#ifdef FALSE
64
#undef FALSE
65
#endif
66
#define FALSE 0
/**< Not true */
67
68
#ifdef TRUE
69
#undef TRUE
70
#endif
71
#define TRUE (!FALSE)
/**< Not false */
72
73
/** Useful macro to safely avoid double-free memory corruption */
74
#define my_free(ptr) do { if(ptr) { free(ptr); ptr = NULL; } } while(0)
75
76
#ifndef ARRAY_SIZE
77
/** Useful for iterating over all elements in a static array */
78
# define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
79
#endif
80
#ifndef veclen
81
/** useful for iterating over all elements in a static array */
82
# define veclen ARRAY_SIZE
83
#endif
84
85
#ifndef offsetof
86
/** standard offsetof macro */
87
# define offsetof(t, f) ((unsigned long)&((t *)0)->f)
88
#endif
89
90
/** character map initialization for .bss-allocated char maps */
91
#define CHAR_MAP_INIT(k) { \
92
k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \
93
k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \
94
k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \
95
k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \
96
k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \
97
k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \
98
k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \
99
k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \
100
k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \
101
k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \
102
k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \
103
k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \
104
k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \
105
k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \
106
k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \
107
k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \
108
}
109
110
/** @} */
111
#endif
Generated by
1.8.14