Open SCAP Library: _sexp-rawptr.h Source File

Open SCAP Library

_sexp-rawptr.h
1 #ifndef SEXP_RAWPTR
2 #define SEXP_RAWPTR
3
4 #include <stdint.h>
5
6 static inline void *SEXP_rawptr_mask(void *ptr, uintptr_t mask)
7 {
8 return (void *)((uintptr_t)(ptr) & mask);
9 }
10
11 #define SEXP_rawptr_maskT(T, ptr, mask) ((T *)SEXP_rawptr_mask((void *)(ptr), mask))
12
13 static inline void *SEXP_rawptr_merge(void *ptr, uintptr_t bits)
14 {
15 return (void *)(((uintptr_t)(ptr) | bits));
16 }
17
18 #define SEXP_rawptr_mergeT(T, ptr, bits) ((T *)SEXP_rawptr_merge((void *)(ptr), bits))
19
20 static inline void *SEXP_rawptr_safemerge(void *ptr, uintptr_t bits, uintptr_t mask)
21 {
22 return (void *)(((uintptr_t)SEXP_rawptr_mask(ptr, mask))|(~mask & bits));
23 }
24
25 #define SEXP_rawptr_safemergeT(T, ptr, bits, mask) ((T *)SEXP_rawptr_safemerge((void *)(ptr), bits, mask))
26
27 static inline bool SEXP_rawptr_bit(void *ptr, int n)
28 {
29 return (bool)(((uintptr_t)(ptr)) & (1 << n));
30 }
31
32 static inline uintptr_t SEXP_rawptr_bitmask(void *ptr, uintptr_t mask)
33 {
34 return ((uintptr_t)(ptr)) & mask;
35 }
36
37 #endif /* SEXP_RAWPTR */