Version 1.8.0.0
[socat.git] / compat.h
blobbb7e2d8f1782a14dc9b50737fa756236684b8a62
1 /* source: compat.h */
2 /* Copyright Gerhard Rieger and contributors (see file CHANGES) */
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 #if !HAVE_DECL_ENVIRON && HAVE_VAR_ENVIRON
9 extern char **environ;
10 #endif
12 /*****************************************************************************/
13 /* I dont like this system dependent part, but it would be quite a challenge
14 for configure */
16 /* define if the following does not work:
17 socket()
18 connect() -> Connection refused
19 connect() -> ok
20 instead, it needs close() and socket() between the two connect() attmpts: */
21 #if __FreeBSD__ || __APPLE__ || _AIX || __hpux__ || __osf__
22 # undef SOCKET_CAN_RECOVER
23 #else
24 # define SOCKET_CAN_RECOVER 1
25 #endif
27 /* define if stat() says that pipes are sockets */
28 #if __APPLE__
29 # define PIPE_STATES_SOCKET 1
30 #else
31 # undef PIPE_STATES_SOCKET
32 #endif
34 #if defined(__sun) || defined(__sun__) || defined(__SunOS)
35 # define XIO_ANCILLARY_TYPE_SOLARIS 1
36 #endif
38 /*****************************************************************************/
40 /* substitute some features that might be missing on some platforms */
42 #if !HAVE_TYPE_SIG_ATOMIC_T
43 typedef int sig_atomic_t;
44 #endif
46 #ifndef SHUT_RD
47 # define SHUT_RD 0
48 #endif
49 #ifndef SHUT_WR
50 # define SHUT_WR 1
51 #endif
52 #ifndef SHUT_RDWR
53 # define SHUT_RDWR 2
54 #endif
56 #ifndef MIN
57 # define MIN(x,y) ((x)<=(y)?(x):(y))
58 #endif
60 #ifndef MAX
61 # define MAX(x,y) ((x)>=(y)?(x):(y))
62 #endif
64 /* O_ASYNC: Linux 2.2.10 */
65 #if !defined(O_ASYNC) && defined(FASYNC)
66 # define O_ASYNC FASYNC
67 #endif
69 /* NGROUPS not defined on Solaris */
70 #if !defined(NGROUPS) && defined(NGROUPS_MAX)
71 # define NGROUPS NGROUPS_MAX
72 #endif
74 /* UNIX_PATH_MAX: AIX 4.3.3 */
75 #ifndef UNIX_PATH_MAX
76 # define UNIX_PATH_MAX 104 /*! why 104? Linux: 108 ! */
77 #endif
80 /* SOL_IP: AIX 4.3.3 */
81 #ifndef SOL_IP
82 # define SOL_IP 0
83 #endif
85 /* SOL_TCP: AIX 4.3.3 */
86 #ifndef SOL_TCP
87 # ifdef IPPROTO_TCP
88 # define SOL_TCP IPPROTO_TCP
89 # endif
90 #endif
92 /* POSIX.1 doesn't seem to know sockets */
93 #ifndef S_ISSOCK
94 # define S_ISSOCK(fmode) 0
95 #endif
97 #if defined(IPPROTO_IPV6) && !defined(SOL_IPV6)
98 # define SOL_IPV6 IPPROTO_IPV6
99 #endif
101 #define F_uint8_t "%hu"
102 #define F_uint8_x "%02hx"
103 #define F_int8_t "%hd"
105 #ifndef F_uint16_t
106 # if HAVE_BASIC_UINT16_T==0
107 # define F_uint16_t "%hu"
108 # define F_uint16_x "%04hx"
109 # elif HAVE_BASIC_UINT16_T==2
110 # define F_uint16_t "%hu"
111 # define F_uint16_x "%04hx"
112 # elif HAVE_BASIC_UINT16_T==4
113 # define F_uint16_t "%u"
114 # define F_uint16_x "%04x"
115 # elif HAVE_BASIC_UINT16_T==6
116 # define F_uint16_t "%lu"
117 # define F_uint16_x "%04lx"
118 # else
119 # error "HAVE_BASIC_UINT16_T is out of range:" HAVE_BASIC_UINT16_T
120 # endif
121 #endif
123 #ifndef F_uint32_t
124 # if HAVE_BASIC_UINT32_T==0
125 # define F_uint32_t "%hu"
126 # define F_uint32_x "%08hx"
127 # elif HAVE_BASIC_UINT32_T==2
128 # define F_uint32_t "%hu"
129 # define F_uint32_x "%08hx"
130 # elif HAVE_BASIC_UINT32_T==4
131 # define F_uint32_t "%u"
132 # define F_uint32_x "%08x"
133 # elif HAVE_BASIC_UINT32_T==6
134 # define F_uint32_t "%lu"
135 # define F_uint32_x "%08lx"
136 # else
137 # error "HAVE_BASIC_UINT32_T is out of range:" HAVE_BASIC_UINT32_T
138 # endif
139 #endif
141 #ifndef F_uint64_t
142 # if HAVE_BASIC_UINT64_T==0
143 # define F_uint64_t "%hu"
144 # define F_uint64_x "%016hx"
145 # elif HAVE_BASIC_UINT64_T==2
146 # define F_uint64_t "%hu"
147 # define F_uint64_x "%016hx"
148 # elif HAVE_BASIC_UINT64_T==4
149 # define F_uint64_t "%u"
150 # define F_uint64_x "%016x"
151 # elif HAVE_BASIC_UINT64_T==6
152 # define F_uint64_t "%lu"
153 # define F_uint64_x "%016lx"
154 # elif HAVE_BASIC_UINT64_T==8
155 # define F_uint64_t "%llu"
156 # define F_uint64_x "%016llx"
157 # else
158 # error "HAVE_BASIC_UINT64_T is out of range:" HAVE_BASIC_UINT64_T
159 # endif
160 #endif
162 #ifndef F_int16_t
163 # if HAVE_BASIC_INT16_T==0
164 # define F_int16_t "%hd"
165 # elif HAVE_BASIC_INT16_T==1
166 # define F_int16_t "%hd"
167 # elif HAVE_BASIC_INT16_T==3
168 # define F_int16_t "%d"
169 # elif HAVE_BASIC_INT16_T==5
170 # define F_int16_t "%ld"
171 # else
172 # error "HAVE_BASIC_INT16_T is out of range:" HAVE_BASIC_INT16_T
173 # endif
174 #endif
176 #ifndef F_int32_t
177 # if HAVE_BASIC_INT32_T==0
178 # define F_int32_t "%hd"
179 # elif HAVE_BASIC_INT32_T==1
180 # define F_int32_t "%hd"
181 # elif HAVE_BASIC_INT32_T==3
182 # define F_int32_t "%d"
183 # elif HAVE_BASIC_INT32_T==5
184 # define F_int32_t "%ld"
185 # else
186 # error "HAVE_BASIC_INT32_T is out of range:" HAVE_BASIC_INT32_T
187 # endif
188 #endif
190 #ifndef F_int64_t
191 # if HAVE_BASIC_INT64_T==0
192 # define F_int64_t "%hd"
193 # elif HAVE_BASIC_INT64_T==1
194 # define F_int64_t "%hd"
195 # elif HAVE_BASIC_INT64_T==3
196 # define F_int64_t "%d"
197 # elif HAVE_BASIC_INT64_T==5
198 # define F_int64_t "%ld"
199 # elif HAVE_BASIC_INT64_T==7
200 # define F_int64_t "%lld"
201 # else
202 # error "HAVE_BASIC_INT64_T is out of range:" HAVE_BASIC_INT64_T
203 # endif
204 #endif
206 /* all unsigned */
207 #if !defined(HAVE_BASIC_SIZE_T) || !HAVE_BASIC_SIZE_T
208 # undef HAVE_BASIC_SIZE_T
209 # define HAVE_BASIC_SIZE_T 6
210 #endif
211 #if HAVE_BASIC_SIZE_T==2
212 # define SIZET_MAX USHRT_MAX
213 # define SSIZET_MIN SHRT_MIN
214 # define SSIZET_MAX SHRT_MAX
215 # define F_Zd "%hd"
216 # define F_Zu "%hu"
217 #elif HAVE_BASIC_SIZE_T==4
218 # define SIZET_MAX UINT_MAX
219 # define SSIZET_MIN INT_MIN
220 # define SSIZET_MAX INT_MAX
221 # define F_Zd "%""d"
222 # define F_Zu "%u"
223 #elif HAVE_BASIC_SIZE_T==6
224 # define SIZET_MAX ULONG_MAX
225 # define SSIZET_MIN LONG_MIN
226 # define SSIZET_MAX LONG_MAX
227 # define F_Zd "%ld"
228 # define F_Zu "%lu"
229 #elif HAVE_BASIC_SIZE_T==8
230 # define SIZET_MAX ULLONG_MAX
231 # define SSIZET_MIN LLONG_MIN
232 # define SSIZET_MAX LLONG_MAX
233 # define F_Zd "%Ld"
234 # define F_Zu "%Lu"
235 #else
236 # error "HAVE_BASIC_SIZE_T is out of range:" HAVE_BASIC_SIZE_T
237 #endif
238 #if HAVE_FORMAT_Z
239 # undef F_Zd
240 # undef F_Zu
241 # define F_Zd "%Zd"
242 # define F_Zu "%Zu"
243 #endif
246 /* mode_t is always unsigned; default: unsigned int */
247 #if !defined(HAVE_BASIC_MODE_T) || !HAVE_BASIC_MODE_T
248 # undef HAVE_BASIC_MODE_T
249 # define HAVE_BASIC_MODE_T 4
250 #endif
251 #ifndef F_mode
252 # if HAVE_BASIC_MODE_T==1 || HAVE_BASIC_MODE_T==2
253 #define F_mode "0%03ho"
254 # elif HAVE_BASIC_MODE_T==3 || HAVE_BASIC_MODE_T==4
255 #define F_mode "0%03o"
256 # elif HAVE_BASIC_MODE_T==5 || HAVE_BASIC_MODE_T==6
257 #define F_mode "0%03lo"
258 # else
259 #error "HAVE_BASIC_MODE_T is out of range:" HAVE_BASIC_MODE_T
260 # endif
261 #endif
264 /* default: unsigned int */
265 #if !defined(HAVE_BASIC_PID_T) || !HAVE_BASIC_PID_T
266 # undef HAVE_BASIC_PID_T
267 # define HAVE_BASIC_PID_T 4
268 #endif
269 #ifndef F_pid
270 # if HAVE_BASIC_PID_T==1
271 #define F_pid "%hd"
272 # elif HAVE_BASIC_PID_T==2
273 #define F_pid "%hu"
274 # elif HAVE_BASIC_PID_T==3
275 #define F_pid "%""d"
276 # elif HAVE_BASIC_PID_T==4
277 #define F_pid "%u"
278 # elif HAVE_BASIC_PID_T==5
279 #define F_pid "%ld"
280 # elif HAVE_BASIC_PID_T==6
281 #define F_pid "%lu"
282 # else
283 #error "HAVE_BASIC_PID_T is out of range:" HAVE_BASIC_PID_T
284 # endif
285 #endif
288 /* default: unsigned int */
289 #if !defined(HAVE_BASIC_UID_T) || !HAVE_BASIC_UID_T
290 # undef HAVE_BASIC_UID_T
291 # define HAVE_BASIC_UID_T 4
292 #endif
293 #ifndef F_uid
294 # if HAVE_BASIC_UID_T==1
295 #define F_uid "%hd"
296 # elif HAVE_BASIC_UID_T==2
297 #define F_uid "%hu"
298 # elif HAVE_BASIC_UID_T==3
299 #define F_uid "%""d"
300 # elif HAVE_BASIC_UID_T==4
301 #define F_uid "%u"
302 # elif HAVE_BASIC_UID_T==5
303 #define F_uid "%ld"
304 # elif HAVE_BASIC_UID_T==6
305 #define F_uid "%lu"
306 # else
307 #error "HAVE_BASIC_UID_T is out of range:" HAVE_BASIC_UID_T
308 # endif
309 #endif
312 /* default: unsigned int */
313 #if !defined(HAVE_BASIC_GID_T) || !HAVE_BASIC_GID_T
314 # undef HAVE_BASIC_GID_T
315 # define HAVE_BASIC_GID_T 4
316 #endif
317 #ifndef F_gid
318 # if HAVE_BASIC_GID_T==1
319 #define F_gid "%hd"
320 # elif HAVE_BASIC_GID_T==2
321 #define F_gid "%hu"
322 # elif HAVE_BASIC_GID_T==3
323 #define F_gid "%""d"
324 # elif HAVE_BASIC_GID_T==4
325 #define F_gid "%u"
326 # elif HAVE_BASIC_GID_T==5
327 #define F_gid "%ld"
328 # elif HAVE_BASIC_GID_T==6
329 #define F_gid "%lu"
330 # else
331 #error "HAVE_BASIC_GID_T is out of range:" HAVE_BASIC_GID_T
332 # endif
333 #endif
336 /* all signed; default: long */
337 #if !defined(HAVE_BASIC_TIME_T) || !HAVE_BASIC_TIME_T
338 # undef HAVE_BASIC_TIME_T
339 # define HAVE_BASIC_TIME_T 5
340 #endif
341 #ifndef F_time
342 # if HAVE_BASIC_TIME_T==1
343 #define F_time "%hd"
344 # elif HAVE_BASIC_TIME_T==2
345 #define F_time "%hu"
346 # elif HAVE_BASIC_TIME_T==3
347 #define F_time "%""d"
348 # elif HAVE_BASIC_TIME_T==4
349 #define F_time "%u"
350 # elif HAVE_BASIC_TIME_T==5
351 #define F_time "%ld"
352 # elif HAVE_BASIC_TIME_T==6
353 #define F_time "%lu"
354 # elif HAVE_BASIC_TIME_T==7
355 #define F_time "%Ld"
356 # elif HAVE_BASIC_TIME_T==8
357 #define F_time "%Lu"
358 # else
359 #error "HAVE_BASIC_TIME_T is out of range:" HAVE_BASIC_TIME_T
360 # endif
361 #endif
364 /* default: int */
365 #if !defined(HAVE_BASIC_SOCKLEN_T) || !HAVE_BASIC_SOCKLEN_T
366 # undef HAVE_BASIC_SOCKLEN_T
367 # define HAVE_BASIC_SOCKLEN_T 3
368 #endif
369 #ifndef F_socklen
370 # if HAVE_BASIC_SOCKLEN_T==1
371 #define F_socklen "%hd"
372 # elif HAVE_BASIC_SOCKLEN_T==2
373 #define F_socklen "%hu"
374 # elif HAVE_BASIC_SOCKLEN_T==3
375 #define F_socklen "%""d"
376 # elif HAVE_BASIC_SOCKLEN_T==4
377 #define F_socklen "%u"
378 # elif HAVE_BASIC_SOCKLEN_T==5
379 #define F_socklen "%ld"
380 # elif HAVE_BASIC_SOCKLEN_T==6
381 #define F_socklen "%lu"
382 # elif HAVE_BASIC_SOCKLEN_T==7
383 #define F_socklen "%Ld"
384 # elif HAVE_BASIC_SOCKLEN_T==8
385 #define F_socklen "%Lu"
386 # else
387 #error "HAVE_BASIC_SOCKLEN_T is out of range:" HAVE_BASIC_SOCKLEN_T
388 # endif
389 #endif
391 #if !defined(HAVE_BASIC_OFF_T) || !HAVE_BASIC_OFF_T
392 # undef HAVE_BASIC_OFF_T
393 # define HAVE_BASIC_OFF_T 5 /*long*/
394 #endif
395 #ifndef F_off
396 # if HAVE_BASIC_OFF_T==3
397 # define F_off "%""d"
398 # elif HAVE_BASIC_OFF_T==5
399 # define F_off "%ld"
400 # elif HAVE_BASIC_OFF_T==7
401 # define F_off "%Ld"
402 # else
403 #error "HAVE_BASIC_OFF_T is out of range:" HAVE_BASIC_OFF_T
404 # endif
405 #endif
407 /* default: long long */
408 #if !defined(HAVE_BASIC_OFF64_T) || !HAVE_BASIC_OFF64_T
409 # undef HAVE_BASIC_OFF64_T
410 # define HAVE_BASIC_OFF64_T 7
411 #endif
412 #ifndef F_off64
413 # if HAVE_BASIC_OFF64_T==1
414 #define F_off64 "%hd"
415 # elif HAVE_BASIC_OFF64_T==2
416 #define F_off64 "%hu"
417 # elif HAVE_BASIC_OFF64_T==3
418 #define F_off64 "%""d"
419 # elif HAVE_BASIC_OFF64_T==4
420 #define F_off64 "%u"
421 # elif HAVE_BASIC_OFF64_T==5
422 #define F_off64 "%ld"
423 # elif HAVE_BASIC_OFF64_T==6
424 #define F_off64 "%lu"
425 # elif HAVE_BASIC_OFF64_T==7
426 #define F_off64 "%Ld"
427 # elif HAVE_BASIC_OFF64_T==8
428 #define F_off64 "%Lu"
429 # else
430 #error "HAVE_BASIC_OFF64_T is out of range:" HAVE_BASIC_OFF64_T
431 # endif
432 #endif
435 /* all unsigned; default: unsigned long */
436 #if !defined(HAVE_BASIC_DEV_T) || !HAVE_BASIC_DEV_T
437 # undef HAVE_BASIC_DEV_T
438 # define HAVE_BASIC_DEV_T 6
439 #endif
440 #ifndef F_dev
441 # if HAVE_BASIC_DEV_T==1
442 #define F_dev "%hd"
443 # elif HAVE_BASIC_DEV_T==2
444 #define F_dev "%hu"
445 # elif HAVE_BASIC_DEV_T==3
446 #define F_dev "%""d"
447 # elif HAVE_BASIC_DEV_T==4
448 #define F_dev "%u"
449 # elif HAVE_BASIC_DEV_T==5
450 #define F_dev "%ld"
451 # elif HAVE_BASIC_DEV_T==6
452 #define F_dev "%lu"
453 # elif HAVE_BASIC_DEV_T==7
454 #define F_dev "%Ld"
455 # elif HAVE_BASIC_DEV_T==8
456 #define F_dev "%Lu"
457 # else
458 #error "HAVE_BASIC_DEV_T is out of range:" HAVE_BASIC_DEV_T
459 # endif
460 #endif
463 #if _WITH_TERMIOS
464 #if !defined(HAVE_BASIC_SPEED_T) || !HAVE_BASIC_SPEED_T
465 # undef HAVE_BASIC_SPEED_T
466 # define HAVE_BASIC_SPEED_T 4
467 #endif
468 #ifndef F_speed
469 # if HAVE_BASIC_SPEED_T==1
470 #define F_speed "%hd"
471 # elif HAVE_BASIC_SPEED_T==2
472 #define F_speed "%hu"
473 # elif HAVE_BASIC_SPEED_T==3
474 #define F_speed "%""d"
475 # elif HAVE_BASIC_SPEED_T==4
476 #define F_speed "%u"
477 # elif HAVE_BASIC_SPEED_T==5
478 #define F_speed "%ld"
479 # elif HAVE_BASIC_SPEED_T==6
480 #define F_speed "%lu"
481 # elif HAVE_BASIC_SPEED_T==7
482 #define F_speed "%Ld"
483 # elif HAVE_BASIC_SPEED_T==8
484 #define F_speed "%Lu"
485 # else
486 #error "HAVE_BASIC_SPEED_T is out of range:" HAVE_BASIC_SPEED_T
487 # endif
488 #endif
489 #endif /* _WITH_TERMIOS */
491 /* all unsigned; default; unsigned long */
492 #if !defined(HAVE_TYPEOF_ST_INO) || !HAVE_TYPEOF_ST_INO
493 # undef HAVE_TYPEOF_ST_INO
494 # define HAVE_TYPEOF_ST_INO 6
495 #endif
496 #ifndef F_st_ino
497 # if HAVE_TYPEOF_ST_INO==1
498 #define F_st_ino "%hd"
499 # elif HAVE_TYPEOF_ST_INO==2
500 #define F_st_ino "%hu"
501 # elif HAVE_TYPEOF_ST_INO==3
502 #define F_st_ino "%""d"
503 # elif HAVE_TYPEOF_ST_INO==4
504 #define F_st_ino "%u"
505 # elif HAVE_TYPEOF_ST_INO==5
506 #define F_st_ino "%ld"
507 # elif HAVE_TYPEOF_ST_INO==6
508 #define F_st_ino "%lu"
509 # elif HAVE_TYPEOF_ST_INO==7 /* Cygwin 1.5 */
510 #define F_st_ino "%Ld"
511 # elif HAVE_TYPEOF_ST_INO==8
512 #define F_st_ino "%Lu"
513 # else
514 #error "HAVE_TYPEOF_ST_INO is out of range:" HAVE_TYPEOF_ST_INO
515 # endif
516 #endif
518 /* all unsigned; default; unsigned long long */
519 #if !defined(HAVE_TYPEOF_ST64_INO) || !HAVE_TYPEOF_ST64_INO
520 # undef HAVE_TYPEOF_ST64_INO
521 # define HAVE_TYPEOF_ST64_INO 8
522 #endif
523 #ifndef F_st64_ino
524 # if HAVE_TYPEOF_ST64_INO==1
525 #define F_st64_ino "%hd"
526 # elif HAVE_TYPEOF_ST64_INO==2
527 #define F_st64_ino "%hu"
528 # elif HAVE_TYPEOF_ST64_INO==3
529 #define F_st64_ino "%""d"
530 # elif HAVE_TYPEOF_ST64_INO==4
531 #define F_st64_ino "%u"
532 # elif HAVE_TYPEOF_ST64_INO==5
533 #define F_st64_ino "%ld"
534 # elif HAVE_TYPEOF_ST64_INO==6
535 #define F_st64_ino "%lu"
536 # elif HAVE_TYPEOF_ST64_INO==7
537 #define F_st64_ino "%Ld"
538 # elif HAVE_TYPEOF_ST64_INO==8
539 #define F_st64_ino "%Lu"
540 # else
541 #error "HAVE_TYPEOF_ST64_INO is out of range:" HAVE_TYPEOF_ST64_INO
542 # endif
543 #endif
545 /* default: unsigned short */
546 #if !defined(HAVE_TYPEOF_ST_NLINK) || !HAVE_TYPEOF_ST_NLINK
547 # undef HAVE_TYPEOF_ST_NLINK
548 # define HAVE_TYPEOF_ST_NLINK 2
549 #endif
550 #ifndef F_st_nlink
551 # if HAVE_TYPEOF_ST_NLINK==1
552 #define F_st_nlink "%hd"
553 # elif HAVE_TYPEOF_ST_NLINK==2
554 #define F_st_nlink "%hu"
555 # elif HAVE_TYPEOF_ST_NLINK==3
556 #define F_st_nlink "%""d"
557 # elif HAVE_TYPEOF_ST_NLINK==4
558 #define F_st_nlink "%u"
559 # elif HAVE_TYPEOF_ST_NLINK==5
560 #define F_st_nlink "%ld"
561 # elif HAVE_TYPEOF_ST_NLINK==6
562 #define F_st_nlink "%lu"
563 # elif HAVE_TYPEOF_ST_NLINK==7
564 #define F_st_nlink "%Ld"
565 # elif HAVE_TYPEOF_ST_NLINK==8
566 #define F_st_nlink "%Lu"
567 # else
568 #error "HAVE_TYPEOF_ST_NLINK is out of range:" HAVE_TYPEOF_ST_NLINK
569 # endif
570 #endif
572 /* all signed; default: long */
573 #if !defined(HAVE_TYPEOF_ST_SIZE) || !HAVE_TYPEOF_ST_SIZE
574 # undef HAVE_TYPEOF_ST_SIZE
575 # define HAVE_TYPEOF_ST_SIZE 5
576 #endif
577 #ifndef F_st_size
578 # if HAVE_TYPEOF_ST_SIZE==1
579 #define F_st_size "%hd"
580 # elif HAVE_TYPEOF_ST_SIZE==2
581 #define F_st_size "%hu"
582 # elif HAVE_TYPEOF_ST_SIZE==3
583 #define F_st_size "%""d"
584 # elif HAVE_TYPEOF_ST_SIZE==4
585 #define F_st_size "%u"
586 # elif HAVE_TYPEOF_ST_SIZE==5
587 #define F_st_size "%ld"
588 # elif HAVE_TYPEOF_ST_SIZE==6
589 #define F_st_size "%lu"
590 # elif HAVE_TYPEOF_ST_SIZE==7
591 #define F_st_size "%Ld"
592 # elif HAVE_TYPEOF_ST_SIZE==8
593 #define F_st_size "%Lu"
594 # else
595 #error "HAVE_TYPEOF_ST_SIZE is out of range:" HAVE_TYPEOF_ST_SIZE
596 # endif
597 #endif
599 /* all signed; default: long long */
600 #if !defined(HAVE_TYPEOF_ST64_SIZE) || !HAVE_TYPEOF_ST64_SIZE
601 # undef HAVE_TYPEOF_ST64_SIZE
602 # define HAVE_TYPEOF_ST64_SIZE 7
603 #endif
604 #ifndef F_st64_size
605 # if HAVE_TYPEOF_ST64_SIZE==1
606 #define F_st64_size "%hd"
607 # elif HAVE_TYPEOF_ST64_SIZE==2
608 #define F_st64_size "%hu"
609 # elif HAVE_TYPEOF_ST64_SIZE==3
610 #define F_st64_size "%""d"
611 # elif HAVE_TYPEOF_ST64_SIZE==4
612 #define F_st64_size "%u"
613 # elif HAVE_TYPEOF_ST64_SIZE==5
614 #define F_st64_size "%ld"
615 # elif HAVE_TYPEOF_ST64_SIZE==6
616 #define F_st64_size "%lu"
617 # elif HAVE_TYPEOF_ST64_SIZE==7
618 #define F_st64_size "%Ld"
619 # elif HAVE_TYPEOF_ST64_SIZE==8
620 #define F_st64_size "%Lu"
621 # else
622 #error "HAVE_TYPEOF_ST64_SIZE is out of range:" HAVE_TYPEOF_ST64_SIZE
623 # endif
624 #endif
626 /* very different results; default: long */
627 #if !defined(HAVE_TYPEOF_ST_BLKSIZE) || !HAVE_TYPEOF_ST_BLKSIZE
628 # undef HAVE_TYPEOF_ST_BLKSIZE
629 # define HAVE_TYPEOF_ST_BLKSIZE 5
630 #endif
631 #ifndef F_st_blksize
632 # if HAVE_TYPEOF_ST_BLKSIZE==1
633 #define F_st_blksize "%hd"
634 # elif HAVE_TYPEOF_ST_BLKSIZE==2
635 #define F_st_blksize "%hu"
636 # elif HAVE_TYPEOF_ST_BLKSIZE==3
637 #define F_st_blksize "%""d"
638 # elif HAVE_TYPEOF_ST_BLKSIZE==4
639 #define F_st_blksize "%u"
640 # elif HAVE_TYPEOF_ST_BLKSIZE==5
641 #define F_st_blksize "%ld"
642 # elif HAVE_TYPEOF_ST_BLKSIZE==6
643 #define F_st_blksize "%lu"
644 # elif HAVE_TYPEOF_ST_BLKSIZE==7
645 #define F_st_blksize "%Ld"
646 # elif HAVE_TYPEOF_ST_BLKSIZE==8
647 #define F_st_blksize "%Lu"
648 # else
649 #error "HAVE_TYPEOF_ST_BLKSIZE is out of range:" HAVE_TYPEOF_ST_BLKSIZE
650 # endif
651 #endif
653 /* default: long */
654 #if !defined(HAVE_TYPEOF_ST_BLOCKS) || !HAVE_TYPEOF_ST_BLOCKS
655 # undef HAVE_TYPEOF_ST_BLOCKS
656 # define HAVE_TYPEOF_ST_BLOCKS 5
657 #endif
658 #ifndef F_st_blocks
659 # if HAVE_TYPEOF_ST_BLOCKS==1
660 #define F_st_blocks "%hd"
661 # elif HAVE_TYPEOF_ST_BLOCKS==2
662 #define F_st_blocks "%hu"
663 # elif HAVE_TYPEOF_ST_BLOCKS==3
664 #define F_st_blocks "%""d"
665 # elif HAVE_TYPEOF_ST_BLOCKS==4
666 #define F_st_blocks "%u"
667 # elif HAVE_TYPEOF_ST_BLOCKS==5
668 #define F_st_blocks "%ld"
669 # elif HAVE_TYPEOF_ST_BLOCKS==6
670 #define F_st_blocks "%lu"
671 # elif HAVE_TYPEOF_ST_BLOCKS==7
672 #define F_st_blocks "%Ld"
673 # elif HAVE_TYPEOF_ST_BLOCKS==8
674 #define F_st_blocks "%Lu"
675 # else
676 #error "HAVE_TYPEOF_ST_BLOCKS is out of range:" HAVE_TYPEOF_ST_BLOCKS
677 # endif
678 #endif
680 /* default: long long */
681 #if !defined(HAVE_TYPEOF_ST64_BLOCKS) || !HAVE_TYPEOF_ST64_BLOCKS
682 # undef HAVE_TYPEOF_ST64_BLOCKS
683 # define HAVE_TYPEOF_ST64_BLOCKS 7
684 #endif
685 #ifndef F_st64_blocks
686 # if HAVE_TYPEOF_ST64_BLOCKS==1
687 #define F_st64_blocks "%hd"
688 # elif HAVE_TYPEOF_ST64_BLOCKS==2
689 #define F_st64_blocks "%hu"
690 # elif HAVE_TYPEOF_ST64_BLOCKS==3
691 #define F_st64_blocks "%""d"
692 # elif HAVE_TYPEOF_ST64_BLOCKS==4
693 #define F_st64_blocks "%u"
694 # elif HAVE_TYPEOF_ST64_BLOCKS==5
695 #define F_st64_blocks "%ld"
696 # elif HAVE_TYPEOF_ST64_BLOCKS==6
697 #define F_st64_blocks "%lu"
698 # elif HAVE_TYPEOF_ST64_BLOCKS==7
699 #define F_st64_blocks "%Ld"
700 # elif HAVE_TYPEOF_ST64_BLOCKS==8
701 #define F_st64_blocks "%Lu"
702 # else
703 #error "HAVE_TYPEOF_ST64_BLOCKS is out of range:" HAVE_TYPEOF_ST64_BLOCKS
704 # endif
705 #endif
708 /* at least for Linux */
709 #define F_tv_sec "%ld"
711 /* default: long */
712 #if !defined(HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC) || !HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC
713 # undef HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC
714 # define HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC 5
715 #endif
716 #ifndef F_tv_usec
717 # if HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC==1
718 #define F_tv_usec "%06hd"
719 # elif HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC==2
720 #define F_tv_usec "%06hu"
721 # elif HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC==3
722 #define F_tv_usec "%06d"
723 # elif HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC==4
724 #define F_tv_usec "%06u"
725 # elif HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC==5
726 #define F_tv_usec "%06ld"
727 # elif HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC==6
728 #define F_tv_usec "%06lu"
729 # elif HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC==7
730 #define F_tv_usec "%06Ld"
731 # elif HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC==8
732 #define F_tv_usec "%06Lu"
733 # else
734 #error "HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC is out of range:" HAVE_TYPEOF_STRUCT_TIMEVAL_TV_USEC
735 # endif
736 #endif
738 /* default: long */
739 #if !defined(HAVE_TYPEOF_STRUCT_TIMESPEC_TV_NSEC) || !HAVE_TYPEOF_STRUCT_TIMESPEC_TV_NSEC
740 # undef HAVE_TYPEOF_STRUCT_TIMESPEC_TV_NSEC
741 # define HAVE_TYPEOF_STRUCT_TIMESPEC_TV_NSEC 5
742 #endif
743 #ifndef F_tv_nsec
744 # if HAVE_TYPEOF_STRUCT_TIMESPEC_TV_NSEC==1
745 #define F_tv_nsec "%09hd"
746 # elif HAVE_TYPEOF_STRUCT_TIMESPEC_TV_NSEC==2
747 #define F_tv_nsec "%09hu"
748 # elif HAVE_TYPEOF_STRUCT_TIMESPEC_TV_NSEC==3
749 #define F_tv_nsec "%09d"
750 # elif HAVE_TYPEOF_STRUCT_TIMESPEC_TV_NSEC==4
751 #define F_tv_nsec "%09u"
752 # elif HAVE_TYPEOF_STRUCT_TIMESPEC_TV_NSEC==5
753 #define F_tv_nsec "%09ld"
754 # elif HAVE_TYPEOF_STRUCT_TIMESPEC_TV_NSEC==6
755 #define F_tv_nsec "%09lu"
756 # elif HAVE_TYPEOF_STRUCT_TIMESPEC_TV_NSEC==7
757 #define F_tv_nsec "%09Ld"
758 # elif HAVE_TYPEOF_STRUCT_TIMESPEC_TV_NSEC==8
759 #define F_tv_nsec "%09Lu"
760 # else
761 #error "HAVE_TYPEOF_STRUCT_TIMESPEC_TV_NSEC is out of range:" HAVE_TYPEOF_STRUCT_TIMESPEC_TV_NSEC
762 # endif
763 #endif
765 /* default: long */
766 #if !defined(HAVE_TYPEOF_RLIM_MAX) || !HAVE_TYPEOF_RLIM_MAX
767 # undef HAVE_TYPEOF_RLIM_MAX
768 # define HAVE_TYPEOF_RLIM_MAX 5
769 #endif
770 #ifndef F_rlim_max
771 # if HAVE_TYPEOF_RLIM_MAX==1
772 #define F_rlim_max "hd"
773 # elif HAVE_TYPEOF_RLIM_MAX==2
774 #define F_rlim_max "hu"
775 # elif HAVE_TYPEOF_RLIM_MAX==3
776 #define F_rlim_max "d"
777 # elif HAVE_TYPEOF_RLIM_MAX==4
778 #define F_rlim_max "u"
779 # elif HAVE_TYPEOF_RLIM_MAX==5
780 #define F_rlim_max "ld"
781 # elif HAVE_TYPEOF_RLIM_MAX==6
782 #define F_rlim_max "lu"
783 # elif HAVE_TYPEOF_RLIM_MAX==7
784 #define F_rlim_max "Ld"
785 # elif HAVE_TYPEOF_RLIM_MAX==8
786 #define F_rlim_max "Lu"
787 # else
788 #error "HAVE_TYPEOF_RLIM_MAX is out of range:" HAVE_TYPEOF_RLIM_MAX
789 # endif
790 #endif
792 /* sigset_t printing - not an exact solution yet */
793 #define F_sigset "0x%06lx"
794 typedef unsigned long T_sigset;
796 /* default: socklen_t */
797 #if !defined(HAVE_TYPEOF_STRUCT_CMSGHDR_CMSG_LEN) || !HAVE_TYPEOF_STRUCT_CMSGHDR_CMSG_LEN
798 # undef HAVE_TYPEOF_STRUCT_CMSGHDR_CMSG_LEN
799 # define HAVE_TYPEOF_STRUCT_CMSGHDR_CMSG_LEN HAVE_BASIC_SOCKLEN_T
800 #endif
801 #ifndef F_cmsg_len
802 # if HAVE_TYPEOF_STRUCT_CMSGHDR_CMSG_LEN==1
803 #define F_cmsg_len "%""hd"
804 # elif HAVE_TYPEOF_STRUCT_CMSGHDR_CMSG_LEN==2
805 #define F_cmsg_len "%""hu"
806 # elif HAVE_TYPEOF_STRUCT_CMSGHDR_CMSG_LEN==3
807 #define F_cmsg_len "%""d"
808 # elif HAVE_TYPEOF_STRUCT_CMSGHDR_CMSG_LEN==4
809 #define F_cmsg_len "%""u"
810 # elif HAVE_TYPEOF_STRUCT_CMSGHDR_CMSG_LEN==5
811 #define F_cmsg_len "%""ld"
812 # elif HAVE_TYPEOF_STRUCT_CMSGHDR_CMSG_LEN==6
813 #define F_cmsg_len "%""lu"
814 # elif HAVE_TYPEOF_STRUCT_CMSGHDR_CMSG_LEN==7
815 #define F_cmsg_len "%""Ld"
816 # elif HAVE_TYPEOF_STRUCT_CMSGHDR_CMSG_LEN==8
817 #define F_cmsg_len "%""Lu"
818 # else
819 #error "HAVE_TYPEOF_STRUCT_CMSGHDR_CMSG_LEN is out of range:" HAVE_TYPEOF_STRUCT_CMSGHDR_CMSG_LEN
820 # endif
821 #endif
823 /* basic type of struct timeval tv_usec */
824 #ifndef F_tv_usec
825 # if TYPEOF_STRUCT_TIMEVAL_TV_USEC==1
826 # define F_tv_usec "%hu"
827 # elif TYPEOF_STRUCT_TIMEVAL_TV_USEC==3
828 # define F_tv_usec "%u"
829 # elif TYPEOF_STRUCT_TIMEVAL_TV_USEC==5
830 # define F_tv_usec "%lu"
831 # endif
832 #endif
834 /* OpenBSD (at least 7.2) does better with this special setting */
835 #if __FreeBSD__ || __OpenBSD__
836 # define UNIX_TIGHTSOCKLEN false
837 #else
838 # define UNIX_TIGHTSOCKLEN true
839 #endif
841 /* Cygwin 1.3.22 has the prototypes, but not the type... */
842 #ifndef HAVE_TYPE_STAT64
843 # undef HAVE_STAT64
844 # undef HAVE_FSTAT64
845 # undef HAVE_LSTAT64
846 #endif
847 #ifndef HAVE_TYPE_OFF64
848 # undef HAVE_LSEEK64
849 # undef HAVE_FTRUNCATE64
850 #endif
852 #if !defined(NETDB_INTERNAL) && defined(h_NETDB_INTERNAL)
853 # define NETDB_INTERNAL h_NETDB_INTERNAL
854 #endif
856 #ifndef INET_ADDRSTRLEN
857 # define INET_ADDRSTRLEN sizeof(struct sockaddr_in)
858 #endif
860 #if !HAVE_PROTOTYPE_HSTRERROR
861 /* with MacOSX this is char * */
862 extern const char *hstrerror(int);
863 #endif
865 #if !HAVE_PROTOTYPE_LIB_strndup
866 extern char *strndup (const char *s, size_t n);
867 #endif
869 #endif /* !defined(__compat_h_included) */