2 /* Copyright Gerhard Rieger 2001-2008 */
3 /* Published under the GNU General Public License V.2, see file COPYING */
5 #ifndef __compat_h_included
6 #define __compat_h_included 1
8 /*****************************************************************************/
9 /* I dont like this system dependent part, but it would be quite a challenge
12 /* define if the following does not work:
14 connect() -> Connection refused
16 instead, it needs close() and socket() between the two connect() attmpts: */
17 #if __FreeBSD__ || __APPLE__ || _AIX || __hpux__ || __osf__
18 # undef SOCKET_CAN_RECOVER
20 # define SOCKET_CAN_RECOVER 1
23 /* define if stat() says that pipes are sockets */
25 # define PIPE_STATES_SOCKET 1
27 # undef PIPE_STATES_SOCKET
30 /*****************************************************************************/
32 /* substitute some features that might be missing on some platforms */
45 # define MIN(x,y) ((x)<=(y)?(x):(y))
49 # define MAX(x,y) ((x)>=(y)?(x):(y))
52 /* O_ASYNC: Linux 2.2.10 */
53 #if !defined(O_ASYNC) && defined(FASYNC)
54 # define O_ASYNC FASYNC
57 /* NGROUPS not defined on Solaris */
58 #if !defined(NGROUPS) && defined(NGROUPS_MAX)
59 # define NGROUPS NGROUPS_MAX
62 /* UNIX_PATH_MAX: AIX 4.3.3 */
64 # define UNIX_PATH_MAX 104 /*! why 104? Linux: 108 ! */
68 /* SOL_IP: AIX 4.3.3 */
73 /* SOL_TCP: AIX 4.3.3 */
75 # define SOL_TCP IPPROTO_TCP
78 /* POSIX.1 doesn't seem to know sockets */
80 # define S_ISSOCK(fmode) 0
83 #if defined(IPPROTO_IPV6) && !defined(SOL_IPV6)
84 # define SOL_IPV6 IPPROTO_IPV6
88 #if !defined(HAVE_BASIC_SIZE_T) || !HAVE_BASIC_SIZE_T
89 # undef HAVE_BASIC_SIZE_T
90 # define HAVE_BASIC_SIZE_T 6
92 #if HAVE_BASIC_SIZE_T==2
93 # define SIZET_MAX USHRT_MAX
94 # define SSIZET_MIN SHRT_MIN
95 # define SSIZET_MAX SHRT_MAX
98 #elif HAVE_BASIC_SIZE_T==4
99 # define SIZET_MAX UINT_MAX
100 # define SSIZET_MIN INT_MIN
101 # define SSIZET_MAX INT_MAX
104 #elif HAVE_BASIC_SIZE_T==6
105 # define SIZET_MAX ULONG_MAX
106 # define SSIZET_MIN LONG_MIN
107 # define SSIZET_MAX LONG_MAX
110 #elif HAVE_BASIC_SIZE_T==8
111 # define SIZET_MAX ULLONG_MAX
112 # define SSIZET_MIN LLONG_MIN
113 # define SSIZET_MAX LLONG_MAX
117 # error "HAVE_BASIC_SIZE_T is out of range:" HAVE_BASIC_SIZE_T
127 /* mode_t is always unsigned; default: unsigned int */
128 #if !defined(HAVE_BASIC_MODE_T) || !HAVE_BASIC_MODE_T
129 # undef HAVE_BASIC_MODE_T
130 # define HAVE_BASIC_MODE_T 4
133 # if HAVE_BASIC_MODE_T==1 || HAVE_BASIC_MODE_T==2
134 #define F_mode "0%03ho"
135 # elif HAVE_BASIC_MODE_T==3 || HAVE_BASIC_MODE_T==4
136 #define F_mode "0%03o"
137 # elif HAVE_BASIC_MODE_T==5 || HAVE_BASIC_MODE_T==6
138 #define F_mode "0%03lo"
140 #error "HAVE_BASIC_MODE_T is out of range:" HAVE_BASIC_MODE_T
145 /* default: unsigned int */
146 #if !defined(HAVE_BASIC_PID_T) || !HAVE_BASIC_PID_T
147 # undef HAVE_BASIC_PID_T
148 # define HAVE_BASIC_PID_T 4
151 # if HAVE_BASIC_PID_T==1
153 # elif HAVE_BASIC_PID_T==2
155 # elif HAVE_BASIC_PID_T==3
157 # elif HAVE_BASIC_PID_T==4
159 # elif HAVE_BASIC_PID_T==5
161 # elif HAVE_BASIC_PID_T==6
164 #error "HAVE_BASIC_PID_T is out of range:" HAVE_BASIC_PID_T
169 /* default: unsigned int */
170 #if !defined(HAVE_BASIC_UID_T) || !HAVE_BASIC_UID_T
171 # undef HAVE_BASIC_UID_T
172 # define HAVE_BASIC_UID_T 4
175 # if HAVE_BASIC_UID_T==1
177 # elif HAVE_BASIC_UID_T==2
179 # elif HAVE_BASIC_UID_T==3
181 # elif HAVE_BASIC_UID_T==4
183 # elif HAVE_BASIC_UID_T==5
185 # elif HAVE_BASIC_UID_T==6
188 #error "HAVE_BASIC_UID_T is out of range:" HAVE_BASIC_UID_T
193 /* default: unsigned int */
194 #if !defined(HAVE_BASIC_GID_T) || !HAVE_BASIC_GID_T
195 # undef HAVE_BASIC_GID_T
196 # define HAVE_BASIC_GID_T 4
199 # if HAVE_BASIC_GID_T==1
201 # elif HAVE_BASIC_GID_T==2
203 # elif HAVE_BASIC_GID_T==3
205 # elif HAVE_BASIC_GID_T==4
207 # elif HAVE_BASIC_GID_T==5
209 # elif HAVE_BASIC_GID_T==6
212 #error "HAVE_BASIC_GID_T is out of range:" HAVE_BASIC_GID_T
217 /* all signed; default: long */
218 #if !defined(HAVE_BASIC_TIME_T) || !HAVE_BASIC_TIME_T
219 # undef HAVE_BASIC_TIME_T
220 # define HAVE_BASIC_TIME_T 5
223 # if HAVE_BASIC_TIME_T==1
225 # elif HAVE_BASIC_TIME_T==2
227 # elif HAVE_BASIC_TIME_T==3
229 # elif HAVE_BASIC_TIME_T==4
231 # elif HAVE_BASIC_TIME_T==5
233 # elif HAVE_BASIC_TIME_T==6
236 #error "HAVE_BASIC_TIME_T is out of range:" HAVE_BASIC_TIME_T
242 #if !defined(HAVE_BASIC_SOCKLEN_T) || !HAVE_BASIC_SOCKLEN_T
243 # undef HAVE_BASIC_SOCKLEN_T
244 # define HAVE_BASIC_SOCKLEN_T 3
247 # if HAVE_BASIC_SOCKLEN_T==1
248 #define F_socklen "%hd"
249 # elif HAVE_BASIC_SOCKLEN_T==2
250 #define F_socklen "%hu"
251 # elif HAVE_BASIC_SOCKLEN_T==3
252 #define F_socklen "%d"
253 # elif HAVE_BASIC_SOCKLEN_T==4
254 #define F_socklen "%u"
255 # elif HAVE_BASIC_SOCKLEN_T==5
256 #define F_socklen "%ld"
257 # elif HAVE_BASIC_SOCKLEN_T==6
258 #define F_socklen "%lu"
260 #error "HAVE_BASIC_SOCKLEN_T is out of range:" HAVE_BASIC_SOCKLEN_T
264 /* might be checked in later versions */
269 /* default: long long */
270 #if !defined(HAVE_BASIC_OFF64_T) || !HAVE_BASIC_OFF64_T
271 # undef HAVE_BASIC_OFF64_T
272 # define HAVE_BASIC_OFF64_T 7
275 # if HAVE_BASIC_OFF64_T==1
276 #define F_off64 "%hd"
277 # elif HAVE_BASIC_OFF64_T==2
278 #define F_off64 "%hu"
279 # elif HAVE_BASIC_OFF64_T==3
281 # elif HAVE_BASIC_OFF64_T==4
283 # elif HAVE_BASIC_OFF64_T==5
284 #define F_off64 "%ld"
285 # elif HAVE_BASIC_OFF64_T==6
286 #define F_off64 "%lu"
287 # elif HAVE_BASIC_OFF64_T==7
288 #define F_off64 "%Ld"
289 # elif HAVE_BASIC_OFF64_T==8
290 #define F_off64 "%Lu"
292 #error "HAVE_BASIC_OFF64_T is out of range:" HAVE_BASIC_OFF64_T
297 /* all unsigned; default: unsigned long */
298 #if !defined(HAVE_TYPEOF_ST_DEV) || !HAVE_TYPEOF_ST_DEV
299 # undef HAVE_TYPEOF_ST_DEV
300 # define HAVE_TYPEOF_ST_DEV 6
303 # if HAVE_TYPEOF_ST_DEV==1
304 #define F_st_dev "%hd"
305 # elif HAVE_TYPEOF_ST_DEV==2
306 #define F_st_dev "%hu"
307 # elif HAVE_TYPEOF_ST_DEV==3
308 #define F_st_dev "%d"
309 # elif HAVE_TYPEOF_ST_DEV==4
310 #define F_st_dev "%u"
311 # elif HAVE_TYPEOF_ST_DEV==5
312 #define F_st_dev "%ld"
313 # elif HAVE_TYPEOF_ST_DEV==6
314 #define F_st_dev "%lu"
315 # elif HAVE_TYPEOF_ST_DEV==7
316 #define F_st_dev "%Ld"
317 # elif HAVE_TYPEOF_ST_DEV==8
318 #define F_st_dev "%Lu"
320 #error "HAVE_TYPEOF_ST_DEV is out of range:" HAVE_TYPEOF_ST_DEV
324 /* all unsigned; default; unsigned long */
325 #if !defined(HAVE_TYPEOF_ST_INO) || !HAVE_TYPEOF_ST_INO
326 # undef HAVE_TYPEOF_ST_INO
327 # define HAVE_TYPEOF_ST_INO 6
330 # if HAVE_TYPEOF_ST_INO==1
331 #define F_st_ino "%hd"
332 # elif HAVE_TYPEOF_ST_INO==2
333 #define F_st_ino "%hu"
334 # elif HAVE_TYPEOF_ST_INO==3
335 #define F_st_ino "%d"
336 # elif HAVE_TYPEOF_ST_INO==4
337 #define F_st_ino "%u"
338 # elif HAVE_TYPEOF_ST_INO==5
339 #define F_st_ino "%ld"
340 # elif HAVE_TYPEOF_ST_INO==6
341 #define F_st_ino "%lu"
342 # elif HAVE_TYPEOF_ST_INO==7 /* Cygwin 1.5 */
343 #define F_st_ino "%Ld"
344 # elif HAVE_TYPEOF_ST_INO==8
345 #define F_st_ino "%Lu"
347 #error "HAVE_TYPEOF_ST_INO is out of range:" HAVE_TYPEOF_ST_INO
351 /* all unsigned; default; unsigned long long */
352 #if !defined(HAVE_TYPEOF_ST64_INO) || !HAVE_TYPEOF_ST64_INO
353 # undef HAVE_TYPEOF_ST64_INO
354 # define HAVE_TYPEOF_ST64_INO 8
357 # if HAVE_TYPEOF_ST64_INO==1
358 #define F_st64_ino "%hd"
359 # elif HAVE_TYPEOF_ST64_INO==2
360 #define F_st64_ino "%hu"
361 # elif HAVE_TYPEOF_ST64_INO==3
362 #define F_st64_ino "%d"
363 # elif HAVE_TYPEOF_ST64_INO==4
364 #define F_st64_ino "%u"
365 # elif HAVE_TYPEOF_ST64_INO==5
366 #define F_st64_ino "%ld"
367 # elif HAVE_TYPEOF_ST64_INO==6
368 #define F_st64_ino "%lu"
369 # elif HAVE_TYPEOF_ST64_INO==7
370 #define F_st64_ino "%Ld"
371 # elif HAVE_TYPEOF_ST64_INO==8
372 #define F_st64_ino "%Lu"
374 #error "HAVE_TYPEOF_ST64_INO is out of range:" HAVE_TYPEOF_ST64_INO
378 /* default: unsigned short */
379 #if !defined(HAVE_TYPEOF_ST_NLINK) || !HAVE_TYPEOF_ST_NLINK
380 # undef HAVE_TYPEOF_ST_NLINK
381 # define HAVE_TYPEOF_ST_NLINK 2
384 # if HAVE_TYPEOF_ST_NLINK==1
385 #define F_st_nlink "%hd"
386 # elif HAVE_TYPEOF_ST_NLINK==2
387 #define F_st_nlink "%hu"
388 # elif HAVE_TYPEOF_ST_NLINK==3
389 #define F_st_nlink "%d"
390 # elif HAVE_TYPEOF_ST_NLINK==4
391 #define F_st_nlink "%u"
392 # elif HAVE_TYPEOF_ST_NLINK==5
393 #define F_st_nlink "%ld"
394 # elif HAVE_TYPEOF_ST_NLINK==6
395 #define F_st_nlink "%lu"
397 #error "HAVE_TYPEOF_ST_NLINK is out of range:" HAVE_TYPEOF_ST_NLINK
401 /* all signed; default: long */
402 #if !defined(HAVE_TYPEOF_ST_SIZE) || !HAVE_TYPEOF_ST_SIZE
403 # undef HAVE_TYPEOF_ST_SIZE
404 # define HAVE_TYPEOF_ST_SIZE 5
407 # if HAVE_TYPEOF_ST_SIZE==1
408 #define F_st_size "%hd"
409 # elif HAVE_TYPEOF_ST_SIZE==2
410 #define F_st_size "%hu"
411 # elif HAVE_TYPEOF_ST_SIZE==3
412 #define F_st_size "%d"
413 # elif HAVE_TYPEOF_ST_SIZE==4
414 #define F_st_size "%u"
415 # elif HAVE_TYPEOF_ST_SIZE==5
416 #define F_st_size "%ld"
417 # elif HAVE_TYPEOF_ST_SIZE==6
418 #define F_st_size "%lu"
419 # elif HAVE_TYPEOF_ST_SIZE==7
420 #define F_st_size "%Ld"
421 # elif HAVE_TYPEOF_ST_SIZE==8
422 #define F_st_size "%Lu"
424 #error "HAVE_TYPEOF_ST_SIZE is out of range:" HAVE_TYPEOF_ST_SIZE
428 /* all signed; default: long long */
429 #if !defined(HAVE_TYPEOF_ST64_SIZE) || !HAVE_TYPEOF_ST64_SIZE
430 # undef HAVE_TYPEOF_ST64_SIZE
431 # define HAVE_TYPEOF_ST64_SIZE 7
434 # if HAVE_TYPEOF_ST64_SIZE==1
435 #define F_st64_size "%hd"
436 # elif HAVE_TYPEOF_ST64_SIZE==2
437 #define F_st64_size "%hu"
438 # elif HAVE_TYPEOF_ST64_SIZE==3
439 #define F_st64_size "%d"
440 # elif HAVE_TYPEOF_ST64_SIZE==4
441 #define F_st64_size "%u"
442 # elif HAVE_TYPEOF_ST64_SIZE==5
443 #define F_st64_size "%ld"
444 # elif HAVE_TYPEOF_ST64_SIZE==6
445 #define F_st64_size "%lu"
446 # elif HAVE_TYPEOF_ST64_SIZE==7
447 #define F_st64_size "%Ld"
448 # elif HAVE_TYPEOF_ST64_SIZE==8
449 #define F_st64_size "%Lu"
451 #error "HAVE_TYPEOF_ST64_SIZE is out of range:" HAVE_TYPEOF_ST64_SIZE
455 /* very different results; default: long */
456 #if !defined(HAVE_TYPEOF_ST_BLKSIZE) || !HAVE_TYPEOF_ST_BLKSIZE
457 # undef HAVE_TYPEOF_ST_BLKSIZE
458 # define HAVE_TYPEOF_ST_BLKSIZE 5
461 # if HAVE_TYPEOF_ST_BLKSIZE==1
462 #define F_st_blksize "%hd"
463 # elif HAVE_TYPEOF_ST_BLKSIZE==2
464 #define F_st_blksize "%hu"
465 # elif HAVE_TYPEOF_ST_BLKSIZE==3
466 #define F_st_blksize "%d"
467 # elif HAVE_TYPEOF_ST_BLKSIZE==4
468 #define F_st_blksize "%u"
469 # elif HAVE_TYPEOF_ST_BLKSIZE==5
470 #define F_st_blksize "%ld"
471 # elif HAVE_TYPEOF_ST_BLKSIZE==6
472 #define F_st_blksize "%lu"
474 #error "HAVE_TYPEOF_ST_BLKSIZE is out of range:" HAVE_TYPEOF_ST_BLKSIZE
479 #if !defined(HAVE_TYPEOF_ST_BLOCKS) || !HAVE_TYPEOF_ST_BLOCKS
480 # undef HAVE_TYPEOF_ST_BLOCKS
481 # define HAVE_TYPEOF_ST_BLOCKS 5
484 # if HAVE_TYPEOF_ST_BLOCKS==1
485 #define F_st_blocks "%hd"
486 # elif HAVE_TYPEOF_ST_BLOCKS==2
487 #define F_st_blocks "%hu"
488 # elif HAVE_TYPEOF_ST_BLOCKS==3
489 #define F_st_blocks "%d"
490 # elif HAVE_TYPEOF_ST_BLOCKS==4
491 #define F_st_blocks "%u"
492 # elif HAVE_TYPEOF_ST_BLOCKS==5
493 #define F_st_blocks "%ld"
494 # elif HAVE_TYPEOF_ST_BLOCKS==6
495 #define F_st_blocks "%lu"
496 # elif HAVE_TYPEOF_ST_BLOCKS==7
497 #define F_st_blocks "%Ld"
498 # elif HAVE_TYPEOF_ST_BLOCKS==8
499 #define F_st_blocks "%Lu"
501 #error "HAVE_TYPEOF_ST_BLOCKS is out of range:" HAVE_TYPEOF_ST_BLOCKS
505 /* default: long long */
506 #if !defined(HAVE_TYPEOF_ST64_BLOCKS) || !HAVE_TYPEOF_ST64_BLOCKS
507 # undef HAVE_TYPEOF_ST64_BLOCKS
508 # define HAVE_TYPEOF_ST64_BLOCKS 7
510 #ifndef F_st64_blocks
511 # if HAVE_TYPEOF_ST64_BLOCKS==1
512 #define F_st64_blocks "%hd"
513 # elif HAVE_TYPEOF_ST64_BLOCKS==2
514 #define F_st64_blocks "%hu"
515 # elif HAVE_TYPEOF_ST64_BLOCKS==3
516 #define F_st64_blocks "%d"
517 # elif HAVE_TYPEOF_ST64_BLOCKS==4
518 #define F_st64_blocks "%u"
519 # elif HAVE_TYPEOF_ST64_BLOCKS==5
520 #define F_st64_blocks "%ld"
521 # elif HAVE_TYPEOF_ST64_BLOCKS==6
522 #define F_st64_blocks "%lu"
523 # elif HAVE_TYPEOF_ST64_BLOCKS==7
524 #define F_st64_blocks "%Ld"
525 # elif HAVE_TYPEOF_ST64_BLOCKS==8
526 #define F_st64_blocks "%Lu"
528 #error "HAVE_TYPEOF_ST64_BLOCKS is out of range:" HAVE_TYPEOF_ST64_BLOCKS
533 /* at least for Linux */
534 #define F_tv_sec "%ld"
537 #if !defined(HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC) || !HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC
538 # undef HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC
539 # define HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC 5
542 # if HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC==1
543 #define F_tv_usec "%06hd"
544 # elif HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC==2
545 #define F_tv_usec "%06hu"
546 # elif HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC==3
547 #define F_tv_usec "%06d"
548 # elif HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC==4
549 #define F_tv_usec "%06u"
550 # elif HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC==5
551 #define F_tv_usec "%06ld"
552 # elif HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC==6
553 #define F_tv_usec "%06lu"
554 # elif HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC==7
555 #define F_tv_usec "%06Ld"
556 # elif HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC==8
557 #define F_tv_usec "%06Lu"
559 #error "HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC is out of range:" HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC
564 #if !defined(HAVE_TYPEOF_RLIM_MAX) || !HAVE_TYPEOF_RLIM_MAX
565 # undef HAVE_TYPEOF_RLIM_MAX
566 # define HAVE_TYPEOF_RLIM_MAX 5
569 # if HAVE_TYPEOF_RLIM_MAX==1
570 #define F_rlim_max "hd"
571 # elif HAVE_TYPEOF_RLIM_MAX==2
572 #define F_rlim_max "hu"
573 # elif HAVE_TYPEOF_RLIM_MAX==3
574 #define F_rlim_max "d"
575 # elif HAVE_TYPEOF_RLIM_MAX==4
576 #define F_rlim_max "u"
577 # elif HAVE_TYPEOF_RLIM_MAX==5
578 #define F_rlim_max "ld"
579 # elif HAVE_TYPEOF_RLIM_MAX==6
580 #define F_rlim_max "lu"
581 # elif HAVE_TYPEOF_RLIM_MAX==7
582 #define F_rlim_max "Ld"
583 # elif HAVE_TYPEOF_RLIM_MAX==8
584 #define F_rlim_max "Lu"
586 #error "HAVE_TYPEOF_RLIM_MAX is out of range:" HAVE_TYPEOF_RLIM_MAX
590 /* Cygwin 1.3.22 has the prototypes, but not the type... */
591 #ifndef HAVE_TYPE_STAT64
596 #ifndef HAVE_TYPE_OFF64
598 # undef HAVE_FTRUNCATE64
601 #if !defined(NETDB_INTERNAL) && defined(h_NETDB_INTERNAL)
602 # define NETDB_INTERNAL h_NETDB_INTERNAL
605 #ifndef INET_ADDRSTRLEN
606 # define INET_ADDRSTRLEN sizeof(struct sockaddr_in)
609 #if !HAVE_PROTOTYPE_HSTRERROR
610 /* with MacOSX this is char * */
611 extern const char *hstrerror(int);
614 /*****************************************************************************/
615 /* here are the declarations of compat.c */
619 void (*sa_handler
)(int);
620 void (*sa_sigaction
)(int, siginfo_t
*, void *);
631 /*clock_t si_utime;*/
632 /*clock_t si_stime;*/
640 extern int sigaction(int signum
, const struct sigaction
*act
,
641 struct sigaction
*oldact
);
642 #endif /* !HAVE_SIGACTION */
644 #endif /* !defined(__compat_h_included) */