Code

Fix two Solaris compile problems
[nagiosplug.git] / plugins / common.h
1 /******************************************************************************
2  *
3  * Nagios plugins common include file
4  *
5  * License: GPL
6  * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
7  *
8  * Last Modified: 11-05-1999
9  *
10  * Description:
11  *
12  * This file contains common include files and defines used in many of
13  * the plugins.
14  *
15  * License Information:
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 2 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30  *
31  * $Id$
32  *
33  *****************************************************************************/
35 #ifndef _COMMON_H_
36 #define _COMMON_H_
38 #include "config.h"
40 #ifdef HAVE_FEATURES_H
41 #include <features.h>
42 #endif
44 #include <stdio.h>                                                      /* obligatory includes */
45 #include <stdlib.h>
46 #include <errno.h>
48 /* This block provides uintmax_t - should be reported to coreutils that this should be added to fsuage.h */
49 #if HAVE_INTTYPES_H
50 # include <inttypes.h>
51 #endif
52 #if HAVE_STDINT_H
53 # include <stdint.h>
54 #endif
55 #include <unistd.h>
56 #ifndef UINTMAX_MAX
57 # define UINTMAX_MAX ((uintmax_t) -1)
58 #endif
60 #include <limits.h>     /* This is assumed true, because coreutils assume it too */
62 #ifdef HAVE_MATH_H
63 #include <math.h>
64 #endif
66 #ifdef HAVE_STRINGS_H
67 #include <strings.h>
68 #endif
69 #ifdef HAVE_STRING_H
70 #include <string.h>
71 #endif
73 #ifdef HAVE_UNISTD_H
74 #include <unistd.h>
75 #endif
77 #ifdef TIME_WITH_SYS_TIME
78 # include <sys/time.h>
79 # include <time.h>
80 #else
81 # ifdef HAVE_SYS_TIME_H
82 #  include <sys/time.h>
83 # else
84 #  include <time.h>
85 # endif
86 #endif
88 #ifdef HAVE_SYS_TYPES_H
89 #include <sys/types.h>
90 #endif
92 #ifdef HAVE_SYS_SOCKET_H
93 #include <sys/socket.h>
94 #endif
96 #ifdef HAVE_SIGNAL_H
97 #include <signal.h>
98 #endif
100 #include <getopt.h>
101 #include <ctype.h>
103 #ifdef HAVE_LWRES_NETDB_H
104 #include <lwres/netdb.h>
105 #else
106 # if !HAVE_GETADDRINFO
107 #  include "getaddrinfo.h"
108 # else
109 #  include <netdb.h>
110 # endif
111 #endif
113 #ifdef HAVE_LOCALE_H
114 #include <locale.h>
115 #endif
117 /* Fixes "Cannot use swapctl in the large files compilation environment" error on Solaris */
118 #ifdef _FILE_OFFSET_BITS
119 #undef _FILE_OFFSET_BITS
120 #endif
122 #ifdef HAVE_DECL_SWAPCTL
123 # ifdef HAVE_SYS_SWAP_H
124 #  include <sys/swap.h>
125 # endif
126 # ifdef HAVE_SYS_STAT_H
127 #  include <sys/stat.h>
128 # endif
129 # ifdef HAVE_SYS_PARAM_H
130 #  include <sys/param.h>
131 # endif
132 #endif
134 #ifndef SWAP_CONVERSION
135 # define SWAP_CONVERSION 1
136 #endif
138 #ifdef HAVE_SYS_POLL_H
139 # include "sys/poll.h"
140 #endif
142 /*
143  *
144  * Missing Functions
145  *
146  */
148 #ifndef HAVE_STRTOL
149 # define strtol(a,b,c) atol((a))
150 #endif
152 #ifndef HAVE_STRTOUL
153 # define strtoul(a,b,c) (unsigned long)atol((a))
154 #endif
156 #ifndef HAVE_ASPRINTF
157 int asprintf(char **strp, const char *fmt, ...);
158 #endif
160 #ifndef HAVE_VASPRINTF
161 /* int vasprintf(char **strp, const char *fmt, va_list ap); */
162 #endif
164 #ifndef HAVE_SNPRINTF
165 int snprintf(char *str, size_t size, const  char  *format, ...);
166 #endif
168 #ifndef HAVE_VSNPRINTF
169 int vsnprintf(char *str, size_t size, const char  *format, va_list ap);
170 #endif
172 /* SSL implementations */
173 #ifdef HAVE_GNUTLS_OPENSSL_H
174 #  include <gnutls/openssl.h>
175 #else
176 #  ifdef HAVE_SSL_H
177 #    include <rsa.h>
178 #    include <crypto.h>
179 #    include <x509.h>
180 #    include <pem.h>
181 #    include <ssl.h>
182 #    include <err.h>
183 #  else
184 #    ifdef HAVE_OPENSSL_SSL_H
185 #      include <openssl/rsa.h>
186 #      include <openssl/crypto.h>
187 #      include <openssl/x509.h>
188 #      include <openssl/pem.h>
189 #      include <openssl/ssl.h>
190 #      include <openssl/err.h>
191 #    endif
192 #  endif
193 #endif
195 /*
196  *
197  * Standard Values
198  *
199  */
201 enum {
202         OK = 0,
203         ERROR = -1
204 };
206 /* AIX seems to have this defined somewhere else */
207 #ifndef FALSE
208 enum {
209         FALSE,
210         TRUE
211 };
212 #endif
214 /* Solaris does not have floorf, but floor works. Should probably be in configure */
215 #if defined(__sun) || defined(__sun__)
216 static inline float floorf (float x) { return floor(x); }
217 #endif
219 enum {
220         STATE_OK,
221         STATE_WARNING,
222         STATE_CRITICAL,
223         STATE_UNKNOWN,
224         STATE_DEPENDENT
225 };
227 enum {
228         DEFAULT_SOCKET_TIMEOUT = 10,     /* timeout after 10 seconds */
229         MAX_INPUT_BUFFER = 1024,             /* max size of most buffers we use */
230         MAX_HOST_ADDRESS_LENGTH = 256    /* max size of a host address */
231 };
233 /*
234  *
235  * Internationalization
236  *
237  */
238 #include "gettext.h"
239 #define _(String) gettext (String)
240 #if ! ENABLE_NLS
241 # undef textdomain
242 # define textdomain(Domainname) /* empty */
243 # undef bindtextdomain
244 # define bindtextdomain(Domainname, Dirname) /* empty */
245 #endif
247 /* For non-GNU compilers to ignore __attribute__ */
248 #ifndef __GNUC__
249 # define __attribute__(x) /* do nothing */
250 #endif
252 #endif /* _COMMON_H_ */