File: buffer.h

package info (click to toggle)
util-linux 2.41.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 92,868 kB
  • sloc: ansic: 179,124; sh: 22,714; yacc: 1,284; makefile: 525; xml: 422; python: 316; lex: 89; ruby: 75; csh: 37; exp: 19; sed: 16; perl: 15; sql: 9
file content (49 lines) | stat: -rw-r--r-- 1,903 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * No copyright is claimed.  This code is in the public domain; do with
 * it what you wish.
 */
#ifndef UTIL_LINUX_BUFFER
#define UTIL_LINUX_BUFFER

#include <stddef.h>

struct ul_buffer {
	char *begin;		/* begin of the data */
	char *end;		/* current end of data */

	size_t sz;		/* allocated space for data */
	size_t chunksize;

	char *encoded;		/* encoded data (from mbs_safe_encode_to_buffer)) */
	size_t encoded_sz;	/* space allocated for encoded data */

	char **ptrs;		/* saved pointers */
	size_t nptrs;		/* number of saved pointers */
};

#define UL_INIT_BUFFER { .begin = NULL }

void ul_buffer_reset_data(struct ul_buffer *buf);
void ul_buffer_free_data(struct ul_buffer *buf);
int ul_buffer_is_empty(struct ul_buffer *buf);
void ul_buffer_set_chunksize(struct ul_buffer *buf, size_t sz);
void ul_buffer_refer_string(struct ul_buffer *buf, char *str);
int ul_buffer_alloc_data(struct ul_buffer *buf, size_t sz);
int ul_buffer_append_data(struct ul_buffer *buf, const char *data, size_t sz);
int ul_buffer_append_string(struct ul_buffer *buf, const char *str);
int ul_buffer_append_ntimes(struct ul_buffer *buf, size_t n, const char *str);
int ul_buffer_set_data(struct ul_buffer *buf, const char *data, size_t sz);

char *ul_buffer_get_data(struct ul_buffer *buf,  size_t *sz, size_t *width);
char *ul_buffer_get_string(struct ul_buffer *buf,  size_t *sz, size_t *width);
char *ul_buffer_get_safe_data(struct ul_buffer *buf, size_t *sz, size_t *width, const char *safechars);

size_t ul_buffer_get_bufsiz(struct ul_buffer *buf);

int ul_buffer_save_pointer(struct ul_buffer *buf, unsigned short ptr_idx);
char *ul_buffer_get_pointer(struct ul_buffer *buf, unsigned short  ptr_idx);
size_t ul_buffer_get_pointer_length(struct ul_buffer *buf, unsigned short ptr_idx);
size_t ul_buffer_get_safe_pointer_width(struct ul_buffer *buf, unsigned short ptr_idx);


#endif /* UTIL_LINUX_BUFFER */