diff options
author | zlago | 2024-10-02 20:39:39 +0200 |
---|---|---|
committer | zlago | 2024-10-02 20:39:39 +0200 |
commit | ce13cd4be59c0415877571d92aaea3fd0d5a7e49 (patch) | |
tree | 6e078cf505d2b1a0362ec6cbd28f30ba814e2a90 /utl/json2map/common.c | |
parent | 89f441dd4b07a507aedd1a61791e30b2ce337a34 (diff) |
entities
Diffstat (limited to 'utl/json2map/common.c')
-rw-r--r-- | utl/json2map/common.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/utl/json2map/common.c b/utl/json2map/common.c index c401fc1..8c2c4c2 100644 --- a/utl/json2map/common.c +++ b/utl/json2map/common.c @@ -1,7 +1,28 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "common.h" +struct blob blob_new(void) { + return (struct blob) {.data = NULL, .size = 0}; +} + +void blob_append(struct blob *const blob, void const *const data, size_t const size) { + char *new = realloc(blob->data, blob->size + size); + if (new == NULL) { + abort(); + } + memcpy(new + blob->size, data, size); + blob->data = new; + blob->size += size; +} + +void blob_free(struct blob *const blob) { + free(blob->data); + blob->data = NULL; + blob->size = 0; +} + struct blob load_file(char const *const name) { const size_t START_SIZE = 8192; FILE *file = fopen(name, "rb"); |