aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-12-19 08:44:10 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-12-19 08:44:10 +0000
commit2a4d7addaea5883213841b3ab6372346e70ccef3 (patch)
treee9af08a15b94271a16eeb922aa124be55e21606a
parent22d1f712aebd6ec4473a98d87d4d64f2f525943f (diff)
downloadobf-2a4d7addaea5883213841b3ab6372346e70ccef3.tar.gz
obf-2a4d7addaea5883213841b3ab6372346e70ccef3.tar.bz2
obf-2a4d7addaea5883213841b3ab6372346e70ccef3.zip
Delete buffer stretchy functions
A buffer should be a strictly sized array representing a file in memory. No dynamic size functions.
-rw-r--r--lib.c42
-rw-r--r--lib.h6
2 files changed, 1 insertions, 47 deletions
diff --git a/lib.c b/lib.c
index 0c3f4f9..4ef6506 100644
--- a/lib.c
+++ b/lib.c
@@ -13,7 +13,6 @@ buffer_t *buffer_init_str(const char *name, const char *str, size_t str_size)
buffer_t *buf = malloc(sizeof(*buf) + str_size + 1);
buf->name = name;
buf->size = str_size;
- buf->capacity = str_size;
if (str)
{
memcpy(buf->data, str, str_size);
@@ -22,47 +21,6 @@ buffer_t *buffer_init_str(const char *name, const char *str, size_t str_size)
return buf;
}
-bool buffer_ensure(buffer_t **buffer, u64 expected)
-{
- if (!buffer)
- return false;
- else if (!*buffer)
- {
- *buffer = buffer_init_str(NULL, NULL, expected);
- }
- else if (buffer[0]->capacity <= expected)
- {
- buffer[0]->capacity = MAX(buffer[0]->capacity * 2, expected);
- *buffer = realloc(*buffer, sizeof(**buffer) + buffer[0]->capacity);
- }
- return true;
-}
-
-bool buffer_ensure_relative(buffer_t **buffer, u64 expected)
-{
- return buffer_ensure(buffer,
- buffer && *buffer ? buffer[0]->size + expected : 0);
-}
-
-bool buffer_append(buffer_t **buffer, u8 datum)
-{
- bool ret = buffer_ensure_relative(buffer, 1);
- if (ret)
- buffer[0]->data[buffer[0]->size++] = datum;
- return ret;
-}
-
-bool buffer_append_bytes(buffer_t **buffer, u8 *data, u64 size)
-{
- bool ret = buffer_ensure_relative(buffer, size);
- if (ret)
- {
- memcpy(buffer[0]->data + buffer[0]->size, data, size);
- buffer[0]->size += size;
- }
- return ret;
-}
-
void print_error(const char *handle, size_t row, size_t column,
const char *reason)
{
diff --git a/lib.h b/lib.h
index 19196f4..bf6181b 100644
--- a/lib.h
+++ b/lib.h
@@ -29,13 +29,9 @@ void print_error(const char *handle, size_t row, size_t column,
typedef struct Buffer
{
const char *name;
- u64 size, capacity;
+ u64 size;
u8 data[];
} buffer_t;
buffer_t *buffer_init_str(const char *name, const char *str, size_t str_size);
-bool buffer_ensure(buffer_t **buffer, u64 expected);
-bool buffer_ensure_relative(buffer_t **buffer, u64 expected);
-bool buffer_append(buffer_t **buffer, u8 datum);
-bool buffer_append_bytes(buffer_t **buffer, u8 *data, u64 size);
#endif