Line |
Branch |
Exec |
Source |
1 |
|
|
#ifndef BLOCK_H |
2 |
|
|
#define BLOCK_H |
3 |
|
|
|
4 |
|
|
#include <stddef.h> |
5 |
|
|
#include "util/list.h" |
6 |
|
|
#include "util/macros.h" |
7 |
|
|
|
8 |
|
|
// Blocks always contain whole lines. |
9 |
|
|
// There's one zero-sized block for an empty file. |
10 |
|
|
// Otherwise zero-sized blocks are forbidden. |
11 |
|
|
typedef struct { |
12 |
|
|
ListHead node; |
13 |
|
|
unsigned char NONSTRING *data; |
14 |
|
|
size_t size; |
15 |
|
|
size_t alloc; |
16 |
|
|
size_t nl; |
17 |
|
|
} Block; |
18 |
|
|
|
19 |
|
|
#define block_for_each(block_, list_head_) \ |
20 |
|
|
for ( \ |
21 |
|
|
block_ = BLOCK((list_head_)->next); \ |
22 |
|
|
&block_->node != (list_head_); \ |
23 |
|
|
block_ = BLOCK(block_->node.next) \ |
24 |
|
|
) |
25 |
|
|
|
26 |
|
|
// NOLINTNEXTLINE(readability-identifier-naming) |
27 |
|
1650 |
static inline Block *BLOCK(ListHead *item) |
28 |
|
|
{ |
29 |
|
1650 |
static_assert(offsetof(Block, node) == 0); |
30 |
|
1650 |
return (Block*)item; |
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
Block *block_new(size_t alloc) RETURNS_NONNULL; |
34 |
|
|
void block_grow(Block *blk, size_t alloc) NONNULL_ARGS; |
35 |
|
|
void block_free(Block *blk) NONNULL_ARGS; |
36 |
|
|
|
37 |
|
|
#endif |
38 |
|
|
|