]> git.ipfire.org Git - thirdparty/util-linux.git/blob - include/buffer.h
include: add DragonFlyBSD GPT partition types
[thirdparty/util-linux.git] / include / buffer.h
1 /*
2 * No copyright is claimed. This code is in the public domain; do with
3 * it what you wish.
4 */
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;
16
17 char *encoded; /* encoded data (from mbs_safe_encode_to_buffer)) */
18 size_t encoded_sz; /* space allocated for encoded data */
19
20 char **ptrs; /* saved pointers */
21 size_t nptrs; /* number of saved pointers */
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);
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
40 size_t ul_buffer_get_bufsiz(struct ul_buffer *buf);
41
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);
45 size_t ul_buffer_get_safe_pointer_width(struct ul_buffer *buf, unsigned short ptr_idx);
46
47
48 #endif /* UTIL_LINUX_BUFFER */