29 #include <common/util.h>
31 #define __XC(a, b) OSCAP_CONCAT(a, b)
32 #define _sym(n) __XC(__XC(_sym, __LINE__), n)
34 typedef uint32_t spb_flags_t;
36 #define SPB_FLAG_FREE 0x00000001
37 #define SPB_FLAG_JOIN 0x00000002
38 #define SPB_FLAG_FILE 0x00000004
40 typedef uint64_t spb_size_t;
41 #define SPB_SZ_FMT "%"PRIo64
55 #define SPB_DEFAULT_BALLOC 32
56 #define SPB_BALLOC_HIGHTRESH 512
57 #define SPB_BALLOC_ADD 32
67 spb_t *spb_new (
void *buffer,
size_t buflen, uint32_t balloc);
69 void spb_free (
spb_t *spb, spb_flags_t flags);
77 uint32_t spb_bindex (
spb_t *spb, spb_size_t index);
83 spb_size_t spb_size (
spb_t *spb);
93 #define spb_iterate_oct(spb, start, end, name) while(0)
95 #define spb_iterate(spb, start, name, icode) \
97 spb_size_t _sym(istart) = (start); \
98 spb_t *_sym(ispb) = (spb); \
99 uint32_t _sym(idx) = spb_bindex(_sym(ispb), _sym(istart)); \
100 size_t _sym(l_off) = (size_t)(_sym(idx) > 0 ? start - _sym(ispb)->buffer[_sym(idx) - 1].gend - 1 : start); \
102 for (; _sym(idx) < _sym(ispb)->btotal; ++_sym(idx)) { \
103 register size_t _sym(l); \
104 register uint8_t *_sym(b); \
106 _sym(l) = (size_t)(_sym(idx) > 0 ? \
107 _sym(ispb)->buffer[_sym(idx)].gend - _sym(ispb)->buffer[_sym(idx) - 1].gend : \
108 _sym(ispb)->buffer[_sym(idx)].gend + 1) - _sym(l_off); \
109 _sym(b) = ((uint8_t *)(_sym(ispb)->buffer[_sym(idx)].base)) + _sym(l_off); \
111 for (; _sym(l) > 0; --_sym(l), ++_sym(b)) { \
129 int spb_add (
spb_t *spb,
void *buffer,
size_t buflen);
138 int spb_pick (
spb_t *spb, spb_size_t start, spb_size_t size,
void *dst);
150 int spb_pick_raw (
spb_t *spb, uint32_t bindex, spb_size_t start, spb_size_t size,
void *dst);
164 int spb_pick_cb (
spb_t *spb, spb_size_t start, spb_size_t size,
void *cb (
void *,
void *,
size_t),
void *cbarg);
166 spb_size_t spb_drop_head (
spb_t *spb, spb_size_t size, spb_flags_t flags);
168 uint8_t spb_octet (
spb_t *spb, spb_size_t idx);
169 const uint8_t *spb_direct (
spb_t *spb, spb_size_t start, spb_size_t size);