about summary refs log tree commit diff stats
path: root/dragonfly/util.h
blob: d08783f6532628fab7380643b29e092d9a3e84d7 (plain) (blame)
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
34
35
#define RB_FOREACH(x, name, head)                                       \
        for ((x) = RB_MIN(name, head);                                  \
             (x) != NULL;                                               \
             (x) = name##_RB_NEXT(x))

#define RB_FOREACH_SAFE(x, name, head, y)                               \
        for ((x) = RB_MIN(name, head);                                  \
            ((x) != NULL) && ((y) = name##_RB_NEXT(x), 1);              \
             (x) = (y))

#define RB_FOREACH_REVERSE(x, name, head)                               \
        for ((x) = RB_MAX(name, head);                                  \
             (x) != NULL;                                               \
             (x) = name##_RB_PREV(x))

#define RB_FOREACH_REVERSE_SAFE(x, name, head, y)                       \
        for ((x) = RB_MAX(name, head);                                  \
            ((x) != NULL) && ((y) = name##_RB_PREV(x), 1);              \
             (x) = (y))


#ifndef TAILQ_END
#define TAILQ_END(head)                 NULL
#endif

#ifndef TAILQ_FOREACH_SAFE
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)                      \
        for ((var) = TAILQ_FIRST(head);                                 \
            (var) != TAILQ_END(head) &&                                 \
            ((tvar) = TAILQ_NEXT(var, field), 1);                       \
            (var) = (tvar))
#endif

#define FMT_SCALED_STRSIZE      7       /* minus sign, 4 digits, suffix, null byte */
int     fmt_scaled(long long number, char *result);