1 /*******************************************************************************
2  * $Id: sysconf.h,v 1.72 2011/09/14 13:06:46 marc Exp marc $
3  *
4  * sysconf.h
5  * (C) 2000-2011 by Marc Huber <Marc.Huber@web.de>
6  * All rights reserved.
7  *
8  * OS specific definitions.
9  *
10  * Most of the software you'll find in the package should compile fine for
11  * most real operating systems (MacOS/Darwin, Sun Solaris, FreeBSD, OpenBSD,
12  * NetBSD, DragonFly BSD, Linux), both in 32 and 64bit variants. Cygwin is
13  * semi-supported (in a degarded mode, due to lack of file descriptor
14  * passing).
15  *
16  * The version number checking below is partially based on more or less
17  * educated guessing.
18  *
19  ******************************************************************************/
20 #if !defined(__SYSCONF_H__)
21 #define __SYSCONF_H__
22 /*******************************************************************************
23  * BSD summary define
24  */
25 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__DragonFly__)
26 # define __ANY_BSD__
27 #endif
28 /*******************************************************************************
29  * Sun Forte 6 C defines __sun, but we prefer __sun__ for GCC compatibility.
30  * Plus, the compiler doesn't understand "__inline__", but accepts "inline".
31  */
32 #if defined(__SUNPRO_C)
33 #  if !defined(__sun__) && defined(__sun)
34 #    define __sun__
35 #  endif
36 #  define __inline__ inline
37 #endif
38 /*******************************************************************************
39  * Intel(R) C++ Compiler for 32-bit applications
40  *
41  * Version 6.0 and higher:
42  * The evaluation and non-commercial copies are free and seem to work fine. You
43  * may need to set LD_LIBRARY_PATH to wherever your Intel shared libraries are.
44  *
45  * Older versions of icc don't support ISO standard C99:
46  */
47 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 800
48 #  define __func__ __FUNCTION__
49 #endif
50 /*******************************************************************************
51  * Non-C99 compliant gcc versions. Guessing about the minor version number.
52  */
53 #if defined(__GNUC__) && __GNUC__ < 3 && __GNUC_MINOR__ < 95
54 #  define __func__ __FUNCTION__
55 #endif
56 /*******************************************************************************
57  * Don't attempt to use GNU-C extensions if we're not using GCC ...
58  */
59 #if !defined(__GNUC__)
60 #  define __attribute__(A)
61 #endif
62 /* ... or compatible. */
63 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER > 1000
64 #  undef __attribute__
65 #endif
66 /*******************************************************************************
67  * For SUN Solaris, XPG-4.2 (aka. UNIX-95) extensions need to be enabled
68  * for ancillary messages. We only want XPG-4.2 to be defined for one
69  * particular file, and there shouldn't be any need to link the xpg library,
70  * as the required functionality is in fact part of the kernel.
71  */
72 #if defined(__sun__) && defined(__SCM_C__)
73 #  include <sys/types.h>
74 #  define _XOPEN_SOURCE
75 #  define _XOPEN_SOURCE_EXTENDED 1
76 #  define _XPG4_2
77 /*
78  * Had to define _XPG6 for Solaris-10 ... seems to break SXDE, however.
79  * #  define _XPG6
80  */
81 /*
82  * For Solaris 2.6, <sys/socket.h> features some more weirdness ...
83  */
84 #  if OSLEVEL < 0x05070000
85 #    define recvmsg __xnet_recvmsg
86 #    define sendmsg __xnet_sendmsg
87 #  endif
88 #endif
89 /******************************************************************************/
90 #include <dlfcn.h>
91 #include <syslog.h>
92 #include <sys/types.h>
93 #include <sys/socket.h>
94 #include <sys/un.h>
95 #include <netinet/in.h>
96 #include <fcntl.h>
97 #if defined(__linux__)
98 /* need to #include this before the openssl stuff ... */
99 #  define __USE_XOPEN
100 #  include <unistd.h>
101 #  undef __USE_XOPEN
102 #endif
103 #if defined(WITH_SSL)
104 #  include <openssl/ssl.h>
105 #endif
106 /*******************************************************************************
107  * Endianess:
108  */
109 #if defined(__sun__)
110 #  include <sys/isa_defs.h>
111 #  ifndef __LITTLE_ENDIAN
112 #    define __LITTLE_ENDIAN 1234
113 #  endif
114 #  ifndef __BIG_ENDIAN
115 #    define __BIG_ENDIAN    4321
116 #  endif
117 #  if defined(_BIG_ENDIAN)
118 #    define __BYTE_ORDER __BIG_ENDIAN
119 #  else
120 #    define __BYTE_ORDER __LITTLE_ENDIAN
121 #  endif
122 #endif
123 #if defined(__linux__)
124 #  include <endian.h>
125 #endif
126 #if defined(__ANY_BSD__)
127 #  include <sys/endian.h>
128 #  ifndef __LITTLE_ENDIAN
129 #    define __LITTLE_ENDIAN 1234
130 #  endif
131 #  ifndef __BIG_ENDIAN
132 #    define __BIG_ENDIAN    4321
133 #  endif
134 #  ifndef __BYTE_ORDER
135 #  if BYTE_ORDER == LITTLE_ENDIAN
136 #    define __BYTE_ORDER __LITTLE_ENDIAN
137 #  else
138 #    define __BYTE_ORDER __BIG_ENDIAN
139 #  endif
140 #  endif
141 #endif
142 /*******************************************************************************
143  * Prototype for crypt(3)
144  */
145 #if (!defined(WITH_SSL) || OPENSSL_VERSION_NUMBER >= 0x00907000L)
146 #  if defined(__sun__)
147 #    undef des_crypt
148 #    include <crypt.h>
149 #  endif
150 #  if defined(__ANY_BSD__)
151 #    include <unistd.h>
152 #  endif
153 #  if defined(__CYGWIN__)
154 #    include <crypt.h>
155 #  endif
156 #else
157 /* Use crypt(3) from libcrypto */
158 #  ifdef WITH_LIBCRYPT
159 #    undef WITH_LIBCRYPT
160 #  endif
161 #endif
162 /*******************************************************************************
163  * Has struct flock a l_sysid member? I guess that's specific to Solaris.
164  */
165 #if defined(__sun__)
166 #  define WITH_FLOCK_L_SYSID
167 #endif
168 /*******************************************************************************
169  * Is dirfd() available?
170  */
171 #if defined(__linux__)
172 #  define WITH_DIRFD
173 #endif
174 #if defined(__sun__)
175 #  define WITH_DIRFD
176 #  if OSLEVEL < 0x050b0000	/* guessing, again */
177 #    if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)
178 #      define dirfd(A) A->dd_fd
179 #    else
180 #      define dirfd(A) A->d_fd
181 #    endif
182 # endif
183 #endif
184 #if defined(__ANY_BSD__)
185 #  define WITH_DIRFD
186 #endif
187 /*******************************************************************************
188  * IPv6 stuff
189  */
190 #if !defined(s6_addr32)
191 /*
192  * Solaris 8 protects s6_addr32 with _KERNEL:
193  */
194 #  if defined(__sun__)
195 #    define s6_addr32	_S6_un._S6_u32
196 #  endif
197 /*
198  * The BSDs have different naming conventions:
199  */
200 #  if defined(__ANY_BSD__)
201 #    define s6_addr32	__u6_addr.__u6_addr32
202 #  endif
203 #  if defined(__DragonFly__)
204 #    undef s6_addr32
205 #    define s6_addr32	_s6_addr32
206 #  endif
207 #endif
208 /*******************************************************************************
209  * Suns prototype for the PAM conversion function differs from Linux PAM
210  * and OpenPAM:
211  */
212 #if defined(__sun__)
213 #  define PAM_CONV_ARG2_TYPE struct pam_message
214 #else
215 #  define PAM_CONV_ARG2_TYPE const struct pam_message
216 #endif
217 /*******************************************************************************
218  * getgrouplist(3) isn't standard, but available on some systems.
219  *
220  * While my custom routines work equally well, getgrouplist(3) would add the
221  * automatically generated groups on MacOS. These don't seem to be present
222  * otherwise.
223  *
224  * Alas, there are at least two prototypes in the wild, and Solaris doesn't
225  * support getgrouplist(3) at all, so it's currently safer to fall back to
226  * my custom implementation. Performance-wise, this doesn't matter.
227  */
228 #if 0
229 #if defined(__linux__)
230 #  define HAVE_GETGROUPLIST
231 #  define GETGROUPLIST_ARG2_TYPE gid_t
232 #endif
233 #if defined(__ANY_BSD__)
234 #  define HAVE_GETGROUPLIST
235 #  define GETGROUPLIST_ARG2_TYPE int
236 #endif
237 #endif
238 /*******************************************************************************
239  * The BSDs don't need to define O_LARGEFILE. Set it to 0 if undefined.
240  */
241 #if !defined(O_LARGEFILE)
242 #  define O_LARGEFILE 0
243 #endif
244 /*******************************************************************************
245  * O_NOFOLLOW is defined on FreeBSD and Linux. Set to 0 if not defined.
246  */
247 #if !defined(O_NOFOLLOW)
248 #  define O_NOFOLLOW 0
249 #endif
250 /*******************************************************************************
251  * If and where to find basename(3):
252  */
253 #if defined(__linux__)
254 #  define WITH_BASENAME
255 #  define WITH_BASENAME_LIBGEN
256 #endif
257 #if defined(__sun__)
258 #  define WITH_BASENAME
259 #  define WITH_BASENAME_LIBGEN
260 #endif
261 #if defined(__ANY_BSD__)
262 #  define WITH_BASENAME
263 #  define WITH_BASENAME_LIBGEN
264 #endif
265 /*******************************************************************************
266  * UNIX_PATH_MAX
267  */
268 #if !defined(UNIX_PATH_MAX)
269 #  define UNIX_PATH_MAX 108
270 #endif
271 /*******************************************************************************
272  * INET6_ADDRSTRLEN
273  */
274 #if !defined(INET6_ADDRSTRLEN)
275 #  define INET6_ADDRSTRLEN 46
276 #endif
277 /*******************************************************************************
278  * INADDR_NONE
279  */
280 #if !defined(INADDR_NONE)
281 #  define INADDR_NONE ((unsigned int) -1)
282 #endif
283 /*******************************************************************************
284  * mmap(2)
285  */
286 #if !defined(WITH_MMAP)
287 #  if defined(__sun__)
288 #    define WITH_MMAP
289 #  endif
290 #  if defined(__linux__)
291 #    define WITH_MMAP
292 #  endif
293 #  if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__DragonFly__)
294 #    define WITH_MMAP
295 #  endif
296 #  if defined(__NetBSD__) && OSLEVEL >= 0x01040000
297 #    define WITH_MMAP
298 #  endif
299 #endif
300 #if defined(WITH_MMAP)
301 #  include <sys/mman.h>
302 #  if !defined(MADV_NORMAL) && defined(POSIX_MADV_NORMAL)
303 #    define madvise posix_madvise
304 #    define MADV_NORMAL		POSIX_MADV_NORMAL
305 #    define MADV_RANDOM		POSIX_MADV_RANDOM
306 #    define MADV_WILLNEED	POSIX_MADV_WILLNEED
307 #    define MADV_DONTNEED	POSIX_MADV_DONTNEED
308 #    define MADV_SEQUENTIAL	POSIX_MADV_SEQUENTIAL
309 #  endif
310 #  if !defined(MADV_NORMAL)
311 #    define madvise(A,B,C)	{}
312 #    define MADV_NORMAL		0
313 #    define MADV_RANDOM		0
314 #    define MADV_WILLNEED	0
315 #    define MADV_DONTNEED	0
316 #    define MADV_SEQUENTIAL	0
317 #  endif
318 #endif
319 /*******************************************************************************
320  * 64bit architecture? Solaris defines _LP64, Linux __WORDSIZE, FreeBSD
321  * ELF_WORD_SIZE, apparently. Don't know about the others ... could probably
322  * check for machine architecture.
323  */
324 #if defined(__linux__) && defined(__WORDSIZE) && __WORDSIZE == 64
325 #  ifndef _LP64
326 #    define _LP64
327 #  endif
328 #endif
329 #if defined(__FreeBSD__)
330 #  include <machine/elf.h>
331 #  if defined(__ELF_WORD_SIZE) && ELF_WORD_SIZE == 64
332 #    ifndef _LP64
333 #      define _LP64
334 #    endif
335 #  endif
336 #endif
337 /*******************************************************************************
338  * Size of off_t:
339  *
340  * Actually, the GNU C library defines __USE_FILE_OFFSET64 in <features.h>.
341  */
342 #if !defined(__USE_FILE_OFFSET64)
343 #  if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
344 /* Compiled with -D_FILE_OFFSET_BITS=64 */
345 #    define __USE_FILE_OFFSET64
346 #  endif
347 #endif
348 #if !defined(__USE_FILE_OFFSET64)
349 #  if defined(_LP64)
350 /* 64bit machines, e.g. Sun Sparc with 64bit compiler */
351 #    define __USE_FILE_OFFSET64
352 #  endif
353 #endif
354 #if !defined(__USE_FILE_OFFSET64)
355 #  if defined(__ANY_BSD__)
356 /* The BSDs have a 64bit off_t by default */
357 #    define __USE_FILE_OFFSET64
358 #  endif
359 #endif
360 /*******************************************************************************
361  * sendfile(2)
362  */
363 #if defined(__linux__) && OSLEVEL >= 0x02020000
364 #  define WITH_SENDFILE
365 #endif
366 #if defined(__linux__) && OSLEVEL >= 0x02050006
367 #  define WITH_SENDFILE64
368 #endif
369 #if defined(__FreeBSD__) && OSLEVEL >= 0x03000000
370 #  define WITH_SENDFILE
371 #endif
372 #if defined(__APPLE__)
373 #  define WITH_SENDFILE
374 #endif
375 #if defined(__DragonFly__)
376 #  define WITH_SENDFILE
377 #endif
378 /*******************************************************************************
379  * alloca(3) prototype:
380  */
381 #if defined(__sun__) || defined(__linux__)
382 #  include <alloca.h>
383 #endif
384 #if defined(__ANY_BSD__)
385 #  include <stdlib.h>
386 #endif
387 /*******************************************************************************
388  * Shadow passwords, password handling routines:
389  */
390 #if defined(__sun__) || defined(__linux__)
391 #  define WITH_SHADOWPWD
392 #endif
393 /*******************************************************************************
394  * BSDs have a sun_len field in struct sockaddr_un:
395  */
396 #if defined(__ANY_BSD__)
397 #  define HAS_SUN_LEN
398 #endif
399 /*******************************************************************************
400  * Some systems actually come with a working setproctitle implementation:
401  */
402 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
403 #  define HAVE_SETPROCTITLE
404 #endif
405 #if defined(__FreeBSD__) && OSLEVEL < 0x04000000
406 #  include <libutil.h>
407 #endif
408 /* Others need to use our custom implementation: */
409 #if defined(__linux__) || defined(__APPLE__)
410 #  define WANT_SETPROCTITLE
411 #endif
412 /*******************************************************************************
413  * On non-ELF systems, an underscore needs to be prepended to dynamic library
414  * symbol names. We're going to need that for dlsym().
415  */
416 #if !defined(__ELF__)
417 #  if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
418 #    define DLSYM_PREFIX "_"
419 #  endif
420 #endif
421 #if !defined(DLSYM_PREFIX)
422 #  define DLSYM_PREFIX ""
423 #endif
424 /*******************************************************************************
425  * socklen_t is unavailable on older systems:
426  */
427 #if defined(__sun__) && OSLEVEL < 0x05070000
428 #  define socklen_t size_t
429 #endif
430 #if defined(__NetBSD__) && OSLEVEL < 0x01040000
431 #  define socklen_t size_t
432 #endif
433 /*******************************************************************************
434  * Some systems have AF_INET6 defined, but in fact don't support IPv6:
435  */
436 #if defined(__FreeBSD__) && OSLEVEL < 0x04000000
437 #  undef AF_INET6
438 #endif
439 #if defined(__NetBSD__) && OSLEVEL < 0x01050000
440 #  undef AF_INET6
441 #endif
442 /*******************************************************************************
443  * Double-check for SCTP
444  */
445 #ifndef AF_SCTP
446 #  undef WITH_SCTP
447 #endif
448 /*******************************************************************************
449  * OpenBSD doesn't define RTLD_GLOBAL
450  */
451 #if !defined(RTLD_GLOBAL)
452 #  define RTLD_GLOBAL 0
453 #endif
454 /*******************************************************************************
455  * Cygwin still lacks file descriptor passing.
456  */
457 #if defined(__CYGWIN__)
458 #  define BROKEN_FD_PASSING
459 #endif
460 /*******************************************************************************
461  * misc
462  */
463 #ifndef LOG_PRIMASK
464 #  define LOG_PRIMASK 0x07
465 #endif
466 /******************************************************************************/
467 #endif				/* __SYSCONF_H__ */
468