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