| 1 | /* |
|---|
| 2 | * Standard system includes and portability adjustments. |
|---|
| 3 | * |
|---|
| 4 | * Declarations of routines and variables in the C library. Including this |
|---|
| 5 | * file is the equivalent of including all of the following headers, |
|---|
| 6 | * portably: |
|---|
| 7 | * |
|---|
| 8 | * #include <sys/types.h> |
|---|
| 9 | * #include <stdarg.h> |
|---|
| 10 | * #include <stdbool.h> |
|---|
| 11 | * #include <stdio.h> |
|---|
| 12 | * #include <stdlib.h> |
|---|
| 13 | * #include <stddef.h> |
|---|
| 14 | * #include <stdint.h> |
|---|
| 15 | * #include <string.h> |
|---|
| 16 | * #include <unistd.h> |
|---|
| 17 | * |
|---|
| 18 | * Missing functions are provided via #define or prototyped if available from |
|---|
| 19 | * the util helper library. Also provides some standard #defines. |
|---|
| 20 | * |
|---|
| 21 | * Written by Russ Allbery <rra@stanford.edu> |
|---|
| 22 | * This work is hereby placed in the public domain by its author. |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | #ifndef PORTABLE_SYSTEM_H |
|---|
| 26 | #define PORTABLE_SYSTEM_H 1 |
|---|
| 27 | |
|---|
| 28 | /* Make sure we have our configuration information. */ |
|---|
| 29 | #include <config.h> |
|---|
| 30 | |
|---|
| 31 | /* BEGIN_DECL and __attribute__. */ |
|---|
| 32 | #include <portable/macros.h> |
|---|
| 33 | |
|---|
| 34 | /* A set of standard ANSI C headers. We don't care about pre-ANSI systems. */ |
|---|
| 35 | #include <stdarg.h> |
|---|
| 36 | #include <stddef.h> |
|---|
| 37 | #include <stdio.h> |
|---|
| 38 | #include <stdlib.h> |
|---|
| 39 | #include <sys/types.h> |
|---|
| 40 | #include <string.h> |
|---|
| 41 | #if HAVE_INTTYPES_H |
|---|
| 42 | # include <inttypes.h> |
|---|
| 43 | #endif |
|---|
| 44 | #if HAVE_STDINT_H |
|---|
| 45 | # include <stdint.h> |
|---|
| 46 | #endif |
|---|
| 47 | #if HAVE_UNISTD_H |
|---|
| 48 | # include <unistd.h> |
|---|
| 49 | #endif |
|---|
| 50 | |
|---|
| 51 | /* SCO OpenServer gets int32_t from here. */ |
|---|
| 52 | #if HAVE_SYS_BITYPES_H |
|---|
| 53 | # include <sys/bitypes.h> |
|---|
| 54 | #endif |
|---|
| 55 | |
|---|
| 56 | /* Get the bool type. */ |
|---|
| 57 | #include <portable/stdbool.h> |
|---|
| 58 | |
|---|
| 59 | BEGIN_DECLS |
|---|
| 60 | |
|---|
| 61 | /* |
|---|
| 62 | * Provide prototypes for functions not declared in system headers. Use the |
|---|
| 63 | * HAVE_DECL macros for those functions that may be prototyped but implemented |
|---|
| 64 | * incorrectly or implemented without a prototype. |
|---|
| 65 | */ |
|---|
| 66 | #if !HAVE_ASPRINTF |
|---|
| 67 | extern int asprintf(char **, const char *, ...) |
|---|
| 68 | __attribute__((__visibility__("hidden"))); |
|---|
| 69 | extern int vasprintf(char **, const char *, va_list) |
|---|
| 70 | __attribute__((__visibility__("hidden"))); |
|---|
| 71 | #endif |
|---|
| 72 | #if !HAVE_DECL_SNPRINTF |
|---|
| 73 | extern int snprintf(char *, size_t, const char *, ...) |
|---|
| 74 | __attribute__((__format__(printf, 3, 4))); |
|---|
| 75 | #endif |
|---|
| 76 | #if !HAVE_DECL_VSNPRINTF |
|---|
| 77 | extern int vsnprintf(char *, size_t, const char *, va_list); |
|---|
| 78 | #endif |
|---|
| 79 | #if !HAVE_DAEMON |
|---|
| 80 | extern int daemon(int, int) |
|---|
| 81 | __attribute__((__visibility__("hidden"))); |
|---|
| 82 | #endif |
|---|
| 83 | #if !HAVE_SETENV |
|---|
| 84 | extern int setenv(const char *, const char *, int) |
|---|
| 85 | __attribute__((__visibility__("hidden"))); |
|---|
| 86 | #endif |
|---|
| 87 | #if !HAVE_STRLCAT |
|---|
| 88 | extern size_t strlcat(char *, const char *, size_t) |
|---|
| 89 | __attribute__((__visibility__("hidden"))); |
|---|
| 90 | #endif |
|---|
| 91 | #if !HAVE_STRLCPY |
|---|
| 92 | extern size_t strlcpy(char *, const char *, size_t) |
|---|
| 93 | __attribute__((__visibility__("hidden"))); |
|---|
| 94 | #endif |
|---|
| 95 | |
|---|
| 96 | END_DECLS |
|---|
| 97 | |
|---|
| 98 | /* Windows provides snprintf under a different name. */ |
|---|
| 99 | #ifdef _WIN32 |
|---|
| 100 | # define snprintf _snprintf |
|---|
| 101 | #endif |
|---|
| 102 | |
|---|
| 103 | /* |
|---|
| 104 | * POSIX requires that these be defined in <unistd.h>. If one of them has |
|---|
| 105 | * been defined, all the rest almost certainly have. |
|---|
| 106 | */ |
|---|
| 107 | #ifndef STDIN_FILENO |
|---|
| 108 | # define STDIN_FILENO 0 |
|---|
| 109 | # define STDOUT_FILENO 1 |
|---|
| 110 | # define STDERR_FILENO 2 |
|---|
| 111 | #endif |
|---|
| 112 | |
|---|
| 113 | /* |
|---|
| 114 | * C99 requires va_copy. Older versions of GCC provide __va_copy. Per the |
|---|
| 115 | * Autoconf manual, memcpy is a generally portable fallback. |
|---|
| 116 | */ |
|---|
| 117 | #ifndef va_copy |
|---|
| 118 | # ifdef __va_copy |
|---|
| 119 | # define va_copy(d, s) __va_copy((d), (s)) |
|---|
| 120 | # else |
|---|
| 121 | # define va_copy(d, s) memcpy(&(d), &(s), sizeof(va_list)) |
|---|
| 122 | # endif |
|---|
| 123 | #endif |
|---|
| 124 | |
|---|
| 125 | #endif /* !PORTABLE_SYSTEM_H */ |
|---|