posix.h
1 /* ========================================================================== */
2 /* Operating system API */
3 /*
4  * Include this as the first header in a C source file that should access the
5  * operating system. A C++ source file must never include this header.
6  */
7 
8 #ifdef __cplusplus
9 # error The POSIX.1-1990 API has no C++ binding!
10 #endif /* __cplusplus */
11 
12 
13 /* ========================================================================== */
14 /* Configuration (must be 1st) */
15 
16 #include "config.h"
17 
18 
19 /* ========================================================================== */
20 /* Tell system headers that they should be POSIX conformant (must be 2nd) */
21 
22 #ifdef HDR_POSIX_H
23  /* This must always be the first header that is included */
24 # error Never include this header more than once!
25 #endif /* NDR_POSIX_H */
26 #define HDR_POSIX_H 1
27 
28 /*
29  * Check twice before requesting another API, this can have many side effects.
30  * It is obvious that older APIs lack support for some features, but newer APIs
31  * also have features removed (because they where deprecated). In both cases we
32  * must provide replacements for (different) missing features.
33  *
34  * See also: ../INSTALL.HP-UX
35  */
36 
37 #if CFG_USE_POSIX_API >= 202405L
38 # define _POSIX_C_SOURCE 202405L
39 #elif CFG_USE_POSIX_API == 200809L
40 # define _POSIX_C_SOURCE 200809L
41 #elif CFG_USE_POSIX_API == 200112L
42  /*
43  * Attention:
44  * At least POSIX.1g-2000 is required for IP6 option
45  */
46 # define _POSIX_C_SOURCE 200112L
47 #else /* CFG_USE_POSIX_API */
48  /*
49  * Attention:
50  * POSIX.1-1990 is not sufficient because we need the POSIX.1b-1993 Realtime
51  * and POSIX.1c-1996 thread extensions
52  */
53 # define _POSIX_C_SOURCE 199506L
54 #endif /* CFG_USE_POSIX_API */
55 
56 #if CFG_USE_XSI
57 # if CFG_USE_POSIX_API == 202405L
58  /*
59  * Attention:
60  * The POSIX version must be not greater than 202405 if this value is 800:
61  * <https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html#tag_16_02_01_02>
62  */
63 # define _XOPEN_SOURCE 800
64 # elif CFG_USE_POSIX_API == 200809L
65  /*
66  * Attention:
67  * The POSIX version must be not greater than 200809 if this value is 700:
68  * <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_02_01_02>
69  */
70 # define _XOPEN_SOURCE 700
71 # elif CFG_USE_POSIX_API == 200112L
72  /*
73  * Attention:
74  * The POSIX version must be not greater than 200112 if this value is 600:
75  * <http://pubs.opengroup.org/onlinepubs/007904975/functions/xsh_chap02_02.html#tag_02_02_01_02>
76  */
77 # define _XOPEN_SOURCE 600
78 # else /* CFG_USE_POSIX_API */
79  /*
80  * Attention:
81  * The POSIX version must be not greater than 199506 if this value is 500:
82  * <http://pubs.opengroup.org/onlinepubs/7908799/xns/compilation.html>
83  */
84 # define _XOPEN_SOURCE 500
85 # endif /* CFG_USE_POSIX_API */
86 #endif /* CFG_USE_XSI */
87 
88 /*
89  * This definition allows linking objects compiled for XNS and BSD sockets:
90  * <http://docstore.mik.ua/manuals/hp-ux/en/B2355-60130/xopen_networking.7.html>
91  */
92 #if defined(__hpux) && CFG_USE_XSI
93 # define _HPUX_ALT_XOPEN_SOCKET_API 1
94 #endif /* defined(__hpux) && CFG_USE_XSI */
95 
96 #include <sys/types.h>
97 #include <pthread.h>
98 #include <stdlib.h>
99 #include <stddef.h>
100 #include <limits.h>
101 #include <errno.h>
102 #include <unistd.h>
103 
104 
105 /* ========================================================================== */
106 /* POSIX.1b realtime support */
107 
108 #include <time.h>
109 
110 #define api_posix_struct_timespec struct timespec
111 
112 #define api_posix_nanosleep nanosleep
113 
114 #if CFG_USE_FSC
115 # define api_posix_fsync fsync
116 #else /* CFG_USE_FSC */
117 int api_posix_fsync(int);
118 #endif /* CFG_USE_FSC */
119 
120 
121 /* ========================================================================== */
122 /* POSIX.1c thread support */
123 
124 #define API_POSIX_PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
125 #define API_POSIX_PTHREAD_COND_INITIALIZER PTHREAD_COND_INITIALIZER
126 #define API_POSIX_PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE
127 
128 #define api_posix_pthread_t pthread_t
129 #define api_posix_pthread_mutex_t pthread_mutex_t
130 #define api_posix_pthread_cond_t pthread_cond_t
131 
132 #define api_posix_pthread_create pthread_create
133 #define api_posix_pthread_cancel pthread_cancel
134 #define api_posix_pthread_setcancelstate pthread_setcancelstate
135 #define api_posix_pthread_join pthread_join
136 #define api_posix_pthread_self pthread_self
137 #define api_posix_pthread_equal pthread_equal
138 #define api_posix_pthread_sigmask pthread_sigmask
139 #define api_posix_pthread_cleanup_push pthread_cleanup_push
140 #define api_posix_pthread_cleanup_pop pthread_cleanup_pop
141 #define api_posix_pthread_mutex_lock pthread_mutex_lock
142 #define api_posix_pthread_mutex_trylock pthread_mutex_trylock
143 #define api_posix_pthread_mutex_unlock pthread_mutex_unlock
144 #define api_posix_pthread_cond_wait pthread_cond_wait
145 #define api_posix_pthread_cond_signal pthread_cond_signal
146 
147 
148 /* ========================================================================== */
149 /* POSIX.2 support */
150 
151 #include <stdio.h>
152 
153 #define api_posix_popen popen
154 #define api_posix_pclose pclose
155 
156 
157 /* ========================================================================== */
158 /* System limits */
159 
160 #if CFG_HDR_INTTYPES_H
161 # include <inttypes.h>
162 #endif /* CFG_HDR_INTTYPES_H */
163 
164 #define API_POSIX_INT_MAX INT_MAX
165 #define API_POSIX_UINT_MAX UINT_MAX
166 #define API_POSIX_LONG_MAX LONG_MAX
167 #define API_POSIX_ULONG_MAX ULONG_MAX
168 #define API_POSIX_SSIZE_MAX SSIZE_MAX
169 #ifdef SIZE_MAX
170 # define API_POSIX_SIZE_MAX SIZE_MAX
171 #else /* SIZE_MAX */
172 # define API_POSIX_SIZE_MAX ((size_t) API_POSIX_SSIZE_MAX * (size_t) 2)
173 #endif /* SIZE_MAX */
174 
175 
176 /* ========================================================================== */
177 /* Environment and return values */
178 
179 /* Pointer to array with environment variables */
180 extern char** environ;
181 #define api_posix_environ environ
182 
183 /* Standard return values for processes */
184 #define API_POSIX_EXIT_SUCCESS EXIT_SUCCESS
185 #define API_POSIX_EXIT_FAILURE EXIT_FAILURE
186 
187 
188 /* ========================================================================== */
189 /* System information */
190 
191 #include <sys/utsname.h>
192 
193 #define api_posix_struct_utsname struct utsname
194 
195 #define api_posix_uname uname
196 
197 
198 /* ========================================================================== */
199 /* System errors */
200 
201 #define API_POSIX_EACCES EACCES
202 #define API_POSIX_EAFNOSUPPORT EAFNOSUPPORT
203 #define API_POSIX_EAGAIN EAGAIN
204 #define API_POSIX_EBADF EBADF
205 #define API_POSIX_ECONNREFUSED ECONNREFUSED
206 #define API_POSIX_EEXIST EEXIST
207 #define API_POSIX_EINTR EINTR
208 #define API_POSIX_EINPROGRESS EINPROGRESS
209 #define API_POSIX_EINVAL EINVAL
210 #define API_POSIX_EIO EIO
211 #define API_POSIX_ENOENT ENOENT
212 #define API_POSIX_ENOMEM ENOMEM
213 #define API_POSIX_ENOPROTOOPT ENOPROTOOPT
214 #define API_POSIX_ENOSYS ENOSYS
215 #define API_POSIX_ENOTSOCK ENOTSOCK
216 #define API_POSIX_EOVERFLOW EOVERFLOW
217 
218 #define api_posix_errno errno
219 
220 
221 /* ========================================================================== */
222 /* Signal handling */
223 
224 #include <signal.h>
225 
226 #define api_posix_sig_atomic_t sig_atomic_t
227 
228 #define api_posix_struct_sigaction struct sigaction
229 
230 #define API_POSIX_SIGHUP SIGHUP
231 #define API_POSIX_SIGINT SIGINT
232 #define API_POSIX_SIGPIPE SIGPIPE
233 #define API_POSIX_SIGQUIT SIGQUIT
234 #define API_POSIX_SIGTERM SIGTERM
235 
236 #define API_POSIX_SIG_DFL SIG_DFL
237 #define API_POSIX_SIG_IGN SIG_IGN
238 
239 #define API_POSIX_SIG_BLOCK SIG_BLOCK
240 #define API_POSIX_SIG_SETMASK SIG_SETMASK
241 
242 #define api_posix_sigset_t sigset_t
243 
244 #define api_posix_kill kill
245 #define api_posix_sigemptyset sigemptyset
246 #define api_posix_sigaddset sigaddset
247 #define api_posix_sigaction sigaction
248 
249 
250 /* ========================================================================== */
251 /* Process handling */
252 
253 #include <sys/wait.h>
254 
255 #define api_posix_pid_t pid_t
256 
257 #define API_POSIX_WIFEXITED WIFEXITED
258 #define API_POSIX_WEXITSTATUS WEXITSTATUS
259 
260 #define API_POSIX_WNOHANG WNOHANG
261 
262 #define api_posix_fork fork
263 #define api_posix_execl execl
264 #define api_posix_execlp execlp
265 #define api_posix_waitpid waitpid
266 #define api_posix_getpid getpid
267 
268 
269 /* ========================================================================== */
270 /* Time */
271 
272 #define api_posix_time_t time_t
273 #define api_posix_struct_tm struct tm
274 
275 #define api_posix_time time
276 
277 #define api_posix_gmtime_r gmtime_r
278 #define api_posix_localtime_r localtime_r
279 
280 /* The %z conversion was included into POSIX.1 since Issue 6 */
281 #if CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI
282 # define api_posix_strftime strftime
283 #endif /* CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI */
284 
285 #if CFG_USE_XSI
286 # include <sys/time.h>
287 
288 # define api_posix_time_t time_t
289 # define api_posix_suseconds_t suseconds_t
290 # define api_posix_struct_timeval struct timeval
291 #else /* CFG_USE_XSI */
292 # define api_posix_suseconds_t long int
293 
294 struct api_posix_timeval
295 {
296  api_posix_time_t tv_sec;
297  api_posix_suseconds_t tv_usec;
298 };
299 
300 # define api_posix_struct_timeval struct api_posix_timeval
301 #endif /* CFG_USE_XSI */
302 
303 
304 /* ========================================================================== */
305 /* Memory management */
306 
307 #if CFG_USE_MEMDEBUG
308 void* api_posix_malloc(size_t);
309 void* api_posix_realloc(void*, size_t);
310 void api_posix_free(void*);
311 #else /* CFG_USE_MEMDEBUG */
312 # define api_posix_malloc malloc
313 # define api_posix_realloc realloc
314 # define api_posix_free free
315 #endif /* CFG_USE_MEMDEBUG */
316 
317 
318 /* ========================================================================== */
319 /* Random numbers */
320 
321 #if CFG_USE_XSI
322 # define api_posix_srandom srandom
323 # define api_posix_random random
324 #else /* CFG_USE_XSI */
325 void api_posix_srandom(unsigned int);
326 long int api_posix_random(void);
327 #endif /* CFG_USE_XSI */
328 
329 
330 /* ========================================================================== */
331 /* File & directory handling */
332 
333 #include <sys/stat.h>
334 #include <fcntl.h>
335 #include <dirent.h>
336 #include <string.h>
337 
338 #define api_posix_off_t off_t
339 
340 #define API_POSIX_SEEK_SET SEEK_SET
341 
342 #define API_POSIX_FD_CLOEXEC FD_CLOEXEC
343 
344 #define API_POSIX_O_NONBLOCK O_NONBLOCK
345 #define API_POSIX_O_CREAT O_CREAT
346 #define API_POSIX_O_TRUNC O_TRUNC
347 #define API_POSIX_O_RDONLY O_RDONLY
348 #define API_POSIX_O_WRONLY O_WRONLY
349 #define API_POSIX_O_RDWR O_RDWR
350 #define API_POSIX_O_EXCL O_EXCL
351 
352 #define API_POSIX_S_IRWXU S_IRWXU
353 #define API_POSIX_S_IRWXG S_IRWXG
354 #define API_POSIX_S_IRWXO S_IRWXO
355 #define API_POSIX_S_IRUSR S_IRUSR
356 #define API_POSIX_S_IWUSR S_IWUSR
357 #define API_POSIX_S_IXUSR S_IXUSR
358 #define API_POSIX_S_IRGRP S_IRGRP
359 #define API_POSIX_S_IWGRP S_IWGRP
360 #define API_POSIX_S_IROTH S_IROTH
361 #define API_POSIX_S_IWOTH S_IWOTH
362 
363 #define API_POSIX_F_GETFL F_GETFL
364 #define API_POSIX_F_SETFL F_SETFL
365 #define API_POSIX_F_WRLCK F_WRLCK
366 #define API_POSIX_F_SETLK F_SETLK
367 #define API_POSIX_F_SETFD F_SETFD
368 
369 #define API_POSIX_STDIN_FILENO STDIN_FILENO
370 #define API_POSIX_STDOUT_FILENO STDOUT_FILENO
371 
372 #define API_POSIX_DIR DIR
373 
374 #define API_POSIX_S_ISREG S_ISREG
375 #define API_POSIX_S_ISDIR S_ISDIR
376 
377 #define api_posix_mode_t mode_t
378 #define api_posix_struct_flock struct flock
379 #define api_posix_struct_stat struct stat
380 #define api_posix_struct_dirent struct dirent
381 
382 #define api_posix_dup2 dup2
383 #define api_posix_pipe pipe
384 #define api_posix_unlink unlink
385 #define api_posix_rename rename
386 #define api_posix_open open
387 #define api_posix_fdopen fdopen
388 #define api_posix_close close
389 #define api_posix_lseek lseek
390 #define api_posix_read read
391 #define api_posix_write write
392 #define api_posix_fcntl fcntl
393 #define api_posix_fgetc fgetc
394 #define api_posix_mkdir mkdir
395 #define api_posix_rmdir rmdir
396 #define api_posix_opendir opendir
397 #define api_posix_readdir readdir
398 #define api_posix_closedir closedir
399 #define api_posix_stat stat
400 
401 #if CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI
402 # define api_posix_ftruncate ftruncate
403 # define api_posix_lstat lstat
404 # define api_posix_symlink symlink
405 #endif /* CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI */
406 
407 /* Included into POSIX.1 since Issue 7 */
408 #if CFG_USE_POSIX_API >= 200809 || CFG_USE_XSI
409 # define api_posix_mkstemp mkstemp
410 #else /* CFG_USE_POSIX_API >= 200809 || CFG_USE_XSI */
411 int api_posix_mkstemp(char*);
412 #endif /* CFG_USE_POSIX_API >= 200809 || CFG_USE_XSI */
413 
414 #if CFG_USE_POSIX_API >= 200809
415 # define api_posix_scandir scandir
416 #else /* CFG_USE_POSIX_API >= 200809 */
417 int api_posix_scandir(const char*, api_posix_struct_dirent***,
418  int (*sel)(api_posix_struct_dirent*),
419  int (*compar)(const api_posix_struct_dirent**,
420  const api_posix_struct_dirent**));
421 #endif /* CFG_USE_POSIX_API >= 200809 */
422 
423 
424 /* ========================================================================== */
425 /* System limits */
426 
427 # define API_POSIX_PC_NAME_MAX _PC_NAME_MAX
428 # define API_POSIX_PC_PATH_MAX _PC_PATH_MAX
429 
430 # define api_posix_pathconf pathconf
431 
432 
433 /* ========================================================================== */
434 /* NLS */
435 
436 #if CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI
437 # include <locale.h>
438 
439 # define API_POSIX_LC_ALL LC_ALL
440 # define API_POSIX_LC_CTYPE LC_CTYPE
441 # define API_POSIX_LC_MESSAGES LC_MESSAGES
442 
443 # define api_posix_setlocale setlocale
444 #endif /* CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI */
445 
446 #if CFG_USE_POSIX_API >= 200809 || CFG_USE_XSI
447 # include <nl_types.h>
448 # include <langinfo.h>
449 
450 # define API_POSIX_NL_MSGMAX NL_MSGMAX
451 # define API_POSIX_NL_CAT_LOCALE NL_CAT_LOCALE
452 
453 # define api_posix_nl_catd nl_catd
454 
455 # define api_posix_nl_langinfo nl_langinfo
456 # define api_posix_catopen catopen
457 # define api_posix_catgets catgets
458 # define api_posix_catclose catclose
459 #endif /* CFG_USE_POSIX_API >= 200809 || CFG_USE_XSI */
460 
461 /* These functions are part of POSIX.1 since Issue 7 */
462 #if CFG_USE_POSIX_API >= 200809
463 # include <strings.h>
464 
465 # define API_POSIX_LC_CTYPE_MASK LC_CTYPE_MASK
466 
467 # define api_posix_locale_t locale_t
468 
469 # define api_posix_newlocale newlocale
470 # define api_posix_freelocale freelocale
471 # define api_posix_strcasecmp_l strcasecmp_l
472 # define api_posix_strncasecmp_l strncasecmp_l
473 #else /* CFG_USE_POSIX_API >= 200809 */
474 # define API_POSIX_LC_CTYPE_MASK 0
475 
476 typedef int api_posix_locale_t;
477 
478 api_posix_locale_t api_posix_newlocale(int, const char*, api_posix_locale_t);
479 void api_posix_freelocale(api_posix_locale_t);
480 int api_posix_strcasecmp_l(const char*, const char*, api_posix_locale_t);
481 int api_posix_strncasecmp_l(const char*, const char*, size_t,
482  api_posix_locale_t);
483 #endif /* CFG_USE_POSIX_API >= 200809 */
484 
485 
486 /* ========================================================================== */
487 /* BSD socket interface (XNS) */
488 
489 /*
490  * If the system report the IP6 option as available, we expect that it provides
491  * XNS too (logical OR)
492  */
493 #if CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI || CFG_USE_IP6
494 # include <netinet/in.h>
495 # include <arpa/inet.h>
496 
497 # define API_POSIX_AF_UNSPEC AF_UNSPEC
498 # define API_POSIX_AF_INET AF_INET
499 # if CFG_USE_IP6
500 # define API_POSIX_AF_INET6 AF_INET6
501 # endif /* CFG_USE_IP6 */
502 
503 # define API_POSIX_MSG_PEEK MSG_PEEK
504 
505 # define api_posix_ssize_t ssize_t
506 
507 /* Some systems that claim to be SUSv2 conformant don't define 'in_addr_t' */
508 # if CFG_HDR_INTTYPES_H
509 # include <inttypes.h>
510 typedef uint16_t api_posix_in_port_t;
511 typedef uint32_t api_posix_in_addr_t;
512 # else /* CFG_HDR_INTTYPES_H */
513 typedef CFG_UINT16_TYPE api_posix_in_port_t;
514 typedef CFG_UINT32_TYPE api_posix_in_addr_t;
515 # endif /* CFG_HDR_INTTYPES_H */
516 
517 # define api_posix_struct_in_addr struct in_addr
518 # define api_posix_struct_sockaddr_in struct sockaddr_in
519 
520 # if CFG_USE_IP6
521 # define api_posix_struct_in6_addr struct in6_addr
522 # define api_posix_struct_sockaddr_in6 struct sockaddr_in6
523 # endif /* CFG_USE_IP6 */
524 
525 /* Bug in NetBSD: Declarations not exposed for POSIX.1-2001 without XSI */
526 # define api_posix_htons htons
527 # define api_posix_htonl htonl
528 # define api_posix_ntohs ntohs
529 # define api_posix_ntohl ntohl
530 
531 # define api_posix_inet_addr inet_addr
532 # if CFG_USE_POSIX_API >= 200112
533 # define api_posix_inet_pton inet_pton
534 # else /* CFG_USE_POSIX_API >= 200112 */
535 int api_posix_inet_pton(int, const char*, void*);
536 # endif /* CFG_USE_POSIX_API >= 200112 */
537 
538 # include <sys/socket.h>
539 
540 # define api_posix_sa_family_t sa_family_t
541 # define api_posix_socklen_t socklen_t
542 
543 /*
544  * 'struct sockaddr_storage' is broken on AIX (see documentation)
545  * Currently there is no workaround provided by this module
546  */
547 # define api_posix_struct_sockaddr_storage struct sockaddr_storage
548 # define api_posix_struct_sockaddr struct sockaddr
549 
550 # define api_posix_struct_servent struct servent
551 # define api_posix_struct_hostent struct hostent
552 
553 # define api_posix_getservbyname getservbyname
554 
555 # if CFG_USE_POSIX_API >= 200809
556  /*
557  * gethostbyname() is marked obsolete in POSIX.1 Issue 6
558  * and was removed with Issue 7.
559  * No replacement is implemented, use getaddrinfo() instead.
560  */
561 # else /* CFG_USE_POSIX_API >= 200809 */
562 # define api_posix_gethostbyname gethostbyname
563 # endif /* CFG_USE_POSIX_API >= 200809 */
564 
565 # define api_posix_socket socket
566 
567 # define API_POSIX_SOCK_STREAM SOCK_STREAM
568 
569 # define api_posix_connect connect
570 
571 # define API_POSIX_SOL_SOCKET SOL_SOCKET
572 
573 # define API_POSIX_SO_ERROR SO_ERROR
574 # define API_POSIX_SO_RCVTIMEO SO_RCVTIMEO
575 # define API_POSIX_SO_SNDTIMEO SO_SNDTIMEO
576 
577 # define api_posix_getsockopt getsockopt
578 # define api_posix_setsockopt setsockopt
579 
580 # define api_posix_send send
581 # define api_posix_recv recv
582 
583 # include <poll.h>
584 
585 # define API_POSIX_POLLIN POLLIN
586 # define API_POSIX_POLLOUT POLLOUT
587 # define API_POSIX_POLLERR POLLERR
588 
589 # define api_posix_struct_pollfd struct pollfd
590 
591 # define api_posix_poll poll
592 #else /* CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI || CFG_USE_IP6 */
593 # /* Use wrappers for original BSD socket API */
594 # define BSD_FOR_POSIX
595 # include "bsd.h"
596 #endif /* CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI || CFG_USE_IP6 */
597 
598 
599 /* ========================================================================== */
600 /* Address information */
601 
602 #include <netdb.h>
603 
604 /*
605  * If the system report the IP6 option as available, we expect that it provides
606  * the POSIX.1g API too (logical OR)
607  *
608  * Attention: This subsystem is emulated using 'gethostbyname()':
609  * This function was marked obsolete by POSIX.1-2001 and was eventually removed
610  * in POSIX.1-2008 => The emulation can no longer be used since POSIX.1-2008
611  * (even for IPv4).
612  */
613 #if CFG_USE_POSIX_API >= 200112 || CFG_USE_IP6
614 # define API_POSIX_AI_ADDRCONFIG AI_ADDRCONFIG
615 
616 # define API_POSIX_EAI_AGAIN EAI_AGAIN
617 # define API_POSIX_EAI_BADFLAGS EAI_BADFLAGS
618 # define API_POSIX_EAI_FAIL EAI_FAIL
619 # define API_POSIX_EAI_FAMILY EAI_FAMILY
620 # define API_POSIX_EAI_MEMORY EAI_MEMORY
621 # define API_POSIX_EAI_NONAME EAI_NONAME
622 # define API_POSIX_EAI_OVERFLOW EAI_OVERFLOW
623 # define API_POSIX_EAI_SERVICE EAI_SERVICE
624 # define API_POSIX_EAI_SOCKTYPE EAI_SOCKTYPE
625 # define API_POSIX_EAI_SYSTEM EAI_SYSTEM
626 
627 # define api_posix_struct_addrinfo struct addrinfo
628 
629 # define api_posix_freeaddrinfo freeaddrinfo
630 # define api_posix_getaddrinfo getaddrinfo
631 # define api_posix_gai_strerror gai_strerror
632 #else /* CFG_USE_POSIX_API >= 200112 || CFG_USE_IP6 */
633 # define API_POSIX_AI_ADDRCONFIG 0x0001
634 
635 # define API_POSIX_EAI_AGAIN -1
636 # define API_POSIX_EAI_BADFLAGS -2
637 # define API_POSIX_EAI_FAIL -3
638 # define API_POSIX_EAI_FAMILY -4
639 # define API_POSIX_EAI_MEMORY -5
640 # define API_POSIX_EAI_NONAME -6
641 # define API_POSIX_EAI_OVERFLOW -7
642 # define API_POSIX_EAI_SERVICE -8
643 # define API_POSIX_EAI_SOCKTYPE -9
644 # define API_POSIX_EAI_SYSTEM -10
645 
646 struct api_posix_addrinfo
647 {
648  int ai_flags;
649  int ai_family;
650  int ai_socktype;
651  int ai_protocol;
652  api_posix_socklen_t ai_addrlen;
653  api_posix_struct_sockaddr* ai_addr;
654  char* ai_canonname;
655  struct api_posix_addrinfo* ai_next;
656 };
657 
658 # define api_posix_struct_addrinfo struct api_posix_addrinfo
659 
660 void api_posix_freeaddrinfo(api_posix_struct_addrinfo*);
661 int api_posix_getaddrinfo(const char*, const char*,
662  const api_posix_struct_addrinfo*,
663  api_posix_struct_addrinfo**);
664 const char* api_posix_gai_strerror(int);
665 #endif /* CFG_USE_POSIX_API >= 200112 || CFG_USE_IP6 */
666 
667 
668 /* ========================================================================== */
669 /* Standard I/O */
670 
671 #include <stdarg.h>
672 #include <string.h>
673 #include <stdio.h>
674 
675 /*
676  * Available since POSIX.1-2001.
677  * Attention: The version in SUSv2 is not sufficient (different semantics)!
678  */
679 #if CFG_USE_POSIX_API >= 200112
680 # define api_posix_snprintf snprintf
681 #else /* CFG_USE_POSIX_API >= 200112 */
682 int api_posix_snprintf(char*, size_t, const char*, ...);
683 #endif /* CFG_USE_POSIX_API >= 200112 */
684 
685 /* Part of POSIX.1 since Issue 7 */
686 #if CFG_USE_POSIX_API >= 200809
687 # define api_posix_getline getline
688 #else /* CFG_USE_POSIX_API >= 200809 */
689 api_posix_ssize_t api_posix_getline(char**, size_t*, FILE*);
690 #endif /* CFG_USE_POSIX_API >= 200809 */
691 
692 
693 /* ========================================================================== */
694 /* Regular expression matching */
695 
696 #if CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI || CFG_USE_CLB
697 # include <regex.h>
698 
699 # define API_POSIX_REG_EXTENDED REG_EXTENDED
700 # define API_POSIX_REG_ICASE REG_ICASE
701 # define API_POSIX_REG_NOSUB REG_NOSUB
702 # define API_POSIX_REG_NEWLINE REG_NEWLINE
703 
704 # define api_posix_regex_t regex_t
705 
706 # define api_posix_regcomp regcomp
707 # define api_posix_regerror regerror
708 # define api_posix_regexec regexec
709 # define api_posix_regfree regfree
710 #endif /* CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI || CFG_USE_CLB */
711 
712 
713 /* ========================================================================== */
714 /* Codeset conversion */
715 
716 /*
717  * Implementations before POSIX.1-2024 may not be good enough.
718  *
719  * The definition from SUSv2 is ambiguous:
720  * <https://pubs.opengroup.org/onlinepubs/007908799/xsh/iconv.html>
721  * Different semantics are used in header and definition!
722  *
723  * Attention:
724  * The version from POSIX.1-2001 looks similar to the one from POSIX.1-2024:
725  * <https://pubs.opengroup.org/onlinepubs/007904975/functions/iconv.html>
726  * But there are operating systems that falsely claim POSIX.1-2001 conformance,
727  * e.g. NetBSD before version 10 (released in 2024).
728  */
729 #if CFG_USE_POSIX_API >= 202405L
730 # include <iconv.h>
731 
732 # define api_posix_iconv_open iconv_open
733 # define api_posix_iconv_close iconv_close
734 # define api_posix_iconv iconv
735 #endif /* CFG_USE_POSIX_API >= 202405L */
736 
737 
738 /* EOF */

Generated at 2026-01-27 using  doxygen