1 /* Copyright (C) 1992-2001, 2002, 2004, 2005, 2006, 2007
2    Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9 
10    The GNU C Library 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 GNU
13    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <http://www.gnu.org/licenses/>.  */
18 
19 #ifndef	_SYS_CDEFS_H
20 #define	_SYS_CDEFS_H	1
21 
22 /* We are almost always included from features.h. */
23 #ifndef _FEATURES_H
24 # include <features.h>
25 #endif
26 
27 /* The GNU libc does not support any K&R compilers or the traditional mode
28    of ISO C compilers anymore.  Check for some of the combinations not
29    anymore supported.  */
30 #if defined __GNUC__ && !defined __STDC__
31 # error "You need a ISO C conforming compiler to use the glibc headers"
32 #endif
33 
34 /* Some user header file might have defined this before.  */
35 #undef	__P
36 #undef	__PMT
37 
38 #ifdef __GNUC__
39 
40 /* GCC can always grok prototypes.  For C++ programs we add throw()
41    to help it optimize the function calls.  But this works only with
42    gcc 2.8.x and egcs.  For gcc 3.2 and up we even mark C functions
43    as non-throwing using a function attribute since programs can use
44    the -fexceptions options for C code as well.  */
45 # if !defined __cplusplus && __GNUC_PREREQ (3, 3)
46 #  define __THROW	__attribute__ ((__nothrow__))
47 #  define __NTH(fct)	__attribute__ ((__nothrow__)) fct
48 # else
49 #  if defined __cplusplus && __GNUC_PREREQ (2,8)
50 #   define __THROW	throw ()
51 #   define __NTH(fct)	fct throw ()
52 #  else
53 #   define __THROW
54 #   define __NTH(fct)	fct
55 #  endif
56 # endif
57 
58 #else	/* Not GCC.  */
59 
60 # define __inline		/* No inline functions.  */
61 
62 # define __THROW
63 # define __NTH(fct)	fct
64 
65 #endif	/* GCC.  */
66 
67 /* These two macros are not used in glibc anymore.  They are kept here
68    only because some other projects expect the macros to be defined.  */
69 #define __P(args)	args
70 #define __PMT(args)	args
71 
72 /* For these things, GCC behaves the ANSI way normally,
73    and the non-ANSI way under -traditional.  */
74 
75 #define __CONCAT(x,y)	x ## y
76 #define __STRING(x)	#x
77 
78 /* This is not a typedef so `const __ptr_t' does the right thing.  */
79 #define __ptr_t void *
80 #define __long_double_t  long double
81 
82 
83 /* C++ needs to know that types and declarations are C, not C++.  */
84 #ifdef	__cplusplus
85 # define __BEGIN_DECLS	extern "C" {
86 # define __END_DECLS	}
87 #else
88 # define __BEGIN_DECLS
89 # define __END_DECLS
90 #endif
91 
92 
93 /* The standard library needs the functions from the ISO C90 standard
94    in the std namespace.  At the same time we want to be safe for
95    future changes and we include the ISO C99 code in the non-standard
96    namespace __c99.  The C++ wrapper header take case of adding the
97    definitions to the global namespace.  */
98 #if defined __cplusplus && defined _GLIBCPP_USE_NAMESPACES
99 # define __BEGIN_NAMESPACE_STD	namespace std {
100 # define __END_NAMESPACE_STD	}
101 # define __USING_NAMESPACE_STD(name) using std::name;
102 # define __BEGIN_NAMESPACE_C99	namespace __c99 {
103 # define __END_NAMESPACE_C99	}
104 # define __USING_NAMESPACE_C99(name) using __c99::name;
105 #else
106 /* For compatibility we do not add the declarations into any
107    namespace.  They will end up in the global namespace which is what
108    old code expects.  */
109 # define __BEGIN_NAMESPACE_STD
110 # define __END_NAMESPACE_STD
111 # define __USING_NAMESPACE_STD(name)
112 # define __BEGIN_NAMESPACE_C99
113 # define __END_NAMESPACE_C99
114 # define __USING_NAMESPACE_C99(name)
115 #endif
116 
117 
118 /* Fortify support.  */
119 #define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
120 #define __bos0(ptr) __builtin_object_size (ptr, 0)
121 
122 #if __GNUC_PREREQ (4,3)
123 # define __warndecl(name, msg) \
124   extern void name (void) __attribute__((__warning__ (msg)))
125 # define __warnattr(msg) __attribute__((__warning__ (msg)))
126 # define __errordecl(name, msg) \
127   extern void name (void) __attribute__((__error__ (msg)))
128 #else
129 # define __warndecl(name, msg) extern void name (void)
130 # define __warnattr(msg)
131 # define __errordecl(name, msg) extern void name (void)
132 #endif
133 
134 /* Support for flexible arrays.  */
135 #if __GNUC_PREREQ (2,97)
136 /* GCC 2.97 supports C99 flexible array members.  */
137 # define __flexarr	[]
138 #else
139 # ifdef __GNUC__
140 #  define __flexarr	[0]
141 # else
142 #  if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
143 #   define __flexarr	[]
144 #  else
145 /* Some other non-C99 compiler.  Approximate with [1].  */
146 #   define __flexarr	[1]
147 #  endif
148 # endif
149 #endif
150 
151 
152 /* __asm__ ("xyz") is used throughout the headers to rename functions
153    at the assembly language level.  This is wrapped by the __REDIRECT
154    macro, in order to support compilers that can do this some other
155    way.  When compilers don't support asm-names at all, we have to do
156    preprocessor tricks instead (which don't have exactly the right
157    semantics, but it's the best we can do).
158 
159    Example:
160    int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
161 
162 #if defined __GNUC__ && __GNUC__ >= 2
163 
164 # define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
165 # ifdef __cplusplus
166 #  define __REDIRECT_NTH(name, proto, alias) \
167      name proto __THROW __asm__ (__ASMNAME (#alias))
168 # else
169 #  define __REDIRECT_NTH(name, proto, alias) \
170      name proto __asm__ (__ASMNAME (#alias)) __THROW
171 # endif
172 # define __ASMNAME(cname)  __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
173 # define __ASMNAME2(prefix, cname) __STRING (prefix) cname
174 
175 /*
176 #elif __SOME_OTHER_COMPILER__
177 
178 # define __REDIRECT(name, proto, alias) name proto; \
179 	_Pragma("let " #name " = " #alias)
180 */
181 #endif
182 
183 /* GCC has various useful declarations that can be made with the
184    `__attribute__' syntax.  All of the ways we use this do fine if
185    they are omitted for compilers that don't understand it. */
186 #if !defined __GNUC__ || __GNUC__ < 2
187 # define __attribute__(xyz)	/* Ignore */
188 #endif
189 
190 /* We make this a no-op unless it can be used as both a variable and
191    a type attribute.  gcc 2.8 is known to support both.  */
192 #if __GNUC_PREREQ (2,8)
193 # define __attribute_aligned__(size) __attribute__ ((__aligned__ (size)))
194 #else
195 # define __attribute_aligned__(size) /* Ignore */
196 #endif
197 
198 /* At some point during the gcc 2.96 development the `malloc' attribute
199    for functions was introduced.  We don't want to use it unconditionally
200    (although this would be possible) since it generates warnings.  */
201 #if __GNUC_PREREQ (2,96)
202 # define __attribute_malloc__ __attribute__ ((__malloc__))
203 #else
204 # define __attribute_malloc__ /* Ignore */
205 #endif
206 
207 /* At some point during the gcc 2.96 development the `pure' attribute
208    for functions was introduced.  We don't want to use it unconditionally
209    (although this would be possible) since it generates warnings.  */
210 #if __GNUC_PREREQ (2,96)
211 # define __attribute_pure__ __attribute__ ((__pure__))
212 #else
213 # define __attribute_pure__ /* Ignore */
214 #endif
215 
216 /* At some point during the gcc 3.1 development the `used' attribute
217    for functions was introduced.  We don't want to use it unconditionally
218    (although this would be possible) since it generates warnings.  */
219 #if __GNUC_PREREQ (3,1)
220 # define __attribute_used__ __attribute__ ((__used__))
221 # define __attribute_noinline__ __attribute__ ((__noinline__))
222 #else
223 # define __attribute_used__ __attribute__ ((__unused__))
224 # define __attribute_noinline__ /* Ignore */
225 #endif
226 
227 /* gcc allows marking deprecated functions.  */
228 #if __GNUC_PREREQ (3,2) && !defined(__UCLIBC_HIDE_DEPRECATED__)
229 # define __attribute_deprecated__ __attribute__ ((__deprecated__))
230 #else
231 # define __attribute_deprecated__ /* Ignore */
232 #endif
233 
234 /* At some point during the gcc 2.8 development the `format_arg' attribute
235    for functions was introduced.  We don't want to use it unconditionally
236    (although this would be possible) since it generates warnings.
237    If several `format_arg' attributes are given for the same function, in
238    gcc-3.0 and older, all but the last one are ignored.  In newer gccs,
239    all designated arguments are considered.  */
240 #if __GNUC_PREREQ (2,8)
241 # define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
242 #else
243 # define __attribute_format_arg__(x) /* Ignore */
244 #endif
245 
246 /* At some point during the gcc 2.97 development the `strfmon' format
247    attribute for functions was introduced.  We don't want to use it
248    unconditionally (although this would be possible) since it
249    generates warnings.  */
250 #if __GNUC_PREREQ (2,97)
251 # define __attribute_format_strfmon__(a,b) \
252   __attribute__ ((__format__ (__strfmon__, a, b)))
253 #else
254 # define __attribute_format_strfmon__(a,b) /* Ignore */
255 #endif
256 
257 /* The nonull function attribute allows to mark pointer parameters which
258    must not be NULL.  */
259 #if __GNUC_PREREQ (3,3)
260 # define __nonnull(params) __attribute__ ((__nonnull__ params))
261 #else
262 # define __nonnull(params)
263 #endif
264 
265 /* If fortification mode, we warn about unused results of certain
266    function calls which can lead to problems.  */
267 #if __GNUC_PREREQ (3,4)
268 # define __attribute_warn_unused_result__ \
269    __attribute__ ((__warn_unused_result__))
270 # if __USE_FORTIFY_LEVEL > 0
271 #  define __wur __attribute_warn_unused_result__
272 # endif
273 #else
274 # define __attribute_warn_unused_result__ /* empty */
275 #endif
276 #ifndef __wur
277 # define __wur /* Ignore */
278 #endif
279 
280 /* Forces a function to be always inlined.  */
281 #if __GNUC_PREREQ (3,2)
282 # define __always_inline __inline __attribute__ ((__always_inline__))
283 #else
284 # define __always_inline __inline
285 #endif
286 
287 /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
288    inline semantics, unless -fgnu89-inline is used.
289    For -std=gnu99, forcing gnu_inline attribute does not change behavior,
290    but may silence spurious warnings (such as in GCC 4.2).  */
291 /* start L4: add clang */
292 #if !defined __cplusplus || __GNUC_PREREQ (4,3) || defined __clang__
293 /* L4: original code
294 #if !defined __cplusplus || __GNUC_PREREQ (4,3)
295 */
296 /* end L4: */
297 # if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__ || defined __cplusplus
298 #  define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
299 #  if __GNUC_PREREQ (4,3)
300 #   define __extern_always_inline \
301   extern __always_inline __attribute__ ((__gnu_inline__, __artificial__))
302 #  else
303 #   define __extern_always_inline \
304   extern __always_inline __attribute__ ((__gnu_inline__))
305 #  endif
306 # else
307 #  define __extern_inline extern __inline
308 #  define __extern_always_inline extern __always_inline
309 # endif
310 #endif
311 
312 /* GCC 4.3 and above allow passing all anonymous arguments of an
313    __extern_always_inline function to some other vararg function.  */
314 #if __GNUC_PREREQ (4,3)
315 # define __va_arg_pack() __builtin_va_arg_pack ()
316 # define __va_arg_pack_len() __builtin_va_arg_pack_len ()
317 #endif
318 
319 /* It is possible to compile containing GCC extensions even if GCC is
320    run in pedantic mode if the uses are carefully marked using the
321    `__extension__' keyword.  But this is not generally available before
322    version 2.8.  */
323 #if !__GNUC_PREREQ (2,8)
324 # define __extension__		/* Ignore */
325 #endif
326 
327 /* __restrict is known in EGCS 1.2 and above. */
328 #if !__GNUC_PREREQ (2,92)
329 # define __restrict	/* Ignore */
330 #endif
331 
332 /* ISO C99 also allows to declare arrays as non-overlapping.  The syntax is
333      array_name[restrict]
334    GCC 3.1 supports this.  */
335 #if __GNUC_PREREQ (3,1) && !defined __GNUG__
336 # define __restrict_arr	__restrict
337 #else
338 # ifdef __GNUC__
339 #  define __restrict_arr	/* Not supported in old GCC.  */
340 # else
341 #  if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
342 #   define __restrict_arr	restrict
343 #  else
344 /* Some other non-C99 compiler.  */
345 #   define __restrict_arr	/* Not supported.  */
346 #  endif
347 # endif
348 #endif
349 
350 #endif	 /* sys/cdefs.h */
351