Blame gnulib/lib/flexmember.h

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