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 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 /* Windows provides snprintf under a different name. */
80 # define snprintf _snprintf
83 /* Windows does not define ssize_t. */
85 typedef ptrdiff_t ssize_t;
89 * POSIX requires that these be defined in <unistd.h>. If one of them has
90 * been defined, all the rest almost certainly have.
93 # define STDIN_FILENO 0
94 # define STDOUT_FILENO 1
95 # define STDERR_FILENO 2
99 * C99 requires va_copy. Older versions of GCC provide __va_copy. Per the
100 * Autoconf manual, memcpy is a generally portable fallback.
104 # define va_copy(d, s) __va_copy((d), (s))
106 # define va_copy(d, s) memcpy(&(d), &(s), sizeof(va_list))
111 * If explicit_bzero is not available, fall back on memset. This does NOT
112 * provide any of the security guarantees of explicit_bzero and will probably
113 * be optimized away by the compiler. It just ensures that code will compile
114 * and function on systems without explicit_bzero.
116 #if !HAVE_EXPLICIT_BZERO
117 # define explicit_bzero(s, n) memset((s), 0, (n))
122 /* Default to a hidden visibility for all portability functions. */
123 #pragma GCC visibility push(hidden)
126 * Provide prototypes for functions not declared in system headers. Use the
127 * HAVE_DECL macros for those functions that may be prototyped but implemented
128 * incorrectly or implemented without a prototype.
131 extern int asprintf(char **, const char *, ...)
132 __attribute__((__format__(printf, 2, 3)));
133 extern int vasprintf(char **, const char *, va_list)
134 __attribute__((__format__(printf, 2, 0)));
136 #if !HAVE_DECL_SNPRINTF
137 extern int snprintf(char *, size_t, const char *, ...)
138 __attribute__((__format__(printf, 3, 4)));
140 #if !HAVE_DECL_VSNPRINTF
141 extern int vsnprintf(char *, size_t, const char *, va_list)
142 __attribute__((__format__(printf, 3, 0)));
145 extern int mkstemp(char *);
147 #if !HAVE_REALLOCARRAY
148 extern void *reallocarray(void *, size_t, size_t);
151 extern char *strndup(const char *, size_t);
154 /* Undo default visibility change. */
155 #pragma GCC visibility pop
159 #endif /* !PORTABLE_SYSTEM_H */