File: sizeof.h

package info (click to toggle)
shadow 1%3A4.19.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 67,276 kB
  • sloc: sh: 44,701; ansic: 34,184; xml: 12,350; exp: 3,691; makefile: 1,656; python: 1,409; perl: 120; sed: 16
file content (33 lines) | stat: -rw-r--r-- 782 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-FileCopyrightText: 2022-2025, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


#ifndef SHADOW_INCLUDE_LIBMISC_SIZEOF_H_
#define SHADOW_INCLUDE_LIBMISC_SIZEOF_H_


#include "config.h"

#include <limits.h>
#if __has_include(<stdcountof.h>)
# include <stdcountof.h>
#endif
#include <sys/types.h>


#define typeas(T)            typeof((T){0})

#define ssizeof(x)           ({(ssize_t){sizeof(x)};})
#define memberof(T, member)  ((T){}.member)
#define WIDTHOF(x)           (sizeof(x) * CHAR_BIT)

#if !defined(countof)
# define countof(a)          (sizeof(a) / sizeof((a)[0]))
#endif

// sizeof_a - sizeof array
#define sizeof_a(a)          (countof(a) * sizeof((a)[0]))
#define STRLEN(s)            (countof("" s "") - 1)


#endif  // include guard