File: strbuf.h

package info (click to toggle)
kmod 23-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,524 kB
  • ctags: 1,705
  • sloc: ansic: 14,537; xml: 1,848; makefile: 593; sh: 214; python: 7
file content (30 lines) | stat: -rw-r--r-- 696 bytes parent folder | download | duplicates (4)
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
#pragma once

#include <stdbool.h>

/*
 * Buffer abstract data type
 */
struct strbuf {
	char *bytes;
	unsigned size;
	unsigned used;
};

void strbuf_init(struct strbuf *buf);
void strbuf_release(struct strbuf *buf);
void strbuf_clear(struct strbuf *buf);

/* Destroy buffer and return a copy as a C string */
char *strbuf_steal(struct strbuf *buf);

/*
 * Return a C string owned by the buffer invalidated if the buffer is
 * changed).
 */
const char *strbuf_str(struct strbuf *buf);

bool strbuf_pushchar(struct strbuf *buf, char ch);
unsigned strbuf_pushchars(struct strbuf *buf, const char *str);
void strbuf_popchar(struct strbuf *buf);
void strbuf_popchars(struct strbuf *buf, unsigned n);