2 * Copyright (c) 2001-2019 The strace developers.
5 * SPDX-License-Identifier: LGPL-2.1-or-later
8 #ifndef STRACE_MACROS_H
9 # define STRACE_MACROS_H
12 # include <sys/types.h>
14 # include "gcc_compat.h"
16 # define ARRAY_SIZE(a_) (sizeof(a_) / sizeof((a_)[0]) + MUST_BE_ARRAY(a_))
18 # define ARRSZ_PAIR(a_) a_, ARRAY_SIZE(a_)
20 # define STRINGIFY(...) #__VA_ARGS__
21 # define STRINGIFY_VAL(...) STRINGIFY(__VA_ARGS__)
24 # define MAX(a, b) (((a) > (b)) ? (a) : (b))
27 # define MIN(a, b) (((a) < (b)) ? (a) : (b))
29 # define CLAMP(val, min, max) MIN(MAX(min, val), max)
32 # define ROUNDUP_DIV(val_, div_) (((val_) + (div_) - 1) / (div_))
36 # define ROUNDUP(val_, div_) (ROUNDUP_DIV((val_), (div_)) * (div_))
40 # define offsetofend(type_, member_) \
41 (offsetof(type_, member_) + sizeof(((type_ *)0)->member_))
45 # define cast_ptr(type_, var_) \
46 ((type_) (uintptr_t) (const volatile void *) (var_))
51 * Return a pointer to a structure that contains the provided variable.
53 * @param ptr_ Pointer to data that is a field of the container structure.
54 * @param struct_ Type of the container structure.
55 * @param member_ Name of the member field.
56 * @return Pointer to the container structure.
58 # define containerof(ptr_, struct_, member_) \
60 (const volatile char *) (ptr_) - offsetof(struct_, member_))
64 is_filled(const char *ptr, char fill, size_t size)
73 # define IS_ARRAY_ZERO(arr_) \
74 is_filled((const char *) (arr_), 0, sizeof(arr_) + MUST_BE_ARRAY(arr_))
76 #endif /* !STRACE_MACROS_H */