diff options
author | K.A.A. <kaa@disroot.org> | 2024-07-10 03:05:54 -0700 |
---|---|---|
committer | K.A.A. <kaa@disroot.org> | 2024-07-10 03:05:54 -0700 |
commit | 01bcfa89fc3b3b754e40a979a1fa983ba49fbae2 (patch) | |
tree | 50b39889b0bfd938fb336e005d6ea81aadbc7535 /d.h |
Diffstat (limited to 'd.h')
-rwxr-xr-x | d.h | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -0,0 +1,24 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +enum { + bufsize = 0x20, +}; + +static char * +getall(FILE *in) +{ + char buf[bufsize]; + static char *contents = NULL; + int len = 0, read; + while ((read = fread(buf, 1, bufsize, in)) > 0) { + len += read; + contents = realloc(contents, len); + memmove(&contents[len-read], buf, read); + } + contents = realloc(contents, ++len); + contents[len-1] = '\0'; + + return contents; +} |