Home | History | Annotate | Line # | Download | only in import
      1      1.1  christos /* A substitute for POSIX 2008 <stddef.h>, for platforms that have issues.
      2      1.1  christos 
      3  1.1.1.2  christos    Copyright (C) 2009-2022 Free Software Foundation, Inc.
      4      1.1  christos 
      5  1.1.1.2  christos    This file is free software: you can redistribute it and/or modify
      6  1.1.1.2  christos    it under the terms of the GNU Lesser General Public License as
      7  1.1.1.2  christos    published by the Free Software Foundation; either version 2.1 of the
      8  1.1.1.2  christos    License, or (at your option) any later version.
      9      1.1  christos 
     10  1.1.1.2  christos    This file 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
     13  1.1.1.2  christos    GNU 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 License
     16  1.1.1.2  christos    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
     17      1.1  christos 
     18      1.1  christos /* Written by Eric Blake.  */
     19      1.1  christos 
     20      1.1  christos /*
     21      1.1  christos  * POSIX 2008 <stddef.h> for platforms that have issues.
     22      1.1  christos  * <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html>
     23      1.1  christos  */
     24      1.1  christos 
     25      1.1  christos #if __GNUC__ >= 3
     26      1.1  christos @PRAGMA_SYSTEM_HEADER@
     27      1.1  christos #endif
     28      1.1  christos @PRAGMA_COLUMNS@
     29      1.1  christos 
     30      1.1  christos #if defined __need_wchar_t || defined __need_size_t  \
     31      1.1  christos   || defined __need_ptrdiff_t || defined __need_NULL \
     32      1.1  christos   || defined __need_wint_t
     33      1.1  christos /* Special invocation convention inside gcc header files.  In
     34      1.1  christos    particular, gcc provides a version of <stddef.h> that blindly
     35      1.1  christos    redefines NULL even when __need_wint_t was defined, even though
     36      1.1  christos    wint_t is not normally provided by <stddef.h>.  Hence, we must
     37      1.1  christos    remember if special invocation has ever been used to obtain wint_t,
     38      1.1  christos    in which case we need to clean up NULL yet again.  */
     39      1.1  christos 
     40      1.1  christos # if !(defined _@GUARD_PREFIX@_STDDEF_H && defined _GL_STDDEF_WINT_T)
     41      1.1  christos #  ifdef __need_wint_t
     42      1.1  christos #   define _GL_STDDEF_WINT_T
     43      1.1  christos #  endif
     44      1.1  christos #  @INCLUDE_NEXT@ @NEXT_STDDEF_H@
     45  1.1.1.2  christos    /* On TinyCC, make sure that the macros that indicate the special invocation
     46  1.1.1.2  christos       convention get undefined.  */
     47  1.1.1.2  christos #  undef __need_wchar_t
     48  1.1.1.2  christos #  undef __need_size_t
     49  1.1.1.2  christos #  undef __need_ptrdiff_t
     50  1.1.1.2  christos #  undef __need_NULL
     51  1.1.1.2  christos #  undef __need_wint_t
     52      1.1  christos # endif
     53      1.1  christos 
     54      1.1  christos #else
     55      1.1  christos /* Normal invocation convention.  */
     56      1.1  christos 
     57      1.1  christos # ifndef _@GUARD_PREFIX@_STDDEF_H
     58      1.1  christos 
     59  1.1.1.2  christos /* On AIX 7.2, with xlc in 64-bit mode, <stddef.h> defines max_align_t to a
     60  1.1.1.2  christos    type with alignment 4, but 'long' has alignment 8.  */
     61  1.1.1.2  christos #  if defined _AIX && defined __LP64__
     62  1.1.1.2  christos #   if !GNULIB_defined_max_align_t
     63  1.1.1.2  christos #    ifdef _MAX_ALIGN_T
     64  1.1.1.2  christos /* /usr/include/stddef.h has already defined max_align_t.  Override it.  */
     65  1.1.1.2  christos typedef long rpl_max_align_t;
     66  1.1.1.2  christos #     define max_align_t rpl_max_align_t
     67  1.1.1.2  christos #    else
     68  1.1.1.2  christos /* Prevent /usr/include/stddef.h from defining max_align_t.  */
     69  1.1.1.2  christos typedef long max_align_t;
     70  1.1.1.2  christos #     define _MAX_ALIGN_T
     71  1.1.1.2  christos #    endif
     72  1.1.1.2  christos #    define GNULIB_defined_max_align_t 1
     73  1.1.1.2  christos #   endif
     74  1.1.1.2  christos #  endif
     75  1.1.1.2  christos 
     76      1.1  christos /* The include_next requires a split double-inclusion guard.  */
     77      1.1  christos 
     78      1.1  christos #  @INCLUDE_NEXT@ @NEXT_STDDEF_H@
     79      1.1  christos 
     80      1.1  christos /* On NetBSD 5.0, the definition of NULL lacks proper parentheses.  */
     81      1.1  christos #  if (@REPLACE_NULL@ \
     82      1.1  christos        && (!defined _@GUARD_PREFIX@_STDDEF_H || defined _GL_STDDEF_WINT_T))
     83      1.1  christos #   undef NULL
     84      1.1  christos #   ifdef __cplusplus
     85      1.1  christos    /* ISO C++ says that the macro NULL must expand to an integer constant
     86      1.1  christos       expression, hence '((void *) 0)' is not allowed in C++.  */
     87      1.1  christos #    if __GNUG__ >= 3
     88      1.1  christos     /* GNU C++ has a __null macro that behaves like an integer ('int' or
     89      1.1  christos        'long') but has the same size as a pointer.  Use that, to avoid
     90      1.1  christos        warnings.  */
     91      1.1  christos #     define NULL __null
     92      1.1  christos #    else
     93      1.1  christos #     define NULL 0L
     94      1.1  christos #    endif
     95      1.1  christos #   else
     96      1.1  christos #    define NULL ((void *) 0)
     97      1.1  christos #   endif
     98      1.1  christos #  endif
     99      1.1  christos 
    100      1.1  christos #  ifndef _@GUARD_PREFIX@_STDDEF_H
    101      1.1  christos #   define _@GUARD_PREFIX@_STDDEF_H
    102      1.1  christos 
    103      1.1  christos /* Some platforms lack wchar_t.  */
    104      1.1  christos #if !@HAVE_WCHAR_T@
    105      1.1  christos # define wchar_t int
    106      1.1  christos #endif
    107      1.1  christos 
    108      1.1  christos /* Some platforms lack max_align_t.  The check for _GCC_MAX_ALIGN_T is
    109      1.1  christos    a hack in case the configure-time test was done with g++ even though
    110      1.1  christos    we are currently compiling with gcc.
    111      1.1  christos    On MSVC, max_align_t is defined only in C++ mode, after <cstddef> was
    112      1.1  christos    included.  Its definition is good since it has an alignment of 8 (on x86
    113  1.1.1.2  christos    and x86_64).
    114  1.1.1.2  christos    Similarly on OS/2 kLIBC.  */
    115  1.1.1.2  christos #if (defined _MSC_VER || (defined __KLIBC__ && !defined __LIBCN__)) \
    116  1.1.1.2  christos     && defined __cplusplus
    117      1.1  christos # include <cstddef>
    118      1.1  christos #else
    119  1.1.1.2  christos # if ! (@HAVE_MAX_ALIGN_T@ || (defined _GCC_MAX_ALIGN_T && !defined __clang__))
    120      1.1  christos #  if !GNULIB_defined_max_align_t
    121      1.1  christos /* On the x86, the maximum storage alignment of double, long, etc. is 4,
    122      1.1  christos    but GCC's C11 ABI for x86 says that max_align_t has an alignment of 8,
    123      1.1  christos    and the C11 standard allows this.  Work around this problem by
    124      1.1  christos    using __alignof__ (which returns 8 for double) rather than _Alignof
    125      1.1  christos    (which returns 4), and align each union member accordingly.  */
    126  1.1.1.2  christos #   if defined __GNUC__ || (__clang_major__ >= 4)
    127      1.1  christos #    define _GL_STDDEF_ALIGNAS(type) \
    128      1.1  christos        __attribute__ ((__aligned__ (__alignof__ (type))))
    129      1.1  christos #   else
    130      1.1  christos #    define _GL_STDDEF_ALIGNAS(type) /* */
    131      1.1  christos #   endif
    132      1.1  christos typedef union
    133      1.1  christos {
    134      1.1  christos   char *__p _GL_STDDEF_ALIGNAS (char *);
    135      1.1  christos   double __d _GL_STDDEF_ALIGNAS (double);
    136      1.1  christos   long double __ld _GL_STDDEF_ALIGNAS (long double);
    137      1.1  christos   long int __i _GL_STDDEF_ALIGNAS (long int);
    138      1.1  christos } rpl_max_align_t;
    139      1.1  christos #   define max_align_t rpl_max_align_t
    140      1.1  christos #   define GNULIB_defined_max_align_t 1
    141      1.1  christos #  endif
    142      1.1  christos # endif
    143      1.1  christos #endif
    144      1.1  christos 
    145      1.1  christos #  endif /* _@GUARD_PREFIX@_STDDEF_H */
    146      1.1  christos # endif /* _@GUARD_PREFIX@_STDDEF_H */
    147      1.1  christos #endif /* __need_XXX */
    148