1 /* Copyright (C) 1992-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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 <https://www.gnu.org/licenses/>. */
19 #define _SYS_CDEFS_H 1
21 /* We are almost always included from features.h. */
23 # include <features.h>
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
29 #if defined __GNUC__ && !defined __STDC__
30 # error "You need a ISO C conforming compiler to use the glibc headers"
33 /* Some user header file might have defined this before. */
37 /* Compilers that are not clang may object to
38 #if defined __clang__ && __has_attribute(...)
39 even though they do not need to evaluate the right-hand side of the &&. */
40 #if defined __clang__ && defined __has_attribute
41 # define __glibc_clang_has_attribute(name) __has_attribute (name)
43 # define __glibc_clang_has_attribute(name) 0
46 /* Compilers that are not clang may object to
47 #if defined __clang__ && __has_builtin(...)
48 even though they do not need to evaluate the right-hand side of the &&. */
49 #if defined __clang__ && defined __has_builtin
50 # define __glibc_clang_has_builtin(name) __has_builtin (name)
52 # define __glibc_clang_has_builtin(name) 0
55 /* Compilers that are not clang may object to
56 #if defined __clang__ && __has_extension(...)
57 even though they do not need to evaluate the right-hand side of the &&. */
58 #if defined __clang__ && defined __has_extension
59 # define __glibc_clang_has_extension(ext) __has_extension (ext)
61 # define __glibc_clang_has_extension(ext) 0
64 #if defined __GNUC__ || defined __clang__
66 /* All functions, except those with callbacks or those that
67 synchronize memory, are leaf functions. */
68 # if __GNUC_PREREQ (4, 6) && !defined _LIBC
69 # define __LEAF , __leaf__
70 # define __LEAF_ATTR __attribute__ ((__leaf__))
76 /* GCC can always grok prototypes. For C++ programs we add throw()
77 to help it optimize the function calls. But this works only with
78 gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions
79 as non-throwing using a function attribute since programs can use
80 the -fexceptions options for C code as well. */
81 # if !defined __cplusplus \
82 && (__GNUC_PREREQ (3, 3) || __glibc_clang_has_attribute (__nothrow__))
83 # define __THROW __attribute__ ((__nothrow__ __LEAF))
84 # define __THROWNL __attribute__ ((__nothrow__))
85 # define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
86 # define __NTHNL(fct) __attribute__ ((__nothrow__)) fct
88 # if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major >= 4)
89 # define __THROW throw ()
90 # define __THROWNL throw ()
91 # define __NTH(fct) __LEAF_ATTR fct throw ()
92 # define __NTHNL(fct) fct throw ()
96 # define __NTH(fct) fct
97 # define __NTHNL(fct) fct
101 #else /* Not GCC or clang. */
103 # if (defined __cplusplus \
104 || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
105 # define __inline inline
107 # define __inline /* No inline functions. */
112 # define __NTH(fct) fct
114 #endif /* GCC || clang. */
116 /* These two macros are not used in glibc anymore. They are kept here
117 only because some other projects expect the macros to be defined. */
118 #define __P(args) args
119 #define __PMT(args) args
121 /* For these things, GCC behaves the ANSI way normally,
122 and the non-ANSI way under -traditional. */
124 #define __CONCAT(x,y) x ## y
125 #define __STRING(x) #x
127 /* This is not a typedef so `const __ptr_t' does the right thing. */
128 #define __ptr_t void *
131 /* C++ needs to know that types and declarations are C, not C++. */
133 # define __BEGIN_DECLS extern "C" {
134 # define __END_DECLS }
136 # define __BEGIN_DECLS
141 /* Fortify support. */
142 #define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
143 #define __bos0(ptr) __builtin_object_size (ptr, 0)
145 #if __GNUC_PREREQ (4,3)
146 # define __warndecl(name, msg) \
147 extern void name (void) __attribute__((__warning__ (msg)))
148 # define __warnattr(msg) __attribute__((__warning__ (msg)))
149 # define __errordecl(name, msg) \
150 extern void name (void) __attribute__((__error__ (msg)))
151 #elif __glibc_clang_has_attribute (__diagnose_if__)
152 # define __warndecl(name, msg) \
153 extern void name (void) __attribute__((__diagnose_if__ (1, msg, "warning")))
154 # define __warnattr(msg) __attribute__((__diagnose_if__ (1, msg, "warning")))
155 # define __errordecl(name, msg) \
156 extern void name (void) __attribute__((__diagnose_if__ (1, msg, "error")))
158 # define __warndecl(name, msg) extern void name (void)
159 # define __warnattr(msg)
160 # define __errordecl(name, msg) extern void name (void)
163 /* Support for flexible arrays.
164 Headers that should use flexible arrays only if they're "real"
165 (e.g. only if they won't affect sizeof()) should test
166 #if __glibc_c99_flexarr_available. */
167 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L && !defined __HP_cc
168 # define __flexarr []
169 # define __glibc_c99_flexarr_available 1
170 #elif __GNUC_PREREQ (2,97) || defined __clang__
171 /* GCC 2.97 and clang support C99 flexible array members as an extension,
172 even when in C89 mode or compiling C++ (any version). */
173 # define __flexarr []
174 # define __glibc_c99_flexarr_available 1
175 #elif defined __GNUC__
176 /* Pre-2.97 GCC did not support C99 flexible arrays but did have
177 an equivalent extension with slightly different notation. */
178 # define __flexarr [0]
179 # define __glibc_c99_flexarr_available 1
181 /* Some other non-C99 compiler. Approximate with [1]. */
182 # define __flexarr [1]
183 # define __glibc_c99_flexarr_available 0
187 /* __asm__ ("xyz") is used throughout the headers to rename functions
188 at the assembly language level. This is wrapped by the __REDIRECT
189 macro, in order to support compilers that can do this some other
190 way. When compilers don't support asm-names at all, we have to do
191 preprocessor tricks instead (which don't have exactly the right
192 semantics, but it's the best we can do).
195 int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
197 #if (defined __GNUC__ && __GNUC__ >= 2) || (__clang_major__ >= 4)
199 # define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
201 # define __REDIRECT_NTH(name, proto, alias) \
202 name proto __THROW __asm__ (__ASMNAME (#alias))
203 # define __REDIRECT_NTHNL(name, proto, alias) \
204 name proto __THROWNL __asm__ (__ASMNAME (#alias))
206 # define __REDIRECT_NTH(name, proto, alias) \
207 name proto __asm__ (__ASMNAME (#alias)) __THROW
208 # define __REDIRECT_NTHNL(name, proto, alias) \
209 name proto __asm__ (__ASMNAME (#alias)) __THROWNL
211 # define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
212 # define __ASMNAME2(prefix, cname) __STRING (prefix) cname
215 #elif __SOME_OTHER_COMPILER__
217 # define __REDIRECT(name, proto, alias) name proto; \
218 _Pragma("let " #name " = " #alias)
222 /* GCC and clang have various useful declarations that can be made with
223 the '__attribute__' syntax. All of the ways we use this do fine if
224 they are omitted for compilers that don't understand it. */
225 #if !(defined __GNUC__ || defined __clang__)
226 # define __attribute__(xyz) /* Ignore */
229 /* At some point during the gcc 2.96 development the `malloc' attribute
230 for functions was introduced. We don't want to use it unconditionally
231 (although this would be possible) since it generates warnings. */
232 #if __GNUC_PREREQ (2,96) || __glibc_clang_has_attribute (__malloc__)
233 # define __attribute_malloc__ __attribute__ ((__malloc__))
235 # define __attribute_malloc__ /* Ignore */
238 /* Tell the compiler which arguments to an allocation function
239 indicate the size of the allocation. */
240 #if __GNUC_PREREQ (4, 3)
241 # define __attribute_alloc_size__(params) \
242 __attribute__ ((__alloc_size__ params))
244 # define __attribute_alloc_size__(params) /* Ignore. */
247 /* At some point during the gcc 2.96 development the `pure' attribute
248 for functions was introduced. We don't want to use it unconditionally
249 (although this would be possible) since it generates warnings. */
250 #if __GNUC_PREREQ (2,96) || __glibc_clang_has_attribute (__pure__)
251 # define __attribute_pure__ __attribute__ ((__pure__))
253 # define __attribute_pure__ /* Ignore */
256 /* This declaration tells the compiler that the value is constant. */
257 #if __GNUC_PREREQ (2,5) || __glibc_clang_has_attribute (__const__)
258 # define __attribute_const__ __attribute__ ((__const__))
260 # define __attribute_const__ /* Ignore */
263 /* At some point during the gcc 3.1 development the `used' 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 __GNUC_PREREQ (3,1) || __glibc_clang_has_attribute (__used__)
267 # define __attribute_used__ __attribute__ ((__used__))
268 # define __attribute_noinline__ __attribute__ ((__noinline__))
270 # define __attribute_used__ __attribute__ ((__unused__))
271 # define __attribute_noinline__ /* Ignore */
274 /* Since version 3.2, gcc allows marking deprecated functions. */
275 #if __GNUC_PREREQ (3,2) || __glibc_clang_has_attribute (__deprecated__)
276 # define __attribute_deprecated__ __attribute__ ((__deprecated__))
278 # define __attribute_deprecated__ /* Ignore */
281 /* Since version 4.5, gcc also allows one to specify the message printed
282 when a deprecated function is used. clang claims to be gcc 4.2, but
283 may also support this feature. */
284 #if __GNUC_PREREQ (4,5) || \
285 __glibc_clang_has_extension (__attribute_deprecated_with_message__)
286 # define __attribute_deprecated_msg__(msg) \
287 __attribute__ ((__deprecated__ (msg)))
289 # define __attribute_deprecated_msg__(msg) __attribute_deprecated__
292 /* At some point during the gcc 2.8 development the `format_arg' attribute
293 for functions was introduced. We don't want to use it unconditionally
294 (although this would be possible) since it generates warnings.
295 If several `format_arg' attributes are given for the same function, in
296 gcc-3.0 and older, all but the last one are ignored. In newer gccs,
297 all designated arguments are considered. */
298 #if __GNUC_PREREQ (2,8) || __glibc_clang_has_attribute (__format_arg__)
299 # define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
301 # define __attribute_format_arg__(x) /* Ignore */
304 /* At some point during the gcc 2.97 development the `strfmon' format
305 attribute for functions was introduced. We don't want to use it
306 unconditionally (although this would be possible) since it
307 generates warnings. */
308 #if __GNUC_PREREQ (2,97) || __glibc_clang_has_attribute (__format__)
309 # define __attribute_format_strfmon__(a,b) \
310 __attribute__ ((__format__ (__strfmon__, a, b)))
312 # define __attribute_format_strfmon__(a,b) /* Ignore */
315 /* The nonnull function attribute marks pointer parameters that
316 must not be NULL. Do not define __nonnull if it is already defined,
317 for portability when this file is used in Gnulib. */
319 # if __GNUC_PREREQ (3,3) || __glibc_clang_has_attribute (__nonnull__)
320 # define __nonnull(params) __attribute__ ((__nonnull__ params))
322 # define __nonnull(params)
326 /* If fortification mode, we warn about unused results of certain
327 function calls which can lead to problems. */
328 #if __GNUC_PREREQ (3,4) || __glibc_clang_has_attribute (__warn_unused_result__)
329 # define __attribute_warn_unused_result__ \
330 __attribute__ ((__warn_unused_result__))
331 # if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0
332 # define __wur __attribute_warn_unused_result__
335 # define __attribute_warn_unused_result__ /* empty */
338 # define __wur /* Ignore */
341 /* Forces a function to be always inlined. */
342 #if __GNUC_PREREQ (3,2) || __glibc_clang_has_attribute (__always_inline__)
343 /* The Linux kernel defines __always_inline in stddef.h (283d7573), and
344 it conflicts with this definition. Therefore undefine it first to
345 allow either header to be included first. */
346 # undef __always_inline
347 # define __always_inline __inline __attribute__ ((__always_inline__))
349 # undef __always_inline
350 # define __always_inline __inline
353 /* Associate error messages with the source location of the call site rather
354 than with the source location inside the function. */
355 #if __GNUC_PREREQ (4,3) || __glibc_clang_has_attribute (__artificial__)
356 # define __attribute_artificial__ __attribute__ ((__artificial__))
358 # define __attribute_artificial__ /* Ignore */
361 /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
362 inline semantics, unless -fgnu89-inline is used. Using __GNUC_STDC_INLINE__
363 or __GNUC_GNU_INLINE is not a good enough check for gcc because gcc versions
364 older than 4.3 may define these macros and still not guarantee GNU inlining
367 clang++ identifies itself as gcc-4.2, but has support for GNU inlining
368 semantics, that can be checked for by using the __GNUC_STDC_INLINE_ and
369 __GNUC_GNU_INLINE__ macro definitions. */
370 #if (!defined __cplusplus || __GNUC_PREREQ (4,3) \
371 || (defined __clang__ && (defined __GNUC_STDC_INLINE__ \
372 || defined __GNUC_GNU_INLINE__)))
373 # if defined __GNUC_STDC_INLINE__ || defined __cplusplus
374 # define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
375 # define __extern_always_inline \
376 extern __always_inline __attribute__ ((__gnu_inline__))
378 # define __extern_inline extern __inline
379 # define __extern_always_inline extern __always_inline
383 #ifdef __extern_always_inline
384 # define __fortify_function __extern_always_inline __attribute_artificial__
387 /* GCC 4.3 and above allow passing all anonymous arguments of an
388 __extern_always_inline function to some other vararg function. */
389 #if __GNUC_PREREQ (4,3)
390 # define __va_arg_pack() __builtin_va_arg_pack ()
391 # define __va_arg_pack_len() __builtin_va_arg_pack_len ()
394 /* It is possible to compile containing GCC extensions even if GCC is
395 run in pedantic mode if the uses are carefully marked using the
396 `__extension__' keyword. But this is not generally available before
398 #if !(__GNUC_PREREQ (2,8) || defined __clang__)
399 # define __extension__ /* Ignore */
402 /* __restrict is known in EGCS 1.2 and above, and in clang.
403 It works also in C++ mode (outside of arrays), but only when spelled
404 as '__restrict', not 'restrict'. */
405 #if !(__GNUC_PREREQ (2,92) || __clang_major__ >= 3)
406 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
407 # define __restrict restrict
409 # define __restrict /* Ignore */
413 /* ISO C99 also allows to declare arrays as non-overlapping. The syntax is
415 GCC 3.1 and clang support this.
416 This syntax is not usable in C++ mode. */
417 #if (__GNUC_PREREQ (3,1) || __clang_major__ >= 3) && !defined __cplusplus
418 # define __restrict_arr __restrict
421 # define __restrict_arr /* Not supported in old GCC. */
423 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
424 # define __restrict_arr restrict
426 /* Some other non-C99 compiler. */
427 # define __restrict_arr /* Not supported. */
432 #if (__GNUC__ >= 3) || __glibc_clang_has_builtin (__builtin_expect)
433 # define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
434 # define __glibc_likely(cond) __builtin_expect ((cond), 1)
436 # define __glibc_unlikely(cond) (cond)
437 # define __glibc_likely(cond) (cond)
440 #ifdef __has_attribute
441 # define __glibc_has_attribute(attr) __has_attribute (attr)
443 # define __glibc_has_attribute(attr) 0
446 #if (!defined _Noreturn \
447 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
448 && !(__GNUC_PREREQ (4,7) \
449 || (3 < __clang_major__ + (5 <= __clang_minor__))))
450 # if __GNUC_PREREQ (2,8)
451 # define _Noreturn __attribute__ ((__noreturn__))
457 #if __GNUC_PREREQ (8, 0)
458 /* Describes a char array whose address can safely be passed as the first
459 argument to strncpy and strncat, as the char array is not necessarily
460 a NUL-terminated string. */
461 # define __attribute_nonstring__ __attribute__ ((__nonstring__))
463 # define __attribute_nonstring__
466 #if (!defined _Static_assert && !defined __cplusplus \
467 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
468 && (!(__GNUC_PREREQ (4, 6) || __clang_major__ >= 4) \
469 || defined __STRICT_ANSI__))
470 # define _Static_assert(expr, diagnostic) \
471 extern int (*__Static_assert_function (void)) \
472 [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
475 /* The #ifndef lets Gnulib avoid including these on non-glibc
476 platforms, where the includes typically do not exist. */
478 # include <bits/wordsize.h>
479 # include <bits/long-double.h>
482 #if defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
483 # define __LDBL_COMPAT 1
485 # define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias)
486 # define __LDBL_REDIR(name, proto) \
487 __LDBL_REDIR1 (name, proto, __nldbl_##name)
488 # define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias)
489 # define __LDBL_REDIR_NTH(name, proto) \
490 __LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
491 # define __LDBL_REDIR1_DECL(name, alias) \
492 extern __typeof (name) name __asm (__ASMNAME (#alias));
493 # define __LDBL_REDIR_DECL(name) \
494 extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
495 # define __REDIRECT_LDBL(name, proto, alias) \
496 __LDBL_REDIR1 (name, proto, __nldbl_##alias)
497 # define __REDIRECT_NTH_LDBL(name, proto, alias) \
498 __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
501 #if !defined __LDBL_COMPAT || !defined __REDIRECT
502 # define __LDBL_REDIR1(name, proto, alias) name proto
503 # define __LDBL_REDIR(name, proto) name proto
504 # define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
505 # define __LDBL_REDIR_NTH(name, proto) name proto __THROW
506 # define __LDBL_REDIR_DECL(name)
508 # define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
509 # define __REDIRECT_NTH_LDBL(name, proto, alias) \
510 __REDIRECT_NTH (name, proto, alias)
514 /* __glibc_macro_warning (MESSAGE) issues warning MESSAGE. This is
515 intended for use in preprocessor macros.
517 Note: MESSAGE must be a _single_ string; concatenation of string
518 literals is not supported. */
519 #if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5)
520 # define __glibc_macro_warning1(message) _Pragma (#message)
521 # define __glibc_macro_warning(message) \
522 __glibc_macro_warning1 (GCC warning message)
524 # define __glibc_macro_warning(msg)
527 /* Generic selection (ISO C11) is a C-only feature, available in GCC
528 since version 4.9. Previous versions do not provide generic
529 selection, even though they might set __STDC_VERSION__ to 201112L,
530 when in -std=c11 mode. Thus, we must check for !defined __GNUC__
531 when testing __STDC_VERSION__ for generic selection support.
532 On the other hand, Clang also defines __GNUC__, so a clang-specific
533 check is required to enable the use of generic selection. */
534 #if !defined __cplusplus \
535 && (__GNUC_PREREQ (4, 9) \
536 || __glibc_clang_has_extension (c_generic_selections) \
537 || (!defined __GNUC__ && defined __STDC_VERSION__ \
538 && __STDC_VERSION__ >= 201112L))
539 # define __HAVE_GENERIC_SELECTION 1
541 # define __HAVE_GENERIC_SELECTION 0
544 #endif /* sys/cdefs.h */