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