]>
Commit | Line | Data |
---|---|---|
f434ba03 PA |
1 | /* A substitute for POSIX 2008 <stddef.h>, for platforms that have issues. |
2 | ||
dc6c21da | 3 | Copyright (C) 2009-2022 Free Software Foundation, Inc. |
f434ba03 | 4 | |
dc6c21da TT |
5 | This file is free software: you can redistribute it and/or modify |
6 | it under the terms of the GNU Lesser General Public License as | |
7 | published by the Free Software Foundation; either version 2.1 of the | |
8 | License, or (at your option) any later version. | |
f434ba03 | 9 | |
dc6c21da | 10 | This file is distributed in the hope that it will be useful, |
f434ba03 PA |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
dc6c21da | 13 | GNU Lesser General Public License for more details. |
f434ba03 | 14 | |
dc6c21da TT |
15 | You should have received a copy of the GNU Lesser General Public License |
16 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ | |
f434ba03 PA |
17 | |
18 | /* Written by Eric Blake. */ | |
19 | ||
20 | /* | |
21 | * POSIX 2008 <stddef.h> for platforms that have issues. | |
c0c3707f | 22 | * <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html> |
f434ba03 PA |
23 | */ |
24 | ||
25 | #if __GNUC__ >= 3 | |
26 | @PRAGMA_SYSTEM_HEADER@ | |
27 | #endif | |
770d76d7 | 28 | @PRAGMA_COLUMNS@ |
f434ba03 PA |
29 | |
30 | #if defined __need_wchar_t || defined __need_size_t \ | |
31 | || defined __need_ptrdiff_t || defined __need_NULL \ | |
32 | || defined __need_wint_t | |
33 | /* Special invocation convention inside gcc header files. In | |
34 | particular, gcc provides a version of <stddef.h> that blindly | |
35 | redefines NULL even when __need_wint_t was defined, even though | |
36 | wint_t is not normally provided by <stddef.h>. Hence, we must | |
37 | remember if special invocation has ever been used to obtain wint_t, | |
38 | in which case we need to clean up NULL yet again. */ | |
39 | ||
770d76d7 | 40 | # if !(defined _@GUARD_PREFIX@_STDDEF_H && defined _GL_STDDEF_WINT_T) |
f434ba03 | 41 | # ifdef __need_wint_t |
f434ba03 PA |
42 | # define _GL_STDDEF_WINT_T |
43 | # endif | |
44 | # @INCLUDE_NEXT@ @NEXT_STDDEF_H@ | |
dc6c21da TT |
45 | /* On TinyCC, make sure that the macros that indicate the special invocation |
46 | convention get undefined. */ | |
47 | # undef __need_wchar_t | |
48 | # undef __need_size_t | |
49 | # undef __need_ptrdiff_t | |
50 | # undef __need_NULL | |
51 | # undef __need_wint_t | |
f434ba03 PA |
52 | # endif |
53 | ||
54 | #else | |
55 | /* Normal invocation convention. */ | |
56 | ||
770d76d7 | 57 | # ifndef _@GUARD_PREFIX@_STDDEF_H |
f434ba03 | 58 | |
9c9d63b1 PM |
59 | /* On AIX 7.2, with xlc in 64-bit mode, <stddef.h> defines max_align_t to a |
60 | type with alignment 4, but 'long' has alignment 8. */ | |
dc6c21da | 61 | # if defined _AIX && defined __LP64__ |
9c9d63b1 PM |
62 | # if !GNULIB_defined_max_align_t |
63 | # ifdef _MAX_ALIGN_T | |
64 | /* /usr/include/stddef.h has already defined max_align_t. Override it. */ | |
65 | typedef long rpl_max_align_t; | |
66 | # define max_align_t rpl_max_align_t | |
67 | # else | |
68 | /* Prevent /usr/include/stddef.h from defining max_align_t. */ | |
69 | typedef long max_align_t; | |
70 | # define _MAX_ALIGN_T | |
71 | # endif | |
72 | # define GNULIB_defined_max_align_t 1 | |
73 | # endif | |
74 | # endif | |
75 | ||
f434ba03 PA |
76 | /* The include_next requires a split double-inclusion guard. */ |
77 | ||
78 | # @INCLUDE_NEXT@ @NEXT_STDDEF_H@ | |
79 | ||
f434ba03 | 80 | /* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */ |
4a626d0a PA |
81 | # if (@REPLACE_NULL@ \ |
82 | && (!defined _@GUARD_PREFIX@_STDDEF_H || defined _GL_STDDEF_WINT_T)) | |
83 | # undef NULL | |
84 | # ifdef __cplusplus | |
f434ba03 PA |
85 | /* ISO C++ says that the macro NULL must expand to an integer constant |
86 | expression, hence '((void *) 0)' is not allowed in C++. */ | |
4a626d0a | 87 | # if __GNUG__ >= 3 |
f434ba03 PA |
88 | /* GNU C++ has a __null macro that behaves like an integer ('int' or |
89 | 'long') but has the same size as a pointer. Use that, to avoid | |
90 | warnings. */ | |
4a626d0a PA |
91 | # define NULL __null |
92 | # else | |
93 | # define NULL 0L | |
94 | # endif | |
95 | # else | |
96 | # define NULL ((void *) 0) | |
97 | # endif | |
f434ba03 | 98 | # endif |
4a626d0a PA |
99 | |
100 | # ifndef _@GUARD_PREFIX@_STDDEF_H | |
101 | # define _@GUARD_PREFIX@_STDDEF_H | |
f434ba03 PA |
102 | |
103 | /* Some platforms lack wchar_t. */ | |
104 | #if !@HAVE_WCHAR_T@ | |
105 | # define wchar_t int | |
106 | #endif | |
107 | ||
49e4877c PA |
108 | /* Some platforms lack max_align_t. The check for _GCC_MAX_ALIGN_T is |
109 | a hack in case the configure-time test was done with g++ even though | |
c0c3707f CB |
110 | we are currently compiling with gcc. |
111 | On MSVC, max_align_t is defined only in C++ mode, after <cstddef> was | |
112 | included. Its definition is good since it has an alignment of 8 (on x86 | |
dc6c21da TT |
113 | and x86_64). |
114 | Similarly on OS/2 kLIBC. */ | |
115 | #if (defined _MSC_VER || (defined __KLIBC__ && !defined __LIBCN__)) \ | |
116 | && defined __cplusplus | |
c0c3707f CB |
117 | # include <cstddef> |
118 | #else | |
dc6c21da | 119 | # if ! (@HAVE_MAX_ALIGN_T@ || (defined _GCC_MAX_ALIGN_T && !defined __clang__)) |
c0c3707f | 120 | # if !GNULIB_defined_max_align_t |
4a626d0a PA |
121 | /* On the x86, the maximum storage alignment of double, long, etc. is 4, |
122 | but GCC's C11 ABI for x86 says that max_align_t has an alignment of 8, | |
123 | and the C11 standard allows this. Work around this problem by | |
124 | using __alignof__ (which returns 8 for double) rather than _Alignof | |
125 | (which returns 4), and align each union member accordingly. */ | |
9c9d63b1 | 126 | # if defined __GNUC__ || (__clang_major__ >= 4) |
c0c3707f CB |
127 | # define _GL_STDDEF_ALIGNAS(type) \ |
128 | __attribute__ ((__aligned__ (__alignof__ (type)))) | |
129 | # else | |
130 | # define _GL_STDDEF_ALIGNAS(type) /* */ | |
131 | # endif | |
4a626d0a PA |
132 | typedef union |
133 | { | |
134 | char *__p _GL_STDDEF_ALIGNAS (char *); | |
135 | double __d _GL_STDDEF_ALIGNAS (double); | |
136 | long double __ld _GL_STDDEF_ALIGNAS (long double); | |
137 | long int __i _GL_STDDEF_ALIGNAS (long int); | |
c0c3707f CB |
138 | } rpl_max_align_t; |
139 | # define max_align_t rpl_max_align_t | |
140 | # define GNULIB_defined_max_align_t 1 | |
141 | # endif | |
142 | # endif | |
4a626d0a PA |
143 | #endif |
144 | ||
770d76d7 PA |
145 | # endif /* _@GUARD_PREFIX@_STDDEF_H */ |
146 | # endif /* _@GUARD_PREFIX@_STDDEF_H */ | |
f434ba03 | 147 | #endif /* __need_XXX */ |