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 <sys/types.h>
10 * #include <stdbool.h>
16 * #include <strings.h>
19 * Missing functions are provided via #define or prototyped if available from
20 * the portable helper library. Also provides some standard #defines.
22 * The canonical version of this file is maintained in the rra-c-util package,
23 * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
25 * Written by Russ Allbery <eagle@eyrie.org>
27 * The authors hereby relinquish any claim to any copyright that they may have
28 * in this work, whether granted under contract or by operation of law or
29 * international treaty, and hereby commit to the public, at large, that they
30 * shall not, at any time in the future, seek to enforce any copyright in this
31 * work against any person or entity, or prevent any person or entity from
32 * copying, publishing, distributing or creating derivative works of this
36 #ifndef PORTABLE_SYSTEM_H
37 #define PORTABLE_SYSTEM_H 1
39 /* Make sure we have our configuration information. */
42 /* BEGIN_DECL and __attribute__. */
43 #include <portable/macros.h>
45 /* A set of standard ANSI C headers. We don't care about pre-ANSI systems. */
47 # include <inttypes.h>
60 #include <sys/types.h>
65 /* SCO OpenServer gets int32_t from here. */
66 #if HAVE_SYS_BITYPES_H
67 # include <sys/bitypes.h>
70 /* Get the bool type. */
71 #include <portable/stdbool.h>
73 /* Windows provides snprintf under a different name. */
75 # define snprintf _snprintf
78 /* Windows does not define ssize_t. */
80 typedef ptrdiff_t ssize_t;
84 * POSIX requires that these be defined in <unistd.h>. If one of them has
85 * been defined, all the rest almost certainly have.
88 # define STDIN_FILENO 0
89 # define STDOUT_FILENO 1
90 # define STDERR_FILENO 2
94 * C99 requires va_copy. Older versions of GCC provide __va_copy. Per the
95 * Autoconf manual, memcpy is a generally portable fallback.
99 # define va_copy(d, s) __va_copy((d), (s))
101 # define va_copy(d, s) memcpy(&(d), &(s), sizeof(va_list))
107 /* Default to a hidden visibility for all portability functions. */
108 #pragma GCC visibility push(hidden)
111 * Provide prototypes for functions not declared in system headers. Use the
112 * HAVE_DECL macros for those functions that may be prototyped but implemented
113 * incorrectly or implemented without a prototype.
116 extern int asprintf(char **, const char *, ...)
117 __attribute__((__format__(printf, 2, 3)));
118 extern int vasprintf(char **, const char *, va_list);
120 #if !HAVE_DECL_SNPRINTF
121 extern int snprintf(char *, size_t, const char *, ...)
122 __attribute__((__format__(printf, 3, 4)));
124 #if !HAVE_DECL_VSNPRINTF
125 extern int vsnprintf(char *, size_t, const char *, va_list);
128 /* Undo default visibility change. */
129 #pragma GCC visibility pop
133 #endif /* !PORTABLE_SYSTEM_H */