Commit | Line | Data |
---|---|---|
f434ba03 PA |
1 | /* A substitute for POSIX 2008 <stddef.h>, for platforms that have issues. |
2 | ||
5e8754f9 | 3 | Copyright (C) 2009-2016 Free Software Foundation, Inc. |
f434ba03 PA |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3, or (at your option) | |
8 | any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
5e8754f9 | 16 | along with this program; if not, see <http://www.gnu.org/licenses/>. */ |
f434ba03 PA |
17 | |
18 | /* Written by Eric Blake. */ | |
19 | ||
20 | /* | |
21 | * POSIX 2008 <stddef.h> for platforms that have issues. | |
22 | * <http://www.opengroup.org/susv3xbd/stddef.h.html> | |
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@ | |
45 | # endif | |
46 | ||
47 | #else | |
48 | /* Normal invocation convention. */ | |
49 | ||
770d76d7 | 50 | # ifndef _@GUARD_PREFIX@_STDDEF_H |
f434ba03 PA |
51 | |
52 | /* The include_next requires a split double-inclusion guard. */ | |
53 | ||
54 | # @INCLUDE_NEXT@ @NEXT_STDDEF_H@ | |
55 | ||
f434ba03 | 56 | /* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */ |
4a626d0a PA |
57 | # if (@REPLACE_NULL@ \ |
58 | && (!defined _@GUARD_PREFIX@_STDDEF_H || defined _GL_STDDEF_WINT_T)) | |
59 | # undef NULL | |
60 | # ifdef __cplusplus | |
f434ba03 PA |
61 | /* ISO C++ says that the macro NULL must expand to an integer constant |
62 | expression, hence '((void *) 0)' is not allowed in C++. */ | |
4a626d0a | 63 | # if __GNUG__ >= 3 |
f434ba03 PA |
64 | /* GNU C++ has a __null macro that behaves like an integer ('int' or |
65 | 'long') but has the same size as a pointer. Use that, to avoid | |
66 | warnings. */ | |
4a626d0a PA |
67 | # define NULL __null |
68 | # else | |
69 | # define NULL 0L | |
70 | # endif | |
71 | # else | |
72 | # define NULL ((void *) 0) | |
73 | # endif | |
f434ba03 | 74 | # endif |
4a626d0a PA |
75 | |
76 | # ifndef _@GUARD_PREFIX@_STDDEF_H | |
77 | # define _@GUARD_PREFIX@_STDDEF_H | |
f434ba03 PA |
78 | |
79 | /* Some platforms lack wchar_t. */ | |
80 | #if !@HAVE_WCHAR_T@ | |
81 | # define wchar_t int | |
82 | #endif | |
83 | ||
49e4877c PA |
84 | /* Some platforms lack max_align_t. The check for _GCC_MAX_ALIGN_T is |
85 | a hack in case the configure-time test was done with g++ even though | |
86 | we are currently compiling with gcc. */ | |
87 | #if ! (@HAVE_MAX_ALIGN_T@ || defined _GCC_MAX_ALIGN_T) | |
4a626d0a PA |
88 | /* On the x86, the maximum storage alignment of double, long, etc. is 4, |
89 | but GCC's C11 ABI for x86 says that max_align_t has an alignment of 8, | |
90 | and the C11 standard allows this. Work around this problem by | |
91 | using __alignof__ (which returns 8 for double) rather than _Alignof | |
92 | (which returns 4), and align each union member accordingly. */ | |
5e8754f9 SDJ |
93 | # ifdef __GNUC__ |
94 | # define _GL_STDDEF_ALIGNAS(type) \ | |
95 | __attribute__ ((__aligned__ (__alignof__ (type)))) | |
96 | # else | |
97 | # define _GL_STDDEF_ALIGNAS(type) /* */ | |
98 | # endif | |
4a626d0a PA |
99 | typedef union |
100 | { | |
101 | char *__p _GL_STDDEF_ALIGNAS (char *); | |
102 | double __d _GL_STDDEF_ALIGNAS (double); | |
103 | long double __ld _GL_STDDEF_ALIGNAS (long double); | |
104 | long int __i _GL_STDDEF_ALIGNAS (long int); | |
5e8754f9 | 105 | } max_align_t; |
4a626d0a PA |
106 | #endif |
107 | ||
770d76d7 PA |
108 | # endif /* _@GUARD_PREFIX@_STDDEF_H */ |
109 | # endif /* _@GUARD_PREFIX@_STDDEF_H */ | |
f434ba03 | 110 | #endif /* __need_XXX */ |