Build system: Add the --enable-standards configure option.
[collectd.git] / src / collectd.h
1 /**
2  * collectd - src/collectd.h
3  * Copyright (C) 2005,2006  Florian octo Forster
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; only version 2 of the License is applicable.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  *
18  * Authors:
19  *   Florian octo Forster <octo at verplant.org>
20  **/
21
22 #ifndef COLLECTD_H
23 #define COLLECTD_H
24
25 #if HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 /* Set to C99 and POSIX code */
30 #if COLLECT_STANDARDS
31 # include "standards.h"
32 #endif /* COLLECT_STANDARDS */
33
34 #include <stdio.h>
35 #if HAVE_SYS_TYPES_H
36 # include <sys/types.h>
37 #endif
38 #if HAVE_SYS_STAT_H
39 # include <sys/stat.h>
40 #endif
41 #if STDC_HEADERS
42 # include <stdlib.h>
43 # include <stddef.h>
44 #else
45 # if HAVE_STDLIB_H
46 #  include <stdlib.h>
47 # endif
48 #endif
49 #if HAVE_STRING_H
50 # if !STDC_HEADERS && HAVE_MEMORY_H
51 #  include <memory.h>
52 # endif
53 # include <string.h>
54 #endif
55 #if HAVE_STRINGS_H
56 # include <strings.h>
57 #endif
58 #if HAVE_INTTYPES_H
59 # include <inttypes.h>
60 #endif
61 #if HAVE_STDINT_H
62 # include <stdint.h>
63 #endif
64 #if HAVE_STDBOOL_H
65 # include <stdbool.h>
66 #endif
67 #if HAVE_UNISTD_H
68 # include <unistd.h>
69 #endif
70 #if HAVE_SYS_WAIT_H
71 # include <sys/wait.h>
72 #endif
73 #ifndef WEXITSTATUS
74 # define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
75 #endif
76 #ifndef WIFEXITED
77 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
78 #endif
79 #if HAVE_SIGNAL_H
80 # include <signal.h>
81 #endif
82 #if HAVE_FCNTL_H
83 # include <fcntl.h>
84 #endif
85 #if HAVE_ERRNO_H
86 # include <errno.h>
87 #endif
88 #if HAVE_LIMITS_H
89 # include <limits.h>
90 #endif
91 #if TIME_WITH_SYS_TIME
92 # include <sys/time.h>
93 # include <time.h>
94 #else
95 # if HAVE_SYS_TIME_H
96 #  include <sys/time.h>
97 # else
98 #  include <time.h>
99 # endif
100 #endif
101
102 #if HAVE_ASSERT_H
103 # include <assert.h>
104 #else
105 # define assert(...) /* nop */
106 #endif
107
108 #if NAN_STATIC_DEFAULT
109 # include <math.h>
110 /* #endif NAN_STATIC_DEFAULT*/
111 #elif NAN_STATIC_ISOC
112 # ifndef __USE_ISOC99
113 #  define DISABLE_ISOC99 1
114 #  define __USE_ISOC99 1
115 # endif /* !defined(__USE_ISOC99) */
116 # include <math.h>
117 # if DISABLE_ISOC99
118 #  undef DISABLE_ISOC99
119 #  undef __USE_ISOC99
120 # endif /* DISABLE_ISOC99 */
121 /* #endif NAN_STATIC_ISOC */
122 #elif NAN_ZERO_ZERO
123 # include <math.h>
124 # ifdef NAN
125 #  undef NAN
126 # endif
127 # define NAN (0.0 / 0.0)
128 # ifndef isnan
129 #  define isnan(f) ((f) != (f))
130 # endif /* !defined(isnan) */
131 #endif /* NAN_ZERO_ZERO */
132
133 /* Try really, really hard to determine endianess. Under NexentaStor 1.0.2 this
134  * information is in <sys/isa_defs.h>, possibly some other Solaris versions do
135  * this too.. */
136 #if HAVE_ENDIAN_H
137 # include <endian.h>
138 #elif HAVE_SYS_ISA_DEFS_H
139 # include <sys/isa_defs.h>
140 #endif
141
142 #ifndef BYTE_ORDER
143 # if defined(_BYTE_ORDER)
144 #  define BYTE_ORDER _BYTE_ORDER
145 # elif defined(__BYTE_ORDER)
146 #  define BYTE_ORDER __BYTE_ORDER
147 # elif defined(__DARWIN_BYTE_ORDER)
148 #  define BYTE_ORDER __DARWIN_BYTE_ORDER
149 # endif
150 #endif
151 #ifndef BIG_ENDIAN
152 # if defined(_BIG_ENDIAN)
153 #  define BIG_ENDIAN _BIG_ENDIAN
154 # elif defined(__BIG_ENDIAN)
155 #  define BIG_ENDIAN __BIG_ENDIAN
156 # elif defined(__DARWIN_BIG_ENDIAN)
157 #  define BIG_ENDIAN __DARWIN_BIG_ENDIAN
158 # endif
159 #endif
160 #ifndef LITTLE_ENDIAN
161 # if defined(_LITTLE_ENDIAN)
162 #  define LITTLE_ENDIAN _LITTLE_ENDIAN
163 # elif defined(__LITTLE_ENDIAN)
164 #  define LITTLE_ENDIAN __LITTLE_ENDIAN
165 # elif defined(__DARWIN_LITTLE_ENDIAN)
166 #  define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
167 # endif
168 #endif
169 #ifndef BYTE_ORDER
170 # if defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN)
171 #  undef BIG_ENDIAN
172 #  define BIG_ENDIAN 4321
173 #  define LITTLE_ENDIAN 1234
174 #  define BYTE_ORDER BIG_ENDIAN
175 # elif !defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
176 #  undef LITTLE_ENDIAN
177 #  define BIG_ENDIAN 4321
178 #  define LITTLE_ENDIAN 1234
179 #  define BYTE_ORDER LITTLE_ENDIAN
180 # endif
181 #endif
182 #if !defined(BYTE_ORDER) || !defined(BIG_ENDIAN)
183 # error "Cannot determine byte order"
184 #endif
185
186 #if HAVE_DIRENT_H
187 # include <dirent.h>
188 # define NAMLEN(dirent) strlen((dirent)->d_name)
189 #else
190 # define dirent direct
191 # define NAMLEN(dirent) (dirent)->d_namlen
192 # if HAVE_SYS_NDIR_H
193 #  include <sys/ndir.h>
194 # endif
195 # if HAVE_SYS_DIR_H
196 #  include <sys/dir.h>
197 # endif
198 # if HAVE_NDIR_H
199 #  include <ndir.h>
200 # endif
201 #endif
202
203 #if HAVE_STDARG_H
204 # include <stdarg.h>
205 #endif
206 #if HAVE_CTYPE_H
207 # include <ctype.h>
208 #endif
209 #if HAVE_SYS_PARAM_H
210 # include <sys/param.h>
211 #endif
212
213 #if HAVE_KSTAT_H
214 # include <kstat.h>
215 #endif
216
217 #if HAVE_SENSORS_SENSORS_H
218 # include <sensors/sensors.h>
219 #endif
220
221 #ifndef PACKAGE_NAME
222 #define PACKAGE_NAME "collectd"
223 #endif
224
225 #ifndef PREFIX
226 #define PREFIX "/opt/" PACKAGE_NAME
227 #endif
228
229 #ifndef SYSCONFDIR
230 #define SYSCONFDIR PREFIX "/etc"
231 #endif
232
233 #ifndef CONFIGFILE
234 #define CONFIGFILE SYSCONFDIR"/collectd.conf"
235 #endif
236
237 #ifndef LOCALSTATEDIR
238 #define LOCALSTATEDIR PREFIX "/var"
239 #endif
240
241 #ifndef PKGLOCALSTATEDIR
242 #define PKGLOCALSTATEDIR PREFIX "/var/lib/" PACKAGE_NAME
243 #endif
244
245 #ifndef PIDFILE
246 #define PIDFILE PREFIX "/var/run/" PACKAGE_NAME ".pid"
247 #endif
248
249 #ifndef PLUGINDIR
250 #define PLUGINDIR PREFIX "/lib/" PACKAGE_NAME
251 #endif
252
253 #ifndef PKGDATADIR
254 #define PKGDATADIR PREFIX "/share/" PACKAGE_NAME
255 #endif
256
257 #ifndef COLLECTD_GRP_NAME
258 # define COLLECTD_GRP_NAME "collectd"
259 #endif
260
261 #define STATIC_ARRAY_LEN(array) (sizeof (array) / sizeof ((array)[0]))
262
263 /* Remove GNU specific __attribute__ settings when using another compiler */
264 #if !__GNUC__
265 # define __attribute__(x) /**/
266 #endif
267
268 #if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
269 # undef strcpy
270 # undef strcat
271 # undef strtok
272 # pragma GCC poison strcpy strcat strtok
273 #endif
274
275 /* 
276  * Special hack for the perl plugin: Because the later included perl.h defines
277  * a macro which is never used, but contains `sprintf', we cannot poison that
278  * identifies just yet. The parl plugin will do that itself once perl.h is
279  * included.
280  */
281 #ifndef DONT_POISON_SPRINTF_YET
282 # if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
283 #  undef sprintf
284 #  pragma GCC poison sprintf
285 # endif
286 #endif
287
288 extern char hostname_g[];
289 extern int  interval_g;
290
291 #endif /* COLLECTD_H */