Blame lib/flexmember.h

Packit Service a2489d
/* Sizes of structs with flexible array members.
Packit Service a2489d
Packit Service a2489d
   Copyright 2016-2018 Free Software Foundation, Inc.
Packit Service a2489d
Packit Service a2489d
   This file is part of the GNU C Library.
Packit Service a2489d
Packit Service a2489d
   The GNU C Library is free software; you can redistribute it and/or
Packit Service a2489d
   modify it under the terms of the GNU General Public
Packit Service a2489d
   License as published by the Free Software Foundation; either
Packit Service a2489d
   version 3 of the License, or (at your option) any later version.
Packit Service a2489d
Packit Service a2489d
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service a2489d
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service a2489d
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service a2489d
   General Public License for more details.
Packit Service a2489d
Packit Service a2489d
   You should have received a copy of the GNU General Public
Packit Service a2489d
   License along with the GNU C Library; if not, see
Packit Service a2489d
   <https://www.gnu.org/licenses/>.
Packit Service a2489d
Packit Service a2489d
   Written by Paul Eggert.  */
Packit Service a2489d
Packit Service a2489d
#include <stddef.h>
Packit Service a2489d
Packit Service a2489d
/* Nonzero multiple of alignment of TYPE, suitable for FLEXSIZEOF below.
Packit Service a2489d
   On older platforms without _Alignof, use a pessimistic bound that is
Packit Service a2489d
   safe in practice even if FLEXIBLE_ARRAY_MEMBER is 1.
Packit Service a2489d
   On newer platforms, use _Alignof to get a tighter bound.  */
Packit Service a2489d
Packit Service a2489d
#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112
Packit Service a2489d
# define FLEXALIGNOF(type) (sizeof (type) & ~ (sizeof (type) - 1))
Packit Service a2489d
#else
Packit Service a2489d
# define FLEXALIGNOF(type) _Alignof (type)
Packit Service a2489d
#endif
Packit Service a2489d
Packit Service a2489d
/* Upper bound on the size of a struct of type TYPE with a flexible
Packit Service a2489d
   array member named MEMBER that is followed by N bytes of other data.
Packit Service a2489d
   This is not simply sizeof (TYPE) + N, since it may require
Packit Service a2489d
   alignment on unusually picky C11 platforms, and
Packit Service a2489d
   FLEXIBLE_ARRAY_MEMBER may be 1 on pre-C11 platforms.
Packit Service a2489d
   Yield a value less than N if and only if arithmetic overflow occurs.  */
Packit Service a2489d
Packit Service a2489d
#define FLEXSIZEOF(type, member, n) \
Packit Service a2489d
   ((offsetof (type, member) + FLEXALIGNOF (type) - 1 + (n)) \
Packit Service a2489d
    & ~ (FLEXALIGNOF (type) - 1))