]> eyrie.org Git - kerberos/krb5-strength.git/blob - portable/system.h
Tweak RPM spec file
[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 <stdint.h>
14  *     #include <stdio.h>
15  *     #include <stdlib.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  * Copyright 2014, 2016, 2018, 2020-2021 Russ Allbery <eagle@eyrie.org>
29  * Copyright 2006-2011, 2013-2014
30  *     The Board of Trustees of the Leland Stanford Junior University
31  *
32  * Copying and distribution of this file, with or without modification, are
33  * permitted in any medium without royalty provided the copyright notice and
34  * this notice are preserved.  This file is offered as-is, without any
35  * warranty.
36  *
37  * SPDX-License-Identifier: FSFAP
38  */
39
40 #ifndef PORTABLE_SYSTEM_H
41 #define PORTABLE_SYSTEM_H 1
42
43 /* Make sure we have our configuration information. */
44 #include <config.h>
45
46 /* BEGIN_DECL and __attribute__. */
47 #include <portable/macros.h>
48
49 /* A set of standard ANSI C headers.  We don't care about pre-ANSI systems. */
50 #if HAVE_INTTYPES_H
51 #    include <inttypes.h>
52 #endif
53 #include <limits.h>
54 #include <stdarg.h>
55 #include <stddef.h>
56 #if HAVE_STDINT_H
57 #    include <stdint.h>
58 #endif
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <string.h>
62 #if HAVE_STRINGS_H
63 #    include <strings.h>
64 #endif
65 #include <sys/types.h>
66 #if HAVE_UNISTD_H
67 #    include <unistd.h>
68 #endif
69
70 /* SCO OpenServer gets int32_t from here. */
71 #if HAVE_SYS_BITYPES_H
72 #    include <sys/bitypes.h>
73 #endif
74
75 /* Get the bool type. */
76 #include <portable/stdbool.h>
77
78 /* In case uint32_t and associated limits weren't defined. */
79 #ifndef UINT32_MAX
80 #    define UINT32_MAX 4294967295UL
81 #endif
82
83 /* Windows provides snprintf under a different name. */
84 #ifdef _WIN32
85 #    define snprintf _snprintf
86 #endif
87
88 /* Windows does not define ssize_t. */
89 #ifndef HAVE_SSIZE_T
90 typedef ptrdiff_t ssize_t;
91 #endif
92
93 /*
94  * POSIX requires that these be defined in <unistd.h>.  If one of them has
95  * been defined, all the rest almost certainly have.
96  */
97 #ifndef STDIN_FILENO
98 #    define STDIN_FILENO  0
99 #    define STDOUT_FILENO 1
100 #    define STDERR_FILENO 2
101 #endif
102
103 /*
104  * C99 requires va_copy.  Older versions of GCC provide __va_copy.  Per the
105  * Autoconf manual, memcpy is a generally portable fallback.
106  */
107 #ifndef va_copy
108 #    ifdef __va_copy
109 #        define va_copy(d, s) __va_copy((d), (s))
110 #    else
111 #        define va_copy(d, s) memcpy(&(d), &(s), sizeof(va_list))
112 #    endif
113 #endif
114
115 /*
116  * If explicit_bzero is not available, fall back on memset.  This does NOT
117  * provide any of the security guarantees of explicit_bzero and will probably
118  * be optimized away by the compiler.  It just ensures that code will compile
119  * and function on systems without explicit_bzero.
120  */
121 #if !HAVE_EXPLICIT_BZERO
122 #    define explicit_bzero(s, n) memset((s), 0, (n))
123 #endif
124
125 BEGIN_DECLS
126
127 /* Default to a hidden visibility for all portability functions. */
128 #pragma GCC visibility push(hidden)
129
130 /*
131  * Provide prototypes for functions not declared in system headers.  Use the
132  * HAVE_DECL macros for those functions that may be prototyped but implemented
133  * incorrectly or implemented without a prototype.
134  */
135 #if !HAVE_ASPRINTF
136 extern int asprintf(char **, const char *, ...)
137     __attribute__((__format__(printf, 2, 3)));
138 extern int vasprintf(char **, const char *, va_list)
139     __attribute__((__format__(printf, 2, 0)));
140 #endif
141 #if !HAVE_MKSTEMP
142 extern int mkstemp(char *);
143 #endif
144 #if !HAVE_DECL_REALLOCARRAY
145 extern void *reallocarray(void *, size_t, size_t);
146 #endif
147 #if !HAVE_STRNDUP
148 extern char *strndup(const char *, size_t);
149 #endif
150
151 /* Undo default visibility change. */
152 #pragma GCC visibility pop
153
154 END_DECLS
155
156 #endif /* !PORTABLE_SYSTEM_H */