|
Nagios 4.4.2
Dev docs for Nagios core and neb-module hackers
|
00001 #ifndef LIBNAGIOS_LNAG_UTILS_H_INCLUDED 00002 #define LIBNAGIOS_LNAG_UTILS_H_INCLUDED 00003 00004 #include <unistd.h> /* for sysconf() */ 00005 #include <stdlib.h> /* for rand() */ 00006 00007 /** 00008 * @file lnag-utils.h 00009 * @brief libnagios helper and compatibility macros that lack a "real" home. 00010 * 00011 * This is the home of random macros that must be present for compilation 00012 * to succeed but are missing on some platforms. 00013 * 00014 * @{ 00015 */ 00016 00017 #define NAGIOS_MKVERSION(a, b, c) \ 00018 (((a) * 10000) + ((b) * 100) + (c)) 00019 00020 #ifdef __cplusplus 00021 /** C++ compatibility macro that avoids confusing indentation programs */ 00022 # define NAGIOS_BEGIN_DECL extern "C" { 00023 /** 00024 * Use at end of header file declarations to obtain C++ compatibility 00025 * ... without confusing indentation programs 00026 */ 00027 # define NAGIOS_END_DECL } 00028 #else 00029 /** C++ compatibility macro that avoids confusing indentation programs */ 00030 # define NAGIOS_BEGIN_DECL /* nothing */ 00031 /** C++ compatibility macro that avoid confusing indentation programs */ 00032 # define NAGIOS_END_DECL /* more of nothing */ 00033 #endif 00034 00035 #ifndef NODOXY /* doxy comments are useless here */ 00036 # ifndef __GNUC__ 00037 # define GCC_VERSION 0 00038 # define __attribute__(x) /* nothing */ 00039 # else 00040 # ifdef __GNUC_PATCHLEVEL__ 00041 # define GCC_VERSION NAGIOS_MKVERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) 00042 # else 00043 # define GCC_VERSION NAGIOS_MKVERSION(__GNUC__, __GNUC_MINOR__, 0) 00044 # endif /* __GNUC_PATCHLEVEL__ */ 00045 # endif /* __GNUC__ */ 00046 #endif /* NODOXY */ 00047 00048 #if GCC_VERSION >= NAGIOS_MKVERSION(4, 5, 0) 00049 # define NAGIOS_DEPRECATED(version, hint) \ 00050 __attribute__((deprecated("This function will be removed in Nagios v" #version ". Please use " #hint " instead"))) 00051 #else 00052 /** Macro for alerting module authors to function deprecation */ 00053 # define NAGIOS_DEPRECATED(version, hint) \ 00054 __attribute__((deprecated)) 00055 #endif 00056 00057 /* 00058 * These macros are widely used throughout Nagios 00059 */ 00060 #define OK 0 /**< Indicates successful function call in Nagios */ 00061 #define ERROR -2 /**< Non-successful function call in Nagios */ 00062 00063 #ifdef FALSE 00064 #undef FALSE 00065 #endif 00066 #define FALSE 0 /**< Not true */ 00067 00068 #ifdef TRUE 00069 #undef TRUE 00070 #endif 00071 #define TRUE (!FALSE) /**< Not false */ 00072 00073 /** Useful macro to safely avoid double-free memory corruption */ 00074 #define my_free(ptr) do { if(ptr) { free(ptr); ptr = NULL; } } while(0) 00075 00076 #ifndef ARRAY_SIZE 00077 /** Useful for iterating over all elements in a static array */ 00078 # define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) 00079 #endif 00080 #ifndef veclen 00081 /** useful for iterating over all elements in a static array */ 00082 # define veclen ARRAY_SIZE 00083 #endif 00084 00085 #ifndef offsetof 00086 /** standard offsetof macro */ 00087 # define offsetof(t, f) ((unsigned long)&((t *)0)->f) 00088 #endif 00089 00090 /** character map initialization for .bss-allocated char maps */ 00091 #define CHAR_MAP_INIT(k) { \ 00092 k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \ 00093 k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \ 00094 k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \ 00095 k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \ 00096 k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \ 00097 k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \ 00098 k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \ 00099 k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \ 00100 k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \ 00101 k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \ 00102 k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \ 00103 k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \ 00104 k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \ 00105 k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \ 00106 k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \ 00107 k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, \ 00108 } 00109 00110 /** @} */ 00111 #endif
1.7.3