Fix compile time issues
[collectd.git] / src / daemon / collectd.h
1 /**
2  * collectd - src/collectd.h
3  * Copyright (C) 2005,2006  Florian octo Forster
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  *
23  * Authors:
24  *   Florian octo Forster <octo at collectd.org>
25  **/
26
27 #ifndef COLLECTD_H
28 #define COLLECTD_H
29
30 #ifdef WIN32
31 typedef int uid_t;
32 #include "gnulib_config.h"
33 #endif
34
35 #if HAVE_CONFIG_H
36 #include "config.h"
37 #endif
38
39 #include <assert.h>
40 #include <ctype.h>
41 #include <errno.h>
42 #include <inttypes.h>
43 #include <limits.h>
44 #include <signal.h>
45 #include <stdarg.h>
46 #include <stdbool.h>
47 #include <stddef.h>
48 #include <stdint.h>
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <string.h>
52 #if HAVE_SYS_TYPES_H
53 #include <sys/types.h>
54 #endif
55 #if HAVE_SYS_STAT_H
56 #include <sys/stat.h>
57 #endif
58 #if HAVE_STRINGS_H
59 #include <strings.h>
60 #endif
61 #if HAVE_UNISTD_H
62 #include <unistd.h>
63 #endif
64 #if HAVE_SYS_WAIT_H
65 #include <sys/wait.h>
66 #endif
67 #ifndef WEXITSTATUS
68 #define WEXITSTATUS(stat_val) ((unsigned int)(stat_val) >> 8)
69 #endif
70 #ifndef WIFEXITED
71 #define WIFEXITED(stat_val) (((stat_val)&255) == 0)
72 #endif
73 #if HAVE_FCNTL_H
74 #include <fcntl.h>
75 #endif
76 #if TIME_WITH_SYS_TIME
77 #include <sys/time.h>
78 #include <time.h>
79 #else
80 #if HAVE_SYS_TIME_H
81 #include <sys/time.h>
82 #else
83 #include <time.h>
84 #endif
85 #endif
86 #if HAVE_SYS_SOCKET_H
87 #include <sys/socket.h>
88 #endif
89
90 #if NAN_STATIC_DEFAULT
91 #include <math.h>
92 /* #endif NAN_STATIC_DEFAULT*/
93 #elif NAN_STATIC_ISOC
94 #ifndef __USE_ISOC99
95 #define DISABLE_ISOC99 1
96 #define __USE_ISOC99 1
97 #endif /* !defined(__USE_ISOC99) */
98 #include <math.h>
99 #if DISABLE_ISOC99
100 #undef DISABLE_ISOC99
101 #undef __USE_ISOC99
102 #endif /* DISABLE_ISOC99 */
103 /* #endif NAN_STATIC_ISOC */
104 #elif NAN_ZERO_ZERO
105 #include <math.h>
106 #ifdef NAN
107 #undef NAN
108 #endif
109 #define NAN (0.0 / 0.0)
110 #ifndef isnan
111 #define isnan(f) ((f) != (f))
112 #endif /* !defined(isnan) */
113 #ifndef isfinite
114 #define isfinite(f) (((f) - (f)) == 0.0)
115 #endif
116 #ifndef isinf
117 #define isinf(f) (!isfinite(f) && !isnan(f))
118 #endif
119 #endif /* NAN_ZERO_ZERO */
120
121 /* Try really, really hard to determine endianess. Under NexentaStor 1.0.2 this
122  * information is in <sys/isa_defs.h>, possibly some other Solaris versions do
123  * this too.. */
124 #if HAVE_ENDIAN_H
125 #include <endian.h>
126 #elif HAVE_SYS_ISA_DEFS_H
127 #include <sys/isa_defs.h>
128 #endif
129
130 #if HAVE_SYS_PARAM_H
131 #include <sys/param.h>
132 #endif
133
134 #ifndef BYTE_ORDER
135 #if defined(_BYTE_ORDER)
136 #define BYTE_ORDER _BYTE_ORDER
137 #elif defined(__BYTE_ORDER)
138 #define BYTE_ORDER __BYTE_ORDER
139 #elif defined(__DARWIN_BYTE_ORDER)
140 #define BYTE_ORDER __DARWIN_BYTE_ORDER
141 #endif
142 #endif
143 #ifndef BIG_ENDIAN
144 #if defined(_BIG_ENDIAN)
145 #define BIG_ENDIAN _BIG_ENDIAN
146 #elif defined(__BIG_ENDIAN)
147 #define BIG_ENDIAN __BIG_ENDIAN
148 #elif defined(__DARWIN_BIG_ENDIAN)
149 #define BIG_ENDIAN __DARWIN_BIG_ENDIAN
150 #endif
151 #endif
152 #ifndef LITTLE_ENDIAN
153 #if defined(_LITTLE_ENDIAN)
154 #define LITTLE_ENDIAN _LITTLE_ENDIAN
155 #elif defined(__LITTLE_ENDIAN)
156 #define LITTLE_ENDIAN __LITTLE_ENDIAN
157 #elif defined(__DARWIN_LITTLE_ENDIAN)
158 #define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
159 #endif
160 #endif
161 #ifndef BYTE_ORDER
162 #if defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN)
163 #undef BIG_ENDIAN
164 #define BIG_ENDIAN 4321
165 #define LITTLE_ENDIAN 1234
166 #define BYTE_ORDER BIG_ENDIAN
167 #elif !defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
168 #undef LITTLE_ENDIAN
169 #define BIG_ENDIAN 4321
170 #define LITTLE_ENDIAN 1234
171 #define BYTE_ORDER LITTLE_ENDIAN
172 #endif
173 #endif
174 #if !defined(BYTE_ORDER) || !defined(BIG_ENDIAN)
175 #error "Cannot determine byte order"
176 #endif
177
178 #if HAVE_DIRENT_H
179 #include <dirent.h>
180 #define NAMLEN(dirent) strlen((dirent)->d_name)
181 #else
182 #define dirent direct
183 #define NAMLEN(dirent) (dirent)->d_namlen
184 #if HAVE_SYS_NDIR_H
185 #include <sys/ndir.h>
186 #endif
187 #if HAVE_SYS_DIR_H
188 #include <sys/dir.h>
189 #endif
190 #if HAVE_NDIR_H
191 #include <ndir.h>
192 #endif
193 #endif
194
195 #ifndef PACKAGE_NAME
196 #define PACKAGE_NAME "collectd"
197 #endif
198
199 #ifndef PREFIX
200 #define PREFIX "/opt/" PACKAGE_NAME
201 #endif
202
203 #ifndef SYSCONFDIR
204 #define SYSCONFDIR PREFIX "/etc"
205 #endif
206
207 #ifndef CONFIGFILE
208 #define CONFIGFILE SYSCONFDIR "/collectd.conf"
209 #endif
210
211 #ifndef LOCALSTATEDIR
212 #define LOCALSTATEDIR PREFIX "/var"
213 #endif
214
215 #ifndef PKGLOCALSTATEDIR
216 #define PKGLOCALSTATEDIR PREFIX "/var/lib/" PACKAGE_NAME
217 #endif
218
219 #ifndef PIDFILE
220 #define PIDFILE PREFIX "/var/run/" PACKAGE_NAME ".pid"
221 #endif
222
223 #ifndef PLUGINDIR
224 #define PLUGINDIR PREFIX "/lib/" PACKAGE_NAME
225 #endif
226
227 #ifndef PKGDATADIR
228 #define PKGDATADIR PREFIX "/share/" PACKAGE_NAME
229 #endif
230
231 #ifndef COLLECTD_GRP_NAME
232 #define COLLECTD_GRP_NAME "collectd"
233 #endif
234
235 #ifndef COLLECTD_DEFAULT_INTERVAL
236 #define COLLECTD_DEFAULT_INTERVAL 10.0
237 #endif
238
239 #ifndef COLLECTD_USERAGENT
240 #define COLLECTD_USERAGENT PACKAGE_NAME "/" PACKAGE_VERSION
241 #endif
242
243 /* Only enable __attribute__() for compilers known to support it. */
244 #if !defined(__clang__) && !defined(__GNUC__)
245 #define __attribute__(x) /**/
246 #endif
247
248 #ifndef GAUGE_FORMAT
249 #define GAUGE_FORMAT "%.15g"
250 #endif
251
252 #include "globals.h"
253
254 #endif /* COLLECTD_H */