diff options
author | bpc2003 <wpesfriendnva@gmail.com> | 2025-03-06 14:48:55 -0500 |
---|---|---|
committer | bpc2003 <wpesfriendnva@gmail.com> | 2025-03-06 14:48:55 -0500 |
commit | cf36cda36f8e91290f1d765f24c7933d4fadd837 (patch) | |
tree | 462df036f21dcd2634256b0637e620fac1dd3e63 /src/fileops.c | |
parent | 575b17b4126baa1025700107ae67e5729935189a (diff) |
Got started on readfile
Diffstat (limited to 'src/fileops.c')
-rw-r--r-- | src/fileops.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/fileops.c b/src/fileops.c new file mode 100644 index 0000000..ca5171d --- /dev/null +++ b/src/fileops.c @@ -0,0 +1,28 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> + +#include "include/fileops.h" + +uint8_t *readdb(char *filename) +{ + FILE *fp = fopen(filename, "rb"); + if (fp == NULL) + return NULL; + + int len = 10; + uint8_t *buf = calloc(len, sizeof(uint8_t)); + int c, i = 0; + while ((c = fgetc(fp)) != EOF) { + if (i >= len) { + len *= 2; + buf = realloc(buf, len * sizeof(uint8_t)); + memset(buf + i, 0, (len - i) * sizeof(uint8_t)); + } + buf[i++] = c; + } + + fclose(fp); + return buf; +} |