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>
29 * The authors hereby relinquish any claim to any copyright that they may have
30 * in this work, whether granted under contract or by operation of law or
31 * international treaty, and hereby commit to the public, at large, that they
32 * shall not, at any time in the future, seek to enforce any copyright in this
33 * work against any person or entity, or prevent any person or entity from
34 * copying, publishing, distributing or creating derivative works of this
38 #ifndef PORTABLE_SYSTEM_H
39 #define PORTABLE_SYSTEM_H 1
41 /* Make sure we have our configuration information. */
44 /* BEGIN_DECL and __attribute__. */
45 #include <portable/macros.h>
47 /* A set of standard ANSI C headers. We don't care about pre-ANSI systems. */
49 # include <inttypes.h>
63 #include <sys/types.h>
68 /* SCO OpenServer gets int32_t from here. */
69 #if HAVE_SYS_BITYPES_H
70 # include <sys/bitypes.h>
73 /* Get the bool type. */
74 #include <portable/stdbool.h>
76 /* Windows provides snprintf under a different name. */
78 # define snprintf _snprintf
81 /* Windows does not define ssize_t. */
83 typedef ptrdiff_t ssize_t;
87 * POSIX requires that these be defined in <unistd.h>. If one of them has
88 * been defined, all the rest almost certainly have.
91 # define STDIN_FILENO 0
92 # define STDOUT_FILENO 1
93 # define STDERR_FILENO 2
97 * C99 requires va_copy. Older versions of GCC provide __va_copy. Per the
98 * Autoconf manual, memcpy is a generally portable fallback.
102 # define va_copy(d, s) __va_copy((d), (s))
104 # define va_copy(d, s) memcpy(&(d), &(s), sizeof(va_list))
110 /* Default to a hidden visibility for all portability functions. */
111 #pragma GCC visibility push(hidden)
114 * Provide prototypes for functions not declared in system headers. Use the
115 * HAVE_DECL macros for those functions that may be prototyped but implemented
116 * incorrectly or implemented without a prototype.
119 extern int asprintf(char **, const char *, ...)
120 __attribute__((__format__(printf, 2, 3)));
121 extern int vasprintf(char **, const char *, va_list);
123 #if !HAVE_DECL_SNPRINTF
124 extern int snprintf(char *, size_t, const char *, ...)
125 __attribute__((__format__(printf, 3, 4)));
127 #if !HAVE_DECL_VSNPRINTF
128 extern int vsnprintf(char *, size_t, const char *, va_list);
131 extern int mkstemp(char *);
133 #if !HAVE_REALLOCARRAY
134 extern void *reallocarray(void *, size_t, size_t);
137 extern char *strndup(const char *, size_t);
140 /* Undo default visibility change. */
141 #pragma GCC visibility pop
145 #endif /* !PORTABLE_SYSTEM_H */