mirror of
https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git
synced 2024-11-14 22:43:44 +08:00
1d0117f86a
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/118 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
33 lines
752 B
C
33 lines
752 B
C
#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, \
|
|
}
|