2 * Standard system includes and portability adjustments.
4 * Declarations of routines and variables in the C library. Including this
5 * file is the equivalent of including all of the following headers,
8 * #include <inttypes.h>
11 * #include <stdbool.h>
17 * #include <strings.h>
18 * #include <sys/types.h>
21 * Missing functions are provided via #define or prototyped if available from
22 * the portable helper library. Also provides some standard #defines.
24 * The canonical version of this file is maintained in the rra-c-util package,
25 * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
27 * Written by Russ Allbery <eagle@eyrie.org>
28 * Copyright 2014, 2016, 2018, 2020-2021 Russ Allbery <eagle@eyrie.org>
29 * Copyright 2006-2011, 2013-2014
30 * The Board of Trustees of the Leland Stanford Junior University
32 * Copying and distribution of this file, with or without modification, are
33 * permitted in any medium without royalty provided the copyright notice and
34 * this notice are preserved. This file is offered as-is, without any
37 * SPDX-License-Identifier: FSFAP
40 #ifndef PORTABLE_SYSTEM_H
41 #define PORTABLE_SYSTEM_H 1
43 /* Make sure we have our configuration information. */
46 /* BEGIN_DECL and __attribute__. */
47 #include <portable/macros.h>
49 /* A set of standard ANSI C headers. We don't care about pre-ANSI systems. */
51 # include <inttypes.h>
65 #include <sys/types.h>
70 /* SCO OpenServer gets int32_t from here. */
71 #if HAVE_SYS_BITYPES_H
72 # include <sys/bitypes.h>
75 /* Get the bool type. */
76 #include <portable/stdbool.h>
78 /* In case uint32_t and associated limits weren't defined. */
80 # define UINT32_MAX 4294967295UL
83 /* Windows provides snprintf under a different name. */
85 # define snprintf _snprintf
88 /* Windows does not define ssize_t. */
90 typedef ptrdiff_t ssize_t;
94 * POSIX requires that these be defined in <unistd.h>. If one of them has
95 * been defined, all the rest almost certainly have.
98 # define STDIN_FILENO 0
99 # define STDOUT_FILENO 1
100 # define STDERR_FILENO 2
104 * C99 requires va_copy. Older versions of GCC provide __va_copy. Per the
105 * Autoconf manual, memcpy is a generally portable fallback.
109 # define va_copy(d, s) __va_copy((d), (s))
111 # define va_copy(d, s) memcpy(&(d), &(s), sizeof(va_list))
116 * If explicit_bzero is not available, fall back on memset. This does NOT
117 * provide any of the security guarantees of explicit_bzero and will probably
118 * be optimized away by the compiler. It just ensures that code will compile
119 * and function on systems without explicit_bzero.
121 #if !HAVE_EXPLICIT_BZERO
122 # define explicit_bzero(s, n) memset((s), 0, (n))
127 /* Default to a hidden visibility for all portability functions. */
128 #pragma GCC visibility push(hidden)
131 * Provide prototypes for functions not declared in system headers. Use the
132 * HAVE_DECL macros for those functions that may be prototyped but implemented
133 * incorrectly or implemented without a prototype.
136 extern int asprintf(char **, const char *, ...)
137 __attribute__((__format__(printf, 2, 3)));
138 extern int vasprintf(char **, const char *, va_list)
139 __attribute__((__format__(printf, 2, 0)));
142 extern int mkstemp(char *);
144 #if !HAVE_DECL_REALLOCARRAY
145 extern void *reallocarray(void *, size_t, size_t);
148 extern char *strndup(const char *, size_t);
151 /* Undo default visibility change. */
152 #pragma GCC visibility pop
156 #endif /* !PORTABLE_SYSTEM_H */