]>
Commit | Line | Data |
---|---|---|
faeb1b64 KZ |
1 | /* |
2 | * No copyright is claimed. This code is in the public domain; do with | |
3 | * it what you wish. | |
4 | */ | |
0a993981 KZ |
5 | #ifndef UTIL_LINUX_BUFFER |
6 | #define UTIL_LINUX_BUFFER | |
7 | ||
8 | #include "c.h" | |
9 | ||
10 | struct ul_buffer { | |
11 | char *begin; /* begin of the data */ | |
12 | char *end; /* current end of data */ | |
13 | ||
14 | size_t sz; /* allocated space for data */ | |
15 | size_t chunksize; | |
f55be401 | 16 | |
9ea47344 KZ |
17 | char *encoded; /* encoded data (from mbs_safe_encode_to_buffer)) */ |
18 | size_t encoded_sz; /* space allocated for encoded data */ | |
19 | ||
f55be401 | 20 | char **ptrs; /* saved pointers */ |
0e85613e | 21 | size_t nptrs; /* number of saved pointers */ |
0a993981 KZ |
22 | }; |
23 | ||
24 | #define UL_INIT_BUFFER { .begin = NULL } | |
25 | ||
26 | void ul_buffer_reset_data(struct ul_buffer *buf); | |
27 | void ul_buffer_free_data(struct ul_buffer *buf); | |
28 | int ul_buffer_is_empty(struct ul_buffer *buf); | |
29 | void ul_buffer_set_chunksize(struct ul_buffer *buf, size_t sz); | |
30 | void ul_buffer_refer_string(struct ul_buffer *buf, char *str); | |
31 | int ul_buffer_alloc_data(struct ul_buffer *buf, size_t sz); | |
32 | int ul_buffer_append_data(struct ul_buffer *buf, const char *data, size_t sz); | |
33 | int ul_buffer_append_string(struct ul_buffer *buf, const char *str); | |
34 | int ul_buffer_append_ntimes(struct ul_buffer *buf, size_t n, const char *str); | |
35 | int ul_buffer_set_data(struct ul_buffer *buf, const char *data, size_t sz); | |
9ea47344 KZ |
36 | |
37 | char *ul_buffer_get_data(struct ul_buffer *buf, size_t *sz, size_t *width); | |
38 | char *ul_buffer_get_safe_data(struct ul_buffer *buf, size_t *sz, size_t *width, const char *safechars); | |
39 | ||
f60dc888 | 40 | size_t ul_buffer_get_bufsiz(struct ul_buffer *buf); |
0a993981 | 41 | |
f55be401 KZ |
42 | int ul_buffer_save_pointer(struct ul_buffer *buf, unsigned short ptr_idx); |
43 | char *ul_buffer_get_pointer(struct ul_buffer *buf, unsigned short ptr_idx); | |
44 | size_t ul_buffer_get_pointer_length(struct ul_buffer *buf, unsigned short ptr_idx); | |
9ea47344 | 45 | size_t ul_buffer_get_safe_pointer_width(struct ul_buffer *buf, unsigned short ptr_idx); |
f55be401 KZ |
46 | |
47 | ||
0a993981 | 48 | #endif /* UTIL_LINUX_BUFFER */ |