Blame src/gl/flexmember.h

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