]> git.ipfire.org Git - thirdparty/util-linux.git/blame - include/buffer.h
Merge branch 'master' of https://github.com/breavyn/util-linux
[thirdparty/util-linux.git] / include / buffer.h
CommitLineData
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
10struct 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
26void ul_buffer_reset_data(struct ul_buffer *buf);
27void ul_buffer_free_data(struct ul_buffer *buf);
28int ul_buffer_is_empty(struct ul_buffer *buf);
29void ul_buffer_set_chunksize(struct ul_buffer *buf, size_t sz);
30void ul_buffer_refer_string(struct ul_buffer *buf, char *str);
31int ul_buffer_alloc_data(struct ul_buffer *buf, size_t sz);
32int ul_buffer_append_data(struct ul_buffer *buf, const char *data, size_t sz);
33int ul_buffer_append_string(struct ul_buffer *buf, const char *str);
34int ul_buffer_append_ntimes(struct ul_buffer *buf, size_t n, const char *str);
35int ul_buffer_set_data(struct ul_buffer *buf, const char *data, size_t sz);
9ea47344
KZ
36
37char *ul_buffer_get_data(struct ul_buffer *buf, size_t *sz, size_t *width);
38char *ul_buffer_get_safe_data(struct ul_buffer *buf, size_t *sz, size_t *width, const char *safechars);
39
f60dc888 40size_t ul_buffer_get_bufsiz(struct ul_buffer *buf);
0a993981 41
f55be401
KZ
42int ul_buffer_save_pointer(struct ul_buffer *buf, unsigned short ptr_idx);
43char *ul_buffer_get_pointer(struct ul_buffer *buf, unsigned short ptr_idx);
44size_t ul_buffer_get_pointer_length(struct ul_buffer *buf, unsigned short ptr_idx);
9ea47344 45size_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 */