]> granicus.if.org Git - strace/blob - macros.h
net: fix off-by-one error in sorted xlat lookup
[strace] / macros.h
1 /*
2  * Copyright (c) 2001-2018 The strace developers.
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: LGPL-2.1-or-later
6  */
7
8 #ifndef STRACE_MACROS_H
9 #define STRACE_MACROS_H
10
11 #include <stdbool.h>
12 #include <sys/types.h>
13
14 #include "gcc_compat.h"
15
16 #define ARRAY_SIZE(a_)  (sizeof(a_) / sizeof((a_)[0]) + MUST_BE_ARRAY(a_))
17
18 #define ARRSZ_PAIR(a_) a_, ARRAY_SIZE(a_)
19
20 #define STRINGIFY(...)          #__VA_ARGS__
21 #define STRINGIFY_VAL(...)      STRINGIFY(__VA_ARGS__)
22
23 #ifndef MAX
24 # define MAX(a, b)              (((a) > (b)) ? (a) : (b))
25 #endif
26 #ifndef MIN
27 # define MIN(a, b)              (((a) < (b)) ? (a) : (b))
28 #endif
29 #define CLAMP(val, min, max)    MIN(MAX(min, val), max)
30
31 #ifndef ROUNDUP
32 # define ROUNDUP(val_, div_) ((((val_) + (div_) - 1) / (div_)) * (div_))
33 #endif
34
35 #ifndef offsetofend
36 # define offsetofend(type_, member_)    \
37         (offsetof(type_, member_) + sizeof(((type_ *)0)->member_))
38 #endif
39
40 static inline bool
41 is_filled(const char *ptr, char fill, size_t size)
42 {
43         while (size--)
44                 if (*ptr++ != fill)
45                         return false;
46
47         return true;
48 }
49
50 #define IS_ARRAY_ZERO(arr_)     \
51         is_filled((const char *) (arr_), 0, sizeof(arr_) + MUST_BE_ARRAY(arr_))
52
53 #endif /* !STRACE_MACROS_H */