Blame lib/flexmember.h

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