Coverage Report

Created: 2026-07-30 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfuse/lib/util.h
Line
Count
Source
1
#ifndef FUSE_UTIL_H_
2
#define FUSE_UTIL_H_
3
4
#include <stdint.h>
5
#include <stdbool.h>
6
7
#define max(x, y) ((x) > (y) ? (x) : (y))
8
#define min(x, y) ((x) < (y) ? (x) : (y))
9
10
#define ROUND_UP(val, round_to) (((val) + (round_to - 1)) & ~(round_to - 1))
11
12
#define likely(x) __builtin_expect(!!(x), 1)
13
#define unlikely(x) __builtin_expect(!!(x), 0)
14
15
struct fuse_conn_info;
16
17
int libfuse_strtol(const char *str, long *res);
18
void fuse_set_thread_name(const char *name);
19
20
/**
21
 * Return the low bits of a number
22
 */
23
static inline uint32_t fuse_lower_32_bits(uint64_t nr)
24
0
{
25
0
  return (uint32_t)(nr & 0xffffffff);
26
0
}
27
28
/**
29
 * Return the high bits of a number
30
 */
31
static inline uint64_t fuse_higher_32_bits(uint64_t nr)
32
0
{
33
0
  return nr & ~0xffffffffULL;
34
0
}
35
36
#ifndef FUSE_VAR_UNUSED
37
#define FUSE_VAR_UNUSED __attribute__((__unused__))
38
#endif
39
40
#define container_of(ptr, type, member)                      \
41
  ({                                                   \
42
    unsigned long __mptr = (unsigned long)(ptr); \
43
    ((type *)(__mptr - offsetof(type, member))); \
44
  })
45
46
#if __has_attribute(__fallthrough__)
47
#define fallthrough __attribute__((__fallthrough__))
48
#else
49
#define fallthrough do {} while (0)
50
#endif
51
52
static inline uint64_t round_up(uint64_t b, unsigned int align)
53
0
{
54
0
  unsigned int m;
55
0
56
0
  if (align == 0)
57
0
    return b;
58
0
  m = b % align;
59
0
  if (m)
60
0
    b += align - m;
61
0
  return b;
62
0
}
63
64
static inline uint64_t round_down(uint64_t b, unsigned int align)
65
0
{
66
0
  unsigned int m;
67
0
68
0
  if (align == 0)
69
0
    return b;
70
0
  m = b % align;
71
0
  return b - m;
72
0
}
73
74
static inline uint64_t howmany(uint64_t b, unsigned int align)
75
0
{
76
0
  unsigned int m;
77
0
78
0
  if (align == 0)
79
0
    return b;
80
0
  m = (b % align) ? 1 : 0;
81
0
  return (b / align) + m;
82
0
}
83
84
#endif /* FUSE_UTIL_H_ */