File: scratchbuf.h

package info (click to toggle)
kmod 26-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,784 kB
  • sloc: ansic: 15,682; xml: 1,879; makefile: 617; sh: 303; python: 7
file content (31 lines) | stat: -rw-r--r-- 620 bytes parent folder | download | duplicates (5)
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
#pragma once

#include <stdbool.h>
#include <stdlib.h>

#include <shared/macro.h>

/*
 * Buffer abstract data type
 */
struct scratchbuf {
	char *bytes;
	size_t size;
	bool need_free;
};

void scratchbuf_init(struct scratchbuf *buf, char *stackbuf, size_t size);
int scratchbuf_alloc(struct scratchbuf *buf, size_t sz);
void scratchbuf_release(struct scratchbuf *buf);

/* Return a C string */
static inline char *scratchbuf_str(struct scratchbuf *buf)
{
	return buf->bytes;
}

#define SCRATCHBUF_INITIALIZER(buf_) {			\
	.bytes = buf_,					\
	.size = sizeof(buf_) + _array_size_chk(buf_),	\
	.need_free = false,				\
}