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
13 # include <sys/types.h>
15 # include "gcc_compat.h"
17 # define ARRAY_SIZE(a_) (sizeof(a_) / sizeof((a_)[0]) + MUST_BE_ARRAY(a_))
19 # define ARRSZ_PAIR(a_) a_, ARRAY_SIZE(a_)
21 # define STRINGIFY(...) #__VA_ARGS__
22 # define STRINGIFY_VAL(...) STRINGIFY(__VA_ARGS__)
25 # define MAX(a, b) (((a) > (b)) ? (a) : (b))
28 # define MIN(a, b) (((a) < (b)) ? (a) : (b))
30 # define CLAMP(val, min, max) MIN(MAX(min, val), max)
33 # define ROUNDUP_DIV(val_, div_) (((val_) + (div_) - 1) / (div_))
37 # define ROUNDUP(val_, div_) (ROUNDUP_DIV((val_), (div_)) * (div_))
41 # define offsetofend(type_, member_) \
42 (offsetof(type_, member_) + sizeof(((type_ *)0)->member_))
46 # define cast_ptr(type_, var_) \
47 ((type_) (uintptr_t) (const volatile void *) (var_))
52 * Return a pointer to a structure that contains the provided variable.
54 * @param ptr_ Pointer to data that is a field of the container structure.
55 * @param struct_ Type of the container structure.
56 * @param member_ Name of the member field.
57 * @return Pointer to the container structure.
59 # define containerof(ptr_, struct_, member_) \
61 (const volatile char *) (ptr_) - offsetof(struct_, member_))
65 is_filled(const char *ptr, char fill, size_t size)
74 # define IS_ARRAY_ZERO(arr_) \
75 is_filled((const char *) (arr_), 0, sizeof(arr_) + MUST_BE_ARRAY(arr_))
78 # define BIT(x_) (1U << (x_))
81 # define FLAG(name_) name_ = BIT(name_##_BIT)
83 #endif /* !STRACE_MACROS_H */