Blame lib/flexmember.h

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