From 01bcfa89fc3b3b754e40a979a1fa983ba49fbae2 Mon Sep 17 00:00:00 2001 From: "K.A.A." Date: Wed, 10 Jul 2024 03:05:54 -0700 Subject: Dynamic file read. --- d.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 d.h diff --git a/d.h b/d.h new file mode 100755 index 0000000..ddaeca2 --- /dev/null +++ b/d.h @@ -0,0 +1,24 @@ +#include +#include +#include + +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; +} -- cgit v1.2.3