Home | History | Annotate | Line # | Download | only in import
      1  1.1.1.2  christos /* Copyright (C) 1992-2022 Free Software Foundation, Inc.
      2  1.1.1.2  christos    Copyright The GNU Toolchain Authors.
      3      1.1  christos    This file is part of the GNU C Library.
      4      1.1  christos 
      5      1.1  christos    The GNU C Library is free software; you can redistribute it and/or
      6  1.1.1.2  christos    modify it under the terms of the GNU Lesser General Public
      7      1.1  christos    License as published by the Free Software Foundation; either
      8  1.1.1.2  christos    version 2.1 of the License, or (at your option) any later version.
      9      1.1  christos 
     10      1.1  christos    The GNU C Library is distributed in the hope that it will be useful,
     11      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13  1.1.1.2  christos    Lesser General Public License for more details.
     14      1.1  christos 
     15  1.1.1.2  christos    You should have received a copy of the GNU Lesser General Public
     16      1.1  christos    License along with the GNU C Library; if not, see
     17      1.1  christos    <https://www.gnu.org/licenses/>.  */
     18      1.1  christos 
     19      1.1  christos #ifndef	_SYS_CDEFS_H
     20      1.1  christos #define	_SYS_CDEFS_H	1
     21      1.1  christos 
     22      1.1  christos /* We are almost always included from features.h. */
     23      1.1  christos #ifndef _FEATURES_H
     24      1.1  christos # include <features.h>
     25      1.1  christos #endif
     26      1.1  christos 
     27      1.1  christos /* The GNU libc does not support any K&R compilers or the traditional mode
     28      1.1  christos    of ISO C compilers anymore.  Check for some of the combinations not
     29  1.1.1.2  christos    supported anymore.  */
     30      1.1  christos #if defined __GNUC__ && !defined __STDC__
     31      1.1  christos # error "You need a ISO C conforming compiler to use the glibc headers"
     32      1.1  christos #endif
     33      1.1  christos 
     34      1.1  christos /* Some user header file might have defined this before.  */
     35      1.1  christos #undef	__P
     36      1.1  christos #undef	__PMT
     37      1.1  christos 
     38  1.1.1.2  christos /* Compilers that lack __has_attribute may object to
     39  1.1.1.2  christos        #if defined __has_attribute && __has_attribute (...)
     40  1.1.1.2  christos    even though they do not need to evaluate the right-hand side of the &&.
     41  1.1.1.2  christos    Similarly for __has_builtin, etc.  */
     42  1.1.1.2  christos #if (defined __has_attribute \
     43  1.1.1.2  christos      && (!defined __clang_minor__ \
     44  1.1.1.2  christos          || (defined __apple_build_version__ \
     45  1.1.1.2  christos              ? 6000000 <= __apple_build_version__ \
     46  1.1.1.2  christos              : 3 < __clang_major__ + (5 <= __clang_minor__))))
     47  1.1.1.2  christos # define __glibc_has_attribute(attr) __has_attribute (attr)
     48  1.1.1.2  christos #else
     49  1.1.1.2  christos # define __glibc_has_attribute(attr) 0
     50  1.1.1.2  christos #endif
     51  1.1.1.2  christos #ifdef __has_builtin
     52  1.1.1.2  christos # define __glibc_has_builtin(name) __has_builtin (name)
     53  1.1.1.2  christos #else
     54  1.1.1.2  christos # define __glibc_has_builtin(name) 0
     55  1.1.1.2  christos #endif
     56  1.1.1.2  christos #ifdef __has_extension
     57  1.1.1.2  christos # define __glibc_has_extension(ext) __has_extension (ext)
     58  1.1.1.2  christos #else
     59  1.1.1.2  christos # define __glibc_has_extension(ext) 0
     60  1.1.1.2  christos #endif
     61  1.1.1.2  christos 
     62  1.1.1.2  christos #if defined __GNUC__ || defined __clang__
     63      1.1  christos 
     64      1.1  christos /* All functions, except those with callbacks or those that
     65      1.1  christos    synchronize memory, are leaf functions.  */
     66      1.1  christos # if __GNUC_PREREQ (4, 6) && !defined _LIBC
     67      1.1  christos #  define __LEAF , __leaf__
     68      1.1  christos #  define __LEAF_ATTR __attribute__ ((__leaf__))
     69      1.1  christos # else
     70      1.1  christos #  define __LEAF
     71      1.1  christos #  define __LEAF_ATTR
     72      1.1  christos # endif
     73      1.1  christos 
     74      1.1  christos /* GCC can always grok prototypes.  For C++ programs we add throw()
     75  1.1.1.2  christos    to help it optimize the function calls.  But this only works with
     76  1.1.1.2  christos    gcc 2.8.x and egcs.  For gcc 3.4 and up we even mark C functions
     77      1.1  christos    as non-throwing using a function attribute since programs can use
     78      1.1  christos    the -fexceptions options for C code as well.  */
     79  1.1.1.2  christos # if !defined __cplusplus \
     80  1.1.1.2  christos      && (__GNUC_PREREQ (3, 4) || __glibc_has_attribute (__nothrow__))
     81      1.1  christos #  define __THROW	__attribute__ ((__nothrow__ __LEAF))
     82      1.1  christos #  define __THROWNL	__attribute__ ((__nothrow__))
     83      1.1  christos #  define __NTH(fct)	__attribute__ ((__nothrow__ __LEAF)) fct
     84      1.1  christos #  define __NTHNL(fct)  __attribute__ ((__nothrow__)) fct
     85      1.1  christos # else
     86  1.1.1.2  christos #  if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major >= 4)
     87  1.1.1.2  christos #   if __cplusplus >= 201103L
     88  1.1.1.2  christos #    define __THROW	noexcept (true)
     89  1.1.1.2  christos #   else
     90  1.1.1.2  christos #    define __THROW	throw ()
     91  1.1.1.2  christos #   endif
     92  1.1.1.2  christos #   define __THROWNL	__THROW
     93  1.1.1.2  christos #   define __NTH(fct)	__LEAF_ATTR fct __THROW
     94  1.1.1.2  christos #   define __NTHNL(fct) fct __THROW
     95      1.1  christos #  else
     96      1.1  christos #   define __THROW
     97      1.1  christos #   define __THROWNL
     98      1.1  christos #   define __NTH(fct)	fct
     99      1.1  christos #   define __NTHNL(fct) fct
    100      1.1  christos #  endif
    101      1.1  christos # endif
    102      1.1  christos 
    103  1.1.1.2  christos #else	/* Not GCC or clang.  */
    104      1.1  christos 
    105      1.1  christos # if (defined __cplusplus						\
    106      1.1  christos       || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
    107      1.1  christos #  define __inline	inline
    108      1.1  christos # else
    109      1.1  christos #  define __inline		/* No inline functions.  */
    110      1.1  christos # endif
    111      1.1  christos 
    112      1.1  christos # define __THROW
    113      1.1  christos # define __THROWNL
    114      1.1  christos # define __NTH(fct)	fct
    115      1.1  christos 
    116  1.1.1.2  christos #endif	/* GCC || clang.  */
    117      1.1  christos 
    118      1.1  christos /* These two macros are not used in glibc anymore.  They are kept here
    119      1.1  christos    only because some other projects expect the macros to be defined.  */
    120      1.1  christos #define __P(args)	args
    121      1.1  christos #define __PMT(args)	args
    122      1.1  christos 
    123      1.1  christos /* For these things, GCC behaves the ANSI way normally,
    124      1.1  christos    and the non-ANSI way under -traditional.  */
    125      1.1  christos 
    126      1.1  christos #define __CONCAT(x,y)	x ## y
    127      1.1  christos #define __STRING(x)	#x
    128      1.1  christos 
    129      1.1  christos /* This is not a typedef so `const __ptr_t' does the right thing.  */
    130      1.1  christos #define __ptr_t void *
    131      1.1  christos 
    132      1.1  christos 
    133      1.1  christos /* C++ needs to know that types and declarations are C, not C++.  */
    134      1.1  christos #ifdef	__cplusplus
    135      1.1  christos # define __BEGIN_DECLS	extern "C" {
    136      1.1  christos # define __END_DECLS	}
    137      1.1  christos #else
    138      1.1  christos # define __BEGIN_DECLS
    139      1.1  christos # define __END_DECLS
    140      1.1  christos #endif
    141      1.1  christos 
    142      1.1  christos 
    143      1.1  christos /* Fortify support.  */
    144      1.1  christos #define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
    145      1.1  christos #define __bos0(ptr) __builtin_object_size (ptr, 0)
    146      1.1  christos 
    147  1.1.1.2  christos /* Use __builtin_dynamic_object_size at _FORTIFY_SOURCE=3 when available.  */
    148  1.1.1.2  christos #if __USE_FORTIFY_LEVEL == 3 && (__glibc_clang_prereq (9, 0)		      \
    149  1.1.1.2  christos 				 || __GNUC_PREREQ (12, 0))
    150  1.1.1.2  christos # define __glibc_objsize0(__o) __builtin_dynamic_object_size (__o, 0)
    151  1.1.1.2  christos # define __glibc_objsize(__o) __builtin_dynamic_object_size (__o, 1)
    152  1.1.1.2  christos #else
    153  1.1.1.2  christos # define __glibc_objsize0(__o) __bos0 (__o)
    154  1.1.1.2  christos # define __glibc_objsize(__o) __bos (__o)
    155  1.1.1.2  christos #endif
    156  1.1.1.2  christos 
    157  1.1.1.2  christos /* Compile time conditions to choose between the regular, _chk and _chk_warn
    158  1.1.1.2  christos    variants.  These conditions should get evaluated to constant and optimized
    159  1.1.1.2  christos    away.  */
    160  1.1.1.2  christos 
    161  1.1.1.2  christos #define __glibc_safe_len_cond(__l, __s, __osz) ((__l) <= (__osz) / (__s))
    162  1.1.1.2  christos #define __glibc_unsigned_or_positive(__l) \
    163  1.1.1.2  christos   ((__typeof (__l)) 0 < (__typeof (__l)) -1				      \
    164  1.1.1.2  christos    || (__builtin_constant_p (__l) && (__l) > 0))
    165  1.1.1.2  christos 
    166  1.1.1.2  christos /* Length is known to be safe at compile time if the __L * __S <= __OBJSZ
    167  1.1.1.2  christos    condition can be folded to a constant and if it is true.  The -1 check is
    168  1.1.1.2  christos    redundant because since it implies that __glibc_safe_len_cond is true.  */
    169  1.1.1.2  christos #define __glibc_safe_or_unknown_len(__l, __s, __osz) \
    170  1.1.1.2  christos   (__glibc_unsigned_or_positive (__l)					      \
    171  1.1.1.2  christos    && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l),     \
    172  1.1.1.2  christos 						   __s, __osz))		      \
    173  1.1.1.2  christos    && __glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz))
    174  1.1.1.2  christos 
    175  1.1.1.2  christos /* Conversely, we know at compile time that the length is unsafe if the
    176  1.1.1.2  christos    __L * __S <= __OBJSZ condition can be folded to a constant and if it is
    177  1.1.1.2  christos    false.  */
    178  1.1.1.2  christos #define __glibc_unsafe_len(__l, __s, __osz) \
    179  1.1.1.2  christos   (__glibc_unsigned_or_positive (__l)					      \
    180  1.1.1.2  christos    && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l),     \
    181  1.1.1.2  christos 						   __s, __osz))		      \
    182  1.1.1.2  christos    && !__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz))
    183  1.1.1.2  christos 
    184  1.1.1.2  christos /* Fortify function f.  __f_alias, __f_chk and __f_chk_warn must be
    185  1.1.1.2  christos    declared.  */
    186  1.1.1.2  christos 
    187  1.1.1.2  christos #define __glibc_fortify(f, __l, __s, __osz, ...) \
    188  1.1.1.2  christos   (__glibc_safe_or_unknown_len (__l, __s, __osz)			      \
    189  1.1.1.2  christos    ? __ ## f ## _alias (__VA_ARGS__)					      \
    190  1.1.1.2  christos    : (__glibc_unsafe_len (__l, __s, __osz)				      \
    191  1.1.1.2  christos       ? __ ## f ## _chk_warn (__VA_ARGS__, __osz)			      \
    192  1.1.1.2  christos       : __ ## f ## _chk (__VA_ARGS__, __osz)))			      \
    193  1.1.1.2  christos 
    194  1.1.1.2  christos /* Fortify function f, where object size argument passed to f is the number of
    195  1.1.1.2  christos    elements and not total size.  */
    196  1.1.1.2  christos 
    197  1.1.1.2  christos #define __glibc_fortify_n(f, __l, __s, __osz, ...) \
    198  1.1.1.2  christos   (__glibc_safe_or_unknown_len (__l, __s, __osz)			      \
    199  1.1.1.2  christos    ? __ ## f ## _alias (__VA_ARGS__)					      \
    200  1.1.1.2  christos    : (__glibc_unsafe_len (__l, __s, __osz)				      \
    201  1.1.1.2  christos       ? __ ## f ## _chk_warn (__VA_ARGS__, (__osz) / (__s))		      \
    202  1.1.1.2  christos       : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s))))		      \
    203  1.1.1.2  christos 
    204      1.1  christos #if __GNUC_PREREQ (4,3)
    205      1.1  christos # define __warnattr(msg) __attribute__((__warning__ (msg)))
    206      1.1  christos # define __errordecl(name, msg) \
    207      1.1  christos   extern void name (void) __attribute__((__error__ (msg)))
    208      1.1  christos #else
    209      1.1  christos # define __warnattr(msg)
    210      1.1  christos # define __errordecl(name, msg) extern void name (void)
    211      1.1  christos #endif
    212      1.1  christos 
    213      1.1  christos /* Support for flexible arrays.
    214      1.1  christos    Headers that should use flexible arrays only if they're "real"
    215      1.1  christos    (e.g. only if they won't affect sizeof()) should test
    216      1.1  christos    #if __glibc_c99_flexarr_available.  */
    217      1.1  christos #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L && !defined __HP_cc
    218      1.1  christos # define __flexarr	[]
    219      1.1  christos # define __glibc_c99_flexarr_available 1
    220  1.1.1.2  christos #elif __GNUC_PREREQ (2,97) || defined __clang__
    221  1.1.1.2  christos /* GCC 2.97 and clang support C99 flexible array members as an extension,
    222      1.1  christos    even when in C89 mode or compiling C++ (any version).  */
    223      1.1  christos # define __flexarr	[]
    224      1.1  christos # define __glibc_c99_flexarr_available 1
    225      1.1  christos #elif defined __GNUC__
    226      1.1  christos /* Pre-2.97 GCC did not support C99 flexible arrays but did have
    227      1.1  christos    an equivalent extension with slightly different notation.  */
    228      1.1  christos # define __flexarr	[0]
    229      1.1  christos # define __glibc_c99_flexarr_available 1
    230      1.1  christos #else
    231      1.1  christos /* Some other non-C99 compiler.  Approximate with [1].  */
    232      1.1  christos # define __flexarr	[1]
    233      1.1  christos # define __glibc_c99_flexarr_available 0
    234      1.1  christos #endif
    235      1.1  christos 
    236      1.1  christos 
    237      1.1  christos /* __asm__ ("xyz") is used throughout the headers to rename functions
    238      1.1  christos    at the assembly language level.  This is wrapped by the __REDIRECT
    239      1.1  christos    macro, in order to support compilers that can do this some other
    240      1.1  christos    way.  When compilers don't support asm-names at all, we have to do
    241      1.1  christos    preprocessor tricks instead (which don't have exactly the right
    242      1.1  christos    semantics, but it's the best we can do).
    243      1.1  christos 
    244      1.1  christos    Example:
    245      1.1  christos    int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
    246      1.1  christos 
    247  1.1.1.2  christos #if (defined __GNUC__ && __GNUC__ >= 2) || (__clang_major__ >= 4)
    248      1.1  christos 
    249      1.1  christos # define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
    250      1.1  christos # ifdef __cplusplus
    251      1.1  christos #  define __REDIRECT_NTH(name, proto, alias) \
    252      1.1  christos      name proto __THROW __asm__ (__ASMNAME (#alias))
    253      1.1  christos #  define __REDIRECT_NTHNL(name, proto, alias) \
    254      1.1  christos      name proto __THROWNL __asm__ (__ASMNAME (#alias))
    255      1.1  christos # else
    256      1.1  christos #  define __REDIRECT_NTH(name, proto, alias) \
    257      1.1  christos      name proto __asm__ (__ASMNAME (#alias)) __THROW
    258      1.1  christos #  define __REDIRECT_NTHNL(name, proto, alias) \
    259      1.1  christos      name proto __asm__ (__ASMNAME (#alias)) __THROWNL
    260      1.1  christos # endif
    261      1.1  christos # define __ASMNAME(cname)  __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
    262      1.1  christos # define __ASMNAME2(prefix, cname) __STRING (prefix) cname
    263      1.1  christos 
    264      1.1  christos /*
    265      1.1  christos #elif __SOME_OTHER_COMPILER__
    266      1.1  christos 
    267      1.1  christos # define __REDIRECT(name, proto, alias) name proto; \
    268      1.1  christos 	_Pragma("let " #name " = " #alias)
    269      1.1  christos */
    270      1.1  christos #endif
    271      1.1  christos 
    272  1.1.1.2  christos /* GCC and clang have various useful declarations that can be made with
    273  1.1.1.2  christos    the '__attribute__' syntax.  All of the ways we use this do fine if
    274  1.1.1.2  christos    they are omitted for compilers that don't understand it.  */
    275  1.1.1.2  christos #if !(defined __GNUC__ || defined __clang__)
    276      1.1  christos # define __attribute__(xyz)	/* Ignore */
    277      1.1  christos #endif
    278      1.1  christos 
    279      1.1  christos /* At some point during the gcc 2.96 development the `malloc' attribute
    280      1.1  christos    for functions was introduced.  We don't want to use it unconditionally
    281      1.1  christos    (although this would be possible) since it generates warnings.  */
    282  1.1.1.2  christos #if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__malloc__)
    283      1.1  christos # define __attribute_malloc__ __attribute__ ((__malloc__))
    284      1.1  christos #else
    285      1.1  christos # define __attribute_malloc__ /* Ignore */
    286      1.1  christos #endif
    287      1.1  christos 
    288      1.1  christos /* Tell the compiler which arguments to an allocation function
    289      1.1  christos    indicate the size of the allocation.  */
    290      1.1  christos #if __GNUC_PREREQ (4, 3)
    291      1.1  christos # define __attribute_alloc_size__(params) \
    292      1.1  christos   __attribute__ ((__alloc_size__ params))
    293      1.1  christos #else
    294      1.1  christos # define __attribute_alloc_size__(params) /* Ignore.  */
    295      1.1  christos #endif
    296      1.1  christos 
    297  1.1.1.2  christos /* Tell the compiler which argument to an allocation function
    298  1.1.1.2  christos    indicates the alignment of the allocation.  */
    299  1.1.1.2  christos #if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__alloc_align__)
    300  1.1.1.2  christos # define __attribute_alloc_align__(param) \
    301  1.1.1.2  christos   __attribute__ ((__alloc_align__ param))
    302  1.1.1.2  christos #else
    303  1.1.1.2  christos # define __attribute_alloc_align__(param) /* Ignore.  */
    304  1.1.1.2  christos #endif
    305  1.1.1.2  christos 
    306      1.1  christos /* At some point during the gcc 2.96 development the `pure' attribute
    307      1.1  christos    for functions was introduced.  We don't want to use it unconditionally
    308      1.1  christos    (although this would be possible) since it generates warnings.  */
    309  1.1.1.2  christos #if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__pure__)
    310      1.1  christos # define __attribute_pure__ __attribute__ ((__pure__))
    311      1.1  christos #else
    312      1.1  christos # define __attribute_pure__ /* Ignore */
    313      1.1  christos #endif
    314      1.1  christos 
    315      1.1  christos /* This declaration tells the compiler that the value is constant.  */
    316  1.1.1.2  christos #if __GNUC_PREREQ (2,5) || __glibc_has_attribute (__const__)
    317      1.1  christos # define __attribute_const__ __attribute__ ((__const__))
    318      1.1  christos #else
    319      1.1  christos # define __attribute_const__ /* Ignore */
    320      1.1  christos #endif
    321      1.1  christos 
    322  1.1.1.2  christos #if __GNUC_PREREQ (2,7) || __glibc_has_attribute (__unused__)
    323  1.1.1.2  christos # define __attribute_maybe_unused__ __attribute__ ((__unused__))
    324  1.1.1.2  christos #else
    325  1.1.1.2  christos # define __attribute_maybe_unused__ /* Ignore */
    326  1.1.1.2  christos #endif
    327  1.1.1.2  christos 
    328      1.1  christos /* At some point during the gcc 3.1 development the `used' attribute
    329      1.1  christos    for functions was introduced.  We don't want to use it unconditionally
    330      1.1  christos    (although this would be possible) since it generates warnings.  */
    331  1.1.1.2  christos #if __GNUC_PREREQ (3,1) || __glibc_has_attribute (__used__)
    332      1.1  christos # define __attribute_used__ __attribute__ ((__used__))
    333      1.1  christos # define __attribute_noinline__ __attribute__ ((__noinline__))
    334      1.1  christos #else
    335      1.1  christos # define __attribute_used__ __attribute__ ((__unused__))
    336      1.1  christos # define __attribute_noinline__ /* Ignore */
    337      1.1  christos #endif
    338      1.1  christos 
    339      1.1  christos /* Since version 3.2, gcc allows marking deprecated functions.  */
    340  1.1.1.2  christos #if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__deprecated__)
    341      1.1  christos # define __attribute_deprecated__ __attribute__ ((__deprecated__))
    342      1.1  christos #else
    343      1.1  christos # define __attribute_deprecated__ /* Ignore */
    344      1.1  christos #endif
    345      1.1  christos 
    346      1.1  christos /* Since version 4.5, gcc also allows one to specify the message printed
    347      1.1  christos    when a deprecated function is used.  clang claims to be gcc 4.2, but
    348      1.1  christos    may also support this feature.  */
    349  1.1.1.2  christos #if __GNUC_PREREQ (4,5) \
    350  1.1.1.2  christos     || __glibc_has_extension (__attribute_deprecated_with_message__)
    351      1.1  christos # define __attribute_deprecated_msg__(msg) \
    352      1.1  christos 	 __attribute__ ((__deprecated__ (msg)))
    353      1.1  christos #else
    354      1.1  christos # define __attribute_deprecated_msg__(msg) __attribute_deprecated__
    355      1.1  christos #endif
    356      1.1  christos 
    357      1.1  christos /* At some point during the gcc 2.8 development the `format_arg' attribute
    358      1.1  christos    for functions was introduced.  We don't want to use it unconditionally
    359      1.1  christos    (although this would be possible) since it generates warnings.
    360      1.1  christos    If several `format_arg' attributes are given for the same function, in
    361      1.1  christos    gcc-3.0 and older, all but the last one are ignored.  In newer gccs,
    362      1.1  christos    all designated arguments are considered.  */
    363  1.1.1.2  christos #if __GNUC_PREREQ (2,8) || __glibc_has_attribute (__format_arg__)
    364      1.1  christos # define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
    365      1.1  christos #else
    366      1.1  christos # define __attribute_format_arg__(x) /* Ignore */
    367      1.1  christos #endif
    368      1.1  christos 
    369      1.1  christos /* At some point during the gcc 2.97 development the `strfmon' format
    370      1.1  christos    attribute for functions was introduced.  We don't want to use it
    371      1.1  christos    unconditionally (although this would be possible) since it
    372      1.1  christos    generates warnings.  */
    373  1.1.1.2  christos #if __GNUC_PREREQ (2,97) || __glibc_has_attribute (__format__)
    374      1.1  christos # define __attribute_format_strfmon__(a,b) \
    375      1.1  christos   __attribute__ ((__format__ (__strfmon__, a, b)))
    376      1.1  christos #else
    377      1.1  christos # define __attribute_format_strfmon__(a,b) /* Ignore */
    378      1.1  christos #endif
    379      1.1  christos 
    380      1.1  christos /* The nonnull function attribute marks pointer parameters that
    381  1.1.1.2  christos    must not be NULL.  This has the name __nonnull in glibc,
    382  1.1.1.2  christos    and __attribute_nonnull__ in files shared with Gnulib to avoid
    383  1.1.1.2  christos    collision with a different __nonnull in DragonFlyBSD 5.9.  */
    384  1.1.1.2  christos #ifndef __attribute_nonnull__
    385  1.1.1.2  christos # if __GNUC_PREREQ (3,3) || __glibc_has_attribute (__nonnull__)
    386  1.1.1.2  christos #  define __attribute_nonnull__(params) __attribute__ ((__nonnull__ params))
    387  1.1.1.2  christos # else
    388  1.1.1.2  christos #  define __attribute_nonnull__(params)
    389  1.1.1.2  christos # endif
    390  1.1.1.2  christos #endif
    391      1.1  christos #ifndef __nonnull
    392  1.1.1.2  christos # define __nonnull(params) __attribute_nonnull__ (params)
    393  1.1.1.2  christos #endif
    394  1.1.1.2  christos 
    395  1.1.1.2  christos /* The returns_nonnull function attribute marks the return type of the function
    396  1.1.1.2  christos    as always being non-null.  */
    397  1.1.1.2  christos #ifndef __returns_nonnull
    398  1.1.1.2  christos # if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__returns_nonnull__)
    399  1.1.1.2  christos # define __returns_nonnull __attribute__ ((__returns_nonnull__))
    400      1.1  christos # else
    401  1.1.1.2  christos # define __returns_nonnull
    402      1.1  christos # endif
    403      1.1  christos #endif
    404      1.1  christos 
    405      1.1  christos /* If fortification mode, we warn about unused results of certain
    406      1.1  christos    function calls which can lead to problems.  */
    407  1.1.1.2  christos #if __GNUC_PREREQ (3,4) || __glibc_has_attribute (__warn_unused_result__)
    408      1.1  christos # define __attribute_warn_unused_result__ \
    409      1.1  christos    __attribute__ ((__warn_unused_result__))
    410      1.1  christos # if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0
    411      1.1  christos #  define __wur __attribute_warn_unused_result__
    412      1.1  christos # endif
    413      1.1  christos #else
    414      1.1  christos # define __attribute_warn_unused_result__ /* empty */
    415      1.1  christos #endif
    416      1.1  christos #ifndef __wur
    417      1.1  christos # define __wur /* Ignore */
    418      1.1  christos #endif
    419      1.1  christos 
    420      1.1  christos /* Forces a function to be always inlined.  */
    421  1.1.1.2  christos #if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__always_inline__)
    422      1.1  christos /* The Linux kernel defines __always_inline in stddef.h (283d7573), and
    423      1.1  christos    it conflicts with this definition.  Therefore undefine it first to
    424      1.1  christos    allow either header to be included first.  */
    425      1.1  christos # undef __always_inline
    426      1.1  christos # define __always_inline __inline __attribute__ ((__always_inline__))
    427      1.1  christos #else
    428      1.1  christos # undef __always_inline
    429      1.1  christos # define __always_inline __inline
    430      1.1  christos #endif
    431      1.1  christos 
    432      1.1  christos /* Associate error messages with the source location of the call site rather
    433      1.1  christos    than with the source location inside the function.  */
    434  1.1.1.2  christos #if __GNUC_PREREQ (4,3) || __glibc_has_attribute (__artificial__)
    435      1.1  christos # define __attribute_artificial__ __attribute__ ((__artificial__))
    436      1.1  christos #else
    437      1.1  christos # define __attribute_artificial__ /* Ignore */
    438      1.1  christos #endif
    439      1.1  christos 
    440      1.1  christos /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
    441      1.1  christos    inline semantics, unless -fgnu89-inline is used.  Using __GNUC_STDC_INLINE__
    442      1.1  christos    or __GNUC_GNU_INLINE is not a good enough check for gcc because gcc versions
    443      1.1  christos    older than 4.3 may define these macros and still not guarantee GNU inlining
    444      1.1  christos    semantics.
    445      1.1  christos 
    446      1.1  christos    clang++ identifies itself as gcc-4.2, but has support for GNU inlining
    447      1.1  christos    semantics, that can be checked for by using the __GNUC_STDC_INLINE_ and
    448      1.1  christos    __GNUC_GNU_INLINE__ macro definitions.  */
    449      1.1  christos #if (!defined __cplusplus || __GNUC_PREREQ (4,3) \
    450      1.1  christos      || (defined __clang__ && (defined __GNUC_STDC_INLINE__ \
    451      1.1  christos 			       || defined __GNUC_GNU_INLINE__)))
    452      1.1  christos # if defined __GNUC_STDC_INLINE__ || defined __cplusplus
    453      1.1  christos #  define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
    454      1.1  christos #  define __extern_always_inline \
    455      1.1  christos   extern __always_inline __attribute__ ((__gnu_inline__))
    456      1.1  christos # else
    457      1.1  christos #  define __extern_inline extern __inline
    458      1.1  christos #  define __extern_always_inline extern __always_inline
    459      1.1  christos # endif
    460      1.1  christos #endif
    461      1.1  christos 
    462      1.1  christos #ifdef __extern_always_inline
    463      1.1  christos # define __fortify_function __extern_always_inline __attribute_artificial__
    464      1.1  christos #endif
    465      1.1  christos 
    466      1.1  christos /* GCC 4.3 and above allow passing all anonymous arguments of an
    467      1.1  christos    __extern_always_inline function to some other vararg function.  */
    468      1.1  christos #if __GNUC_PREREQ (4,3)
    469      1.1  christos # define __va_arg_pack() __builtin_va_arg_pack ()
    470      1.1  christos # define __va_arg_pack_len() __builtin_va_arg_pack_len ()
    471      1.1  christos #endif
    472      1.1  christos 
    473      1.1  christos /* It is possible to compile containing GCC extensions even if GCC is
    474      1.1  christos    run in pedantic mode if the uses are carefully marked using the
    475      1.1  christos    `__extension__' keyword.  But this is not generally available before
    476      1.1  christos    version 2.8.  */
    477  1.1.1.2  christos #if !(__GNUC_PREREQ (2,8) || defined __clang__)
    478      1.1  christos # define __extension__		/* Ignore */
    479      1.1  christos #endif
    480      1.1  christos 
    481  1.1.1.2  christos /* __restrict is known in EGCS 1.2 and above, and in clang.
    482  1.1.1.2  christos    It works also in C++ mode (outside of arrays), but only when spelled
    483  1.1.1.2  christos    as '__restrict', not 'restrict'.  */
    484  1.1.1.2  christos #if !(__GNUC_PREREQ (2,92) || __clang_major__ >= 3)
    485      1.1  christos # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
    486      1.1  christos #  define __restrict	restrict
    487      1.1  christos # else
    488      1.1  christos #  define __restrict	/* Ignore */
    489      1.1  christos # endif
    490      1.1  christos #endif
    491      1.1  christos 
    492      1.1  christos /* ISO C99 also allows to declare arrays as non-overlapping.  The syntax is
    493      1.1  christos      array_name[restrict]
    494  1.1.1.2  christos    GCC 3.1 and clang support this.
    495  1.1.1.2  christos    This syntax is not usable in C++ mode.  */
    496  1.1.1.2  christos #if (__GNUC_PREREQ (3,1) || __clang_major__ >= 3) && !defined __cplusplus
    497      1.1  christos # define __restrict_arr	__restrict
    498      1.1  christos #else
    499      1.1  christos # ifdef __GNUC__
    500      1.1  christos #  define __restrict_arr	/* Not supported in old GCC.  */
    501      1.1  christos # else
    502      1.1  christos #  if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
    503      1.1  christos #   define __restrict_arr	restrict
    504      1.1  christos #  else
    505      1.1  christos /* Some other non-C99 compiler.  */
    506      1.1  christos #   define __restrict_arr	/* Not supported.  */
    507      1.1  christos #  endif
    508      1.1  christos # endif
    509      1.1  christos #endif
    510      1.1  christos 
    511  1.1.1.2  christos #if (__GNUC__ >= 3) || __glibc_has_builtin (__builtin_expect)
    512      1.1  christos # define __glibc_unlikely(cond)	__builtin_expect ((cond), 0)
    513      1.1  christos # define __glibc_likely(cond)	__builtin_expect ((cond), 1)
    514      1.1  christos #else
    515      1.1  christos # define __glibc_unlikely(cond)	(cond)
    516      1.1  christos # define __glibc_likely(cond)	(cond)
    517      1.1  christos #endif
    518      1.1  christos 
    519      1.1  christos #if (!defined _Noreturn \
    520      1.1  christos      && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
    521  1.1.1.2  christos      &&  !(__GNUC_PREREQ (4,7) \
    522  1.1.1.2  christos            || (3 < __clang_major__ + (5 <= __clang_minor__))))
    523      1.1  christos # if __GNUC_PREREQ (2,8)
    524      1.1  christos #  define _Noreturn __attribute__ ((__noreturn__))
    525      1.1  christos # else
    526      1.1  christos #  define _Noreturn
    527      1.1  christos # endif
    528      1.1  christos #endif
    529      1.1  christos 
    530      1.1  christos #if __GNUC_PREREQ (8, 0)
    531      1.1  christos /* Describes a char array whose address can safely be passed as the first
    532      1.1  christos    argument to strncpy and strncat, as the char array is not necessarily
    533      1.1  christos    a NUL-terminated string.  */
    534      1.1  christos # define __attribute_nonstring__ __attribute__ ((__nonstring__))
    535      1.1  christos #else
    536      1.1  christos # define __attribute_nonstring__
    537      1.1  christos #endif
    538      1.1  christos 
    539  1.1.1.2  christos /* Undefine (also defined in libc-symbols.h).  */
    540  1.1.1.2  christos #undef __attribute_copy__
    541  1.1.1.2  christos #if __GNUC_PREREQ (9, 0)
    542  1.1.1.2  christos /* Copies attributes from the declaration or type referenced by
    543  1.1.1.2  christos    the argument.  */
    544  1.1.1.2  christos # define __attribute_copy__(arg) __attribute__ ((__copy__ (arg)))
    545  1.1.1.2  christos #else
    546  1.1.1.2  christos # define __attribute_copy__(arg)
    547  1.1.1.2  christos #endif
    548  1.1.1.2  christos 
    549      1.1  christos #if (!defined _Static_assert && !defined __cplusplus \
    550      1.1  christos      && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
    551  1.1.1.2  christos      && (!(__GNUC_PREREQ (4, 6) || __clang_major__ >= 4) \
    552  1.1.1.2  christos          || defined __STRICT_ANSI__))
    553      1.1  christos # define _Static_assert(expr, diagnostic) \
    554      1.1  christos     extern int (*__Static_assert_function (void)) \
    555      1.1  christos       [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
    556      1.1  christos #endif
    557      1.1  christos 
    558  1.1.1.2  christos /* Gnulib avoids including these, as they don't work on non-glibc or
    559  1.1.1.2  christos    older glibc platforms.  */
    560  1.1.1.2  christos #ifndef __GNULIB_CDEFS
    561      1.1  christos # include <bits/wordsize.h>
    562      1.1  christos # include <bits/long-double.h>
    563      1.1  christos #endif
    564      1.1  christos 
    565  1.1.1.2  christos #if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
    566  1.1.1.2  christos # ifdef __REDIRECT
    567  1.1.1.2  christos 
    568  1.1.1.2  christos /* Alias name defined automatically.  */
    569  1.1.1.2  christos #  define __LDBL_REDIR(name, proto) ... unused__ldbl_redir
    570  1.1.1.2  christos #  define __LDBL_REDIR_DECL(name) \
    571  1.1.1.2  christos   extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128"));
    572  1.1.1.2  christos 
    573  1.1.1.2  christos /* Alias name defined automatically, with leading underscores.  */
    574  1.1.1.2  christos #  define __LDBL_REDIR2_DECL(name) \
    575  1.1.1.2  christos   extern __typeof (__##name) __##name \
    576  1.1.1.2  christos     __asm (__ASMNAME ("__" #name "ieee128"));
    577  1.1.1.2  christos 
    578  1.1.1.2  christos /* Alias name defined manually.  */
    579  1.1.1.2  christos #  define __LDBL_REDIR1(name, proto, alias) ... unused__ldbl_redir1
    580  1.1.1.2  christos #  define __LDBL_REDIR1_DECL(name, alias) \
    581  1.1.1.2  christos   extern __typeof (name) name __asm (__ASMNAME (#alias));
    582  1.1.1.2  christos 
    583  1.1.1.2  christos #  define __LDBL_REDIR1_NTH(name, proto, alias) \
    584  1.1.1.2  christos   __REDIRECT_NTH (name, proto, alias)
    585  1.1.1.2  christos #  define __REDIRECT_NTH_LDBL(name, proto, alias) \
    586  1.1.1.2  christos   __LDBL_REDIR1_NTH (name, proto, __##alias##ieee128)
    587  1.1.1.2  christos 
    588  1.1.1.2  christos /* Unused.  */
    589  1.1.1.2  christos #  define __REDIRECT_LDBL(name, proto, alias) ... unused__redirect_ldbl
    590  1.1.1.2  christos #  define __LDBL_REDIR_NTH(name, proto) ... unused__ldbl_redir_nth
    591  1.1.1.2  christos 
    592  1.1.1.2  christos # else
    593  1.1.1.2  christos _Static_assert (0, "IEEE 128-bits long double requires redirection on this platform");
    594  1.1.1.2  christos # endif
    595  1.1.1.2  christos #elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
    596      1.1  christos # define __LDBL_COMPAT 1
    597      1.1  christos # ifdef __REDIRECT
    598      1.1  christos #  define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias)
    599      1.1  christos #  define __LDBL_REDIR(name, proto) \
    600      1.1  christos   __LDBL_REDIR1 (name, proto, __nldbl_##name)
    601      1.1  christos #  define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias)
    602      1.1  christos #  define __LDBL_REDIR_NTH(name, proto) \
    603      1.1  christos   __LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
    604  1.1.1.2  christos #  define __LDBL_REDIR2_DECL(name) \
    605  1.1.1.2  christos   extern __typeof (__##name) __##name __asm (__ASMNAME ("__nldbl___" #name));
    606      1.1  christos #  define __LDBL_REDIR1_DECL(name, alias) \
    607      1.1  christos   extern __typeof (name) name __asm (__ASMNAME (#alias));
    608      1.1  christos #  define __LDBL_REDIR_DECL(name) \
    609      1.1  christos   extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
    610      1.1  christos #  define __REDIRECT_LDBL(name, proto, alias) \
    611      1.1  christos   __LDBL_REDIR1 (name, proto, __nldbl_##alias)
    612      1.1  christos #  define __REDIRECT_NTH_LDBL(name, proto, alias) \
    613      1.1  christos   __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
    614      1.1  christos # endif
    615      1.1  christos #endif
    616  1.1.1.2  christos #if (!defined __LDBL_COMPAT && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0) \
    617  1.1.1.2  christos     || !defined __REDIRECT
    618      1.1  christos # define __LDBL_REDIR1(name, proto, alias) name proto
    619      1.1  christos # define __LDBL_REDIR(name, proto) name proto
    620      1.1  christos # define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
    621      1.1  christos # define __LDBL_REDIR_NTH(name, proto) name proto __THROW
    622  1.1.1.2  christos # define __LDBL_REDIR2_DECL(name)
    623      1.1  christos # define __LDBL_REDIR_DECL(name)
    624      1.1  christos # ifdef __REDIRECT
    625      1.1  christos #  define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
    626      1.1  christos #  define __REDIRECT_NTH_LDBL(name, proto, alias) \
    627      1.1  christos   __REDIRECT_NTH (name, proto, alias)
    628      1.1  christos # endif
    629      1.1  christos #endif
    630      1.1  christos 
    631      1.1  christos /* __glibc_macro_warning (MESSAGE) issues warning MESSAGE.  This is
    632      1.1  christos    intended for use in preprocessor macros.
    633      1.1  christos 
    634      1.1  christos    Note: MESSAGE must be a _single_ string; concatenation of string
    635      1.1  christos    literals is not supported.  */
    636      1.1  christos #if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5)
    637      1.1  christos # define __glibc_macro_warning1(message) _Pragma (#message)
    638      1.1  christos # define __glibc_macro_warning(message) \
    639      1.1  christos   __glibc_macro_warning1 (GCC warning message)
    640      1.1  christos #else
    641      1.1  christos # define __glibc_macro_warning(msg)
    642      1.1  christos #endif
    643      1.1  christos 
    644      1.1  christos /* Generic selection (ISO C11) is a C-only feature, available in GCC
    645      1.1  christos    since version 4.9.  Previous versions do not provide generic
    646      1.1  christos    selection, even though they might set __STDC_VERSION__ to 201112L,
    647      1.1  christos    when in -std=c11 mode.  Thus, we must check for !defined __GNUC__
    648      1.1  christos    when testing __STDC_VERSION__ for generic selection support.
    649      1.1  christos    On the other hand, Clang also defines __GNUC__, so a clang-specific
    650      1.1  christos    check is required to enable the use of generic selection.  */
    651      1.1  christos #if !defined __cplusplus \
    652      1.1  christos     && (__GNUC_PREREQ (4, 9) \
    653  1.1.1.2  christos 	|| __glibc_has_extension (c_generic_selections) \
    654      1.1  christos 	|| (!defined __GNUC__ && defined __STDC_VERSION__ \
    655      1.1  christos 	    && __STDC_VERSION__ >= 201112L))
    656      1.1  christos # define __HAVE_GENERIC_SELECTION 1
    657      1.1  christos #else
    658      1.1  christos # define __HAVE_GENERIC_SELECTION 0
    659      1.1  christos #endif
    660      1.1  christos 
    661  1.1.1.2  christos #if __GNUC_PREREQ (10, 0)
    662  1.1.1.2  christos /* Designates a 1-based positional argument ref-index of pointer type
    663  1.1.1.2  christos    that can be used to access size-index elements of the pointed-to
    664  1.1.1.2  christos    array according to access mode, or at least one element when
    665  1.1.1.2  christos    size-index is not provided:
    666  1.1.1.2  christos      access (access-mode, <ref-index> [, <size-index>])  */
    667  1.1.1.2  christos #  define __attr_access(x) __attribute__ ((__access__ x))
    668  1.1.1.2  christos /* For _FORTIFY_SOURCE == 3 we use __builtin_dynamic_object_size, which may
    669  1.1.1.2  christos    use the access attribute to get object sizes from function definition
    670  1.1.1.2  christos    arguments, so we can't use them on functions we fortify.  Drop the object
    671  1.1.1.2  christos    size hints for such functions.  */
    672  1.1.1.2  christos #  if __USE_FORTIFY_LEVEL == 3
    673  1.1.1.2  christos #    define __fortified_attr_access(a, o, s) __attribute__ ((__access__ (a, o)))
    674  1.1.1.2  christos #  else
    675  1.1.1.2  christos #    define __fortified_attr_access(a, o, s) __attr_access ((a, o, s))
    676  1.1.1.2  christos #  endif
    677  1.1.1.2  christos #  if __GNUC_PREREQ (11, 0)
    678  1.1.1.2  christos #    define __attr_access_none(argno) __attribute__ ((__access__ (__none__, argno)))
    679  1.1.1.2  christos #  else
    680  1.1.1.2  christos #    define __attr_access_none(argno)
    681  1.1.1.2  christos #  endif
    682  1.1.1.2  christos #else
    683  1.1.1.2  christos #  define __fortified_attr_access(a, o, s)
    684  1.1.1.2  christos #  define __attr_access(x)
    685  1.1.1.2  christos #  define __attr_access_none(argno)
    686  1.1.1.2  christos #endif
    687  1.1.1.2  christos 
    688  1.1.1.2  christos #if __GNUC_PREREQ (11, 0)
    689  1.1.1.2  christos /* Designates dealloc as a function to call to deallocate objects
    690  1.1.1.2  christos    allocated by the declared function.  */
    691  1.1.1.2  christos # define __attr_dealloc(dealloc, argno) \
    692  1.1.1.2  christos     __attribute__ ((__malloc__ (dealloc, argno)))
    693  1.1.1.2  christos # define __attr_dealloc_free __attr_dealloc (__builtin_free, 1)
    694  1.1.1.2  christos #else
    695  1.1.1.2  christos # define __attr_dealloc(dealloc, argno)
    696  1.1.1.2  christos # define __attr_dealloc_free
    697  1.1.1.2  christos #endif
    698  1.1.1.2  christos 
    699  1.1.1.2  christos /* Specify that a function such as setjmp or vfork may return
    700  1.1.1.2  christos    twice.  */
    701  1.1.1.2  christos #if __GNUC_PREREQ (4, 1)
    702  1.1.1.2  christos # define __attribute_returns_twice__ __attribute__ ((__returns_twice__))
    703  1.1.1.2  christos #else
    704  1.1.1.2  christos # define __attribute_returns_twice__ /* Ignore.  */
    705  1.1.1.2  christos #endif
    706  1.1.1.2  christos 
    707      1.1  christos #endif	 /* sys/cdefs.h */
    708