1/* Copyright (C) 1992-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
17
18#ifndef _SYS_CDEFS_H
19#define _SYS_CDEFS_H 1
20
21/* We are almost always included from features.h. */
22#ifndef _FEATURES_H
23# include <features.h>
24#endif
25
26/* The GNU libc does not support any K&R compilers or the traditional mode
27 of ISO C compilers anymore. Check for some of the combinations not
28 anymore supported. */
29#if defined __GNUC__ && !defined __STDC__
30# error "You need a ISO C conforming compiler to use the glibc headers"
31#endif
32
33/* Some user header file might have defined this before. */
34#undef __P
35#undef __PMT
36
37#ifdef __GNUC__
38
39/* All functions, except those with callbacks or those that
40 synchronize memory, are leaf functions. */
41# if __GNUC_PREREQ (4, 6) && !defined _LIBC
42# define __LEAF , __leaf__
43# define __LEAF_ATTR __attribute__ ((__leaf__))
44# else
45# define __LEAF
46# define __LEAF_ATTR
47# endif
48
49/* GCC can always grok prototypes. For C++ programs we add throw()
50 to help it optimize the function calls. But this works only with
51 gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions
52 as non-throwing using a function attribute since programs can use
53 the -fexceptions options for C code as well. */
54# if !defined __cplusplus && __GNUC_PREREQ (3, 3)
55# define __THROW __attribute__ ((__nothrow__ __LEAF))
56# define __THROWNL __attribute__ ((__nothrow__))
57# define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
58# else
59# if defined __cplusplus && __GNUC_PREREQ (2,8)
60# define __THROW throw ()
61# define __THROWNL throw ()
62# define __NTH(fct) __LEAF_ATTR fct throw ()
63# else
64# define __THROW
65# define __THROWNL
66# define __NTH(fct) fct
67# endif
68# endif
69
70#else /* Not GCC. */
71
72# define __inline /* No inline functions. */
73
74# define __THROW
75# define __THROWNL
76# define __NTH(fct) fct
77
78#endif /* GCC. */
79
80/* Compilers that are not clang may object to
81 #if defined __clang__ && __has_extension(...)
82 even though they do not need to evaluate the right-hand side of the &&. */
83#if defined __clang__ && defined __has_extension
84# define __glibc_clang_has_extension(ext) __has_extension (ext)
85#else
86# define __glibc_clang_has_extension(ext) 0
87#endif
88
89/* These two macros are not used in glibc anymore. They are kept here
90 only because some other projects expect the macros to be defined. */
91#define __P(args) args
92#define __PMT(args) args
93
94/* For these things, GCC behaves the ANSI way normally,
95 and the non-ANSI way under -traditional. */
96
97#define __CONCAT(x,y) x ## y
98#define __STRING(x) #x
99
100/* This is not a typedef so `const __ptr_t' does the right thing. */
101#define __ptr_t void *
102#define __long_double_t long double
103
104
105/* C++ needs to know that types and declarations are C, not C++. */
106#ifdef __cplusplus
107# define __BEGIN_DECLS extern "C" {
108# define __END_DECLS }
109#else
110# define __BEGIN_DECLS
111# define __END_DECLS
112#endif
113
114
115/* The standard library needs the functions from the ISO C90 standard
116 in the std namespace. At the same time we want to be safe for
117 future changes and we include the ISO C99 code in the non-standard
118 namespace __c99. The C++ wrapper header take case of adding the
119 definitions to the global namespace. */
120#if defined __cplusplus && defined _GLIBCPP_USE_NAMESPACES
121# define __BEGIN_NAMESPACE_STD namespace std {
122# define __END_NAMESPACE_STD }
123# define __USING_NAMESPACE_STD(name) using std::name;
124# define __BEGIN_NAMESPACE_C99 namespace __c99 {
125# define __END_NAMESPACE_C99 }
126# define __USING_NAMESPACE_C99(name) using __c99::name;
127#else
128/* For compatibility we do not add the declarations into any
129 namespace. They will end up in the global namespace which is what
130 old code expects. */
131# define __BEGIN_NAMESPACE_STD
132# define __END_NAMESPACE_STD
133# define __USING_NAMESPACE_STD(name)
134# define __BEGIN_NAMESPACE_C99
135# define __END_NAMESPACE_C99
136# define __USING_NAMESPACE_C99(name)
137#endif
138
139
140/* Fortify support. */
141#define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
142#define __bos0(ptr) __builtin_object_size (ptr, 0)
143
144#if __GNUC_PREREQ (4,3)
145# define __warndecl(name, msg) \
146 extern void name (void) __attribute__((__warning__ (msg)))
147# define __warnattr(msg) __attribute__((__warning__ (msg)))
148# define __errordecl(name, msg) \
149 extern void name (void) __attribute__((__error__ (msg)))
150#else
151# define __warndecl(name, msg) extern void name (void)
152# define __warnattr(msg)
153# define __errordecl(name, msg) extern void name (void)
154#endif
155
156/* Support for flexible arrays.
157 Headers that should use flexible arrays only if they're "real"
158 (e.g. only if they won't affect sizeof()) should test
159 #if __glibc_c99_flexarr_available. */
160#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
161# define __flexarr []
162# define __glibc_c99_flexarr_available 1
163#elif __GNUC_PREREQ (2,97)
164/* GCC 2.97 supports C99 flexible array members as an extension,
165 even when in C89 mode or compiling C++ (any version). */
166# define __flexarr []
167# define __glibc_c99_flexarr_available 1
168#elif defined __GNUC__
169/* Pre-2.97 GCC did not support C99 flexible arrays but did have
170 an equivalent extension with slightly different notation. */
171# define __flexarr [0]
172# define __glibc_c99_flexarr_available 1
173#else
174/* Some other non-C99 compiler. Approximate with [1]. */
175# define __flexarr [1]
176# define __glibc_c99_flexarr_available 0
177#endif
178
179
180/* __asm__ ("xyz") is used throughout the headers to rename functions
181 at the assembly language level. This is wrapped by the __REDIRECT
182 macro, in order to support compilers that can do this some other
183 way. When compilers don't support asm-names at all, we have to do
184 preprocessor tricks instead (which don't have exactly the right
185 semantics, but it's the best we can do).
186
187 Example:
188 int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
189
190#if defined __GNUC__ && __GNUC__ >= 2
191
192# define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
193# ifdef __cplusplus
194# define __REDIRECT_NTH(name, proto, alias) \
195 name proto __THROW __asm__ (__ASMNAME (#alias))
196# define __REDIRECT_NTHNL(name, proto, alias) \
197 name proto __THROWNL __asm__ (__ASMNAME (#alias))
198# else
199# define __REDIRECT_NTH(name, proto, alias) \
200 name proto __asm__ (__ASMNAME (#alias)) __THROW
201# define __REDIRECT_NTHNL(name, proto, alias) \
202 name proto __asm__ (__ASMNAME (#alias)) __THROWNL
203# endif
204# define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
205# define __ASMNAME2(prefix, cname) __STRING (prefix) cname
206
207/*
208#elif __SOME_OTHER_COMPILER__
209
210# define __REDIRECT(name, proto, alias) name proto; \
211 _Pragma("let " #name " = " #alias)
212*/
213#endif
214
215/* GCC has various useful declarations that can be made with the
216 `__attribute__' syntax. All of the ways we use this do fine if
217 they are omitted for compilers that don't understand it. */
218#if !defined __GNUC__ || __GNUC__ < 2
219# define __attribute__(xyz) /* Ignore */
220#endif
221
222/* At some point during the gcc 2.96 development the `malloc' attribute
223 for functions was introduced. We don't want to use it unconditionally
224 (although this would be possible) since it generates warnings. */
225#if __GNUC_PREREQ (2,96)
226# define __attribute_malloc__ __attribute__ ((__malloc__))
227#else
228# define __attribute_malloc__ /* Ignore */
229#endif
230
231/* Tell the compiler which arguments to an allocation function
232 indicate the size of the allocation. */
233#if __GNUC_PREREQ (4, 3)
234# define __attribute_alloc_size__(params) \
235 __attribute__ ((__alloc_size__ params))
236#else
237# define __attribute_alloc_size__(params) /* Ignore. */
238#endif
239
240/* At some point during the gcc 2.96 development the `pure' attribute
241 for functions was introduced. We don't want to use it unconditionally
242 (although this would be possible) since it generates warnings. */
243#if __GNUC_PREREQ (2,96)
244# define __attribute_pure__ __attribute__ ((__pure__))
245#else
246# define __attribute_pure__ /* Ignore */
247#endif
248
249/* This declaration tells the compiler that the value is constant. */
250#if __GNUC_PREREQ (2,5)
251# define __attribute_const__ __attribute__ ((__const__))
252#else
253# define __attribute_const__ /* Ignore */
254#endif
255
256/* At some point during the gcc 3.1 development the `used' attribute
257 for functions was introduced. We don't want to use it unconditionally
258 (although this would be possible) since it generates warnings. */
259#if __GNUC_PREREQ (3,1)
260# define __attribute_used__ __attribute__ ((__used__))
261# define __attribute_noinline__ __attribute__ ((__noinline__))
262#else
263# define __attribute_used__ __attribute__ ((__unused__))
264# define __attribute_noinline__ /* Ignore */
265#endif
266
267/* Since version 3.2, gcc allows marking deprecated functions. */
268#if __GNUC_PREREQ (3,2)
269# define __attribute_deprecated__ __attribute__ ((__deprecated__))
270#else
271# define __attribute_deprecated__ /* Ignore */
272#endif
273
274/* Since version 4.5, gcc also allows one to specify the message printed
275 when a deprecated function is used. clang claims to be gcc 4.2, but
276 may also support this feature. */
277#if __GNUC_PREREQ (4,5) || \
278 __glibc_clang_has_extension (__attribute_deprecated_with_message__)
279# define __attribute_deprecated_msg__(msg) \
280 __attribute__ ((__deprecated__ (msg)))
281#else
282# define __attribute_deprecated_msg__(msg) __attribute_deprecated__
283#endif
284
285/* At some point during the gcc 2.8 development the `format_arg' attribute
286 for functions was introduced. We don't want to use it unconditionally
287 (although this would be possible) since it generates warnings.
288 If several `format_arg' attributes are given for the same function, in
289 gcc-3.0 and older, all but the last one are ignored. In newer gccs,
290 all designated arguments are considered. */
291#if __GNUC_PREREQ (2,8)
292# define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
293#else
294# define __attribute_format_arg__(x) /* Ignore */
295#endif
296
297/* At some point during the gcc 2.97 development the `strfmon' format
298 attribute for functions was introduced. We don't want to use it
299 unconditionally (although this would be possible) since it
300 generates warnings. */
301#if __GNUC_PREREQ (2,97)
302# define __attribute_format_strfmon__(a,b) \
303 __attribute__ ((__format__ (__strfmon__, a, b)))
304#else
305# define __attribute_format_strfmon__(a,b) /* Ignore */
306#endif
307
308/* The nonull function attribute allows to mark pointer parameters which
309 must not be NULL. */
310#if __GNUC_PREREQ (3,3)
311# define __nonnull(params) __attribute__ ((__nonnull__ params))
312#else
313# define __nonnull(params)
314#endif
315
316/* If fortification mode, we warn about unused results of certain
317 function calls which can lead to problems. */
318#if __GNUC_PREREQ (3,4)
319# define __attribute_warn_unused_result__ \
320 __attribute__ ((__warn_unused_result__))
321# if __USE_FORTIFY_LEVEL > 0
322# define __wur __attribute_warn_unused_result__
323# endif
324#else
325# define __attribute_warn_unused_result__ /* empty */
326#endif
327#ifndef __wur
328# define __wur /* Ignore */
329#endif
330
331/* Forces a function to be always inlined. */
332#if __GNUC_PREREQ (3,2)
333/* The Linux kernel defines __always_inline in stddef.h (283d7573), and
334 it conflicts with this definition. Therefore undefine it first to
335 allow either header to be included first. */
336# undef __always_inline
337# define __always_inline __inline __attribute__ ((__always_inline__))
338#else
339# undef __always_inline
340# define __always_inline __inline
341#endif
342
343/* Associate error messages with the source location of the call site rather
344 than with the source location inside the function. */
345#if __GNUC_PREREQ (4,3)
346# define __attribute_artificial__ __attribute__ ((__artificial__))
347#else
348# define __attribute_artificial__ /* Ignore */
349#endif
350
351/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
352 inline semantics, unless -fgnu89-inline is used. Using __GNUC_STDC_INLINE__
353 or __GNUC_GNU_INLINE is not a good enough check for gcc because gcc versions
354 older than 4.3 may define these macros and still not guarantee GNU inlining
355 semantics.
356
357 clang++ identifies itself as gcc-4.2, but has support for GNU inlining
358 semantics, that can be checked fot by using the __GNUC_STDC_INLINE_ and
359 __GNUC_GNU_INLINE__ macro definitions. */
360#if (!defined __cplusplus || __GNUC_PREREQ (4,3) \
361 || (defined __clang__ && (defined __GNUC_STDC_INLINE__ \
362 || defined __GNUC_GNU_INLINE__)))
363# if defined __GNUC_STDC_INLINE__ || defined __cplusplus
364# define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
365# define __extern_always_inline \
366 extern __always_inline __attribute__ ((__gnu_inline__))
367# else
368# define __extern_inline extern __inline
369# define __extern_always_inline extern __always_inline
370# endif
371#endif
372
373#ifdef __extern_always_inline
374# define __fortify_function __extern_always_inline __attribute_artificial__
375#endif
376
377/* GCC 4.3 and above allow passing all anonymous arguments of an
378 __extern_always_inline function to some other vararg function. */
379#if __GNUC_PREREQ (4,3)
380# define __va_arg_pack() __builtin_va_arg_pack ()
381# define __va_arg_pack_len() __builtin_va_arg_pack_len ()
382#endif
383
384/* It is possible to compile containing GCC extensions even if GCC is
385 run in pedantic mode if the uses are carefully marked using the
386 `__extension__' keyword. But this is not generally available before
387 version 2.8. */
388#if !__GNUC_PREREQ (2,8)
389# define __extension__ /* Ignore */
390#endif
391
392/* __restrict is known in EGCS 1.2 and above. */
393#if !__GNUC_PREREQ (2,92)
394# define __restrict /* Ignore */
395#endif
396
397/* ISO C99 also allows to declare arrays as non-overlapping. The syntax is
398 array_name[restrict]
399 GCC 3.1 supports this. */
400#if __GNUC_PREREQ (3,1) && !defined __GNUG__
401# define __restrict_arr __restrict
402#else
403# ifdef __GNUC__
404# define __restrict_arr /* Not supported in old GCC. */
405# else
406# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
407# define __restrict_arr restrict
408# else
409/* Some other non-C99 compiler. */
410# define __restrict_arr /* Not supported. */
411# endif
412# endif
413#endif
414
415#if __GNUC__ >= 3
416# define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
417# define __glibc_likely(cond) __builtin_expect ((cond), 1)
418#else
419# define __glibc_unlikely(cond) (cond)
420# define __glibc_likely(cond) (cond)
421#endif
422
423#if (!defined _Noreturn \
424 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
425 && !__GNUC_PREREQ (4,7))
426# if __GNUC_PREREQ (2,8)
427# define _Noreturn __attribute__ ((__noreturn__))
428# else
429# define _Noreturn
430# endif
431#endif
432
433#if (!defined _Static_assert && !defined __cplusplus \
434 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
435 && (!__GNUC_PREREQ (4, 6) || defined __STRICT_ANSI__))
436# define _Static_assert(expr, diagnostic) \
437 extern int (*__Static_assert_function (void)) \
438 [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
439#endif
440
441#include <bits/wordsize.h>
442#include <bits/long-double.h>
443
444#if defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
445# define __LDBL_COMPAT 1
446# ifdef __REDIRECT
447# define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias)
448# define __LDBL_REDIR(name, proto) \
449 __LDBL_REDIR1 (name, proto, __nldbl_##name)
450# define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias)
451# define __LDBL_REDIR_NTH(name, proto) \
452 __LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
453# define __LDBL_REDIR1_DECL(name, alias) \
454 extern __typeof (name) name __asm (__ASMNAME (#alias));
455# define __LDBL_REDIR_DECL(name) \
456 extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
457# define __REDIRECT_LDBL(name, proto, alias) \
458 __LDBL_REDIR1 (name, proto, __nldbl_##alias)
459# define __REDIRECT_NTH_LDBL(name, proto, alias) \
460 __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
461# endif
462#endif
463#if !defined __LDBL_COMPAT || !defined __REDIRECT
464# define __LDBL_REDIR1(name, proto, alias) name proto
465# define __LDBL_REDIR(name, proto) name proto
466# define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
467# define __LDBL_REDIR_NTH(name, proto) name proto __THROW
468# define __LDBL_REDIR_DECL(name)
469# ifdef __REDIRECT
470# define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
471# define __REDIRECT_NTH_LDBL(name, proto, alias) \
472 __REDIRECT_NTH (name, proto, alias)
473# endif
474#endif
475
476/* __glibc_macro_warning (MESSAGE) issues warning MESSAGE. This is
477 intended for use in preprocessor macros.
478
479 Note: MESSAGE must be a _single_ string; concatenation of string
480 literals is not supported. */
481#if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5)
482# define __glibc_macro_warning1(message) _Pragma (#message)
483# define __glibc_macro_warning(message) \
484 __glibc_macro_warning1 (GCC warning message)
485#else
486# define __glibc_macro_warning(msg)
487#endif
488
489#endif /* sys/cdefs.h */
490