]> eyrie.org Git - kerberos/krb5-strength.git/blob - portable/system.h
Change my email address to eagle@eyrie.org
[kerberos/krb5-strength.git] / portable / system.h
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 <stddef.h>
12  *     #include <stdio.h>
13  *     #include <stdlib.h>
14  *     #include <stdint.h>
15  *     #include <string.h>
16  *     #include <strings.h>
17  *     #include <unistd.h>
18  *
19  * Missing functions are provided via #define or prototyped if available from
20  * the portable helper library.  Also provides some standard #defines.
21  *
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/>.
24  *
25  * Written by Russ Allbery <eagle@eyrie.org>
26  *
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
33  * work.
34  */
35
36 #ifndef PORTABLE_SYSTEM_H
37 #define PORTABLE_SYSTEM_H 1
38
39 /* Make sure we have our configuration information. */
40 #include <config.h>
41
42 /* BEGIN_DECL and __attribute__. */
43 #include <portable/macros.h>
44
45 /* A set of standard ANSI C headers.  We don't care about pre-ANSI systems. */
46 #if HAVE_INTTYPES_H
47 # include <inttypes.h>
48 #endif
49 #include <stdarg.h>
50 #include <stddef.h>
51 #if HAVE_STDINT_H
52 # include <stdint.h>
53 #endif
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <string.h>
57 #if HAVE_STRINGS_H
58 # include <strings.h>
59 #endif
60 #include <sys/types.h>
61 #if HAVE_UNISTD_H
62 # include <unistd.h>
63 #endif
64
65 /* SCO OpenServer gets int32_t from here. */
66 #if HAVE_SYS_BITYPES_H
67 # include <sys/bitypes.h>
68 #endif
69
70 /* Get the bool type. */
71 #include <portable/stdbool.h>
72
73 /* Windows provides snprintf under a different name. */
74 #ifdef _WIN32
75 # define snprintf _snprintf
76 #endif
77
78 /* Windows does not define ssize_t. */
79 #ifndef HAVE_SSIZE_T
80 typedef ptrdiff_t ssize_t;
81 #endif
82
83 /*
84  * POSIX requires that these be defined in <unistd.h>.  If one of them has
85  * been defined, all the rest almost certainly have.
86  */
87 #ifndef STDIN_FILENO
88 # define STDIN_FILENO  0
89 # define STDOUT_FILENO 1
90 # define STDERR_FILENO 2
91 #endif
92
93 /*
94  * C99 requires va_copy.  Older versions of GCC provide __va_copy.  Per the
95  * Autoconf manual, memcpy is a generally portable fallback.
96  */
97 #ifndef va_copy
98 # ifdef __va_copy
99 #  define va_copy(d, s) __va_copy((d), (s))
100 # else
101 #  define va_copy(d, s) memcpy(&(d), &(s), sizeof(va_list))
102 # endif
103 #endif
104
105 BEGIN_DECLS
106
107 /* Default to a hidden visibility for all portability functions. */
108 #pragma GCC visibility push(hidden)
109
110 /*
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.
114  */
115 #if !HAVE_ASPRINTF
116 extern int asprintf(char **, const char *, ...)
117     __attribute__((__format__(printf, 2, 3)));
118 extern int vasprintf(char **, const char *, va_list);
119 #endif
120 #if !HAVE_DECL_SNPRINTF
121 extern int snprintf(char *, size_t, const char *, ...)
122     __attribute__((__format__(printf, 3, 4)));
123 #endif
124 #if !HAVE_DECL_VSNPRINTF
125 extern int vsnprintf(char *, size_t, const char *, va_list);
126 #endif
127
128 /* Undo default visibility change. */
129 #pragma GCC visibility pop
130
131 END_DECLS
132
133 #endif /* !PORTABLE_SYSTEM_H */