From 0782fdab9d99a1d6a198245c681c46db65a71808 Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Thu, 6 Feb 2025 03:17:08 -0500 Subject: add strio.h with read_whole_file() --- strio.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 strio.h diff --git a/strio.h b/strio.h new file mode 100644 index 0000000..4dbdd74 --- /dev/null +++ b/strio.h @@ -0,0 +1,25 @@ +#ifndef STRIO_H +#define STRIO_H + +/* optional I/O routines for strings */ + +#include "str.h" + +string read_whole_file(FILE *f); + +#ifdef STDWRM_STR_IMPL + +string read_whole_file(FILE *f) { + char chunk[256]; + string s; + DA_INIT(s); + while (!feof(f)) { + size_t n = fread(chunk, 1, sizeof chunk, f); + DA_PUSH_MULT(s, chunk, n); + } + DA_PUSH(s, 0); + return s; +} + +#endif +#endif -- cgit 1.4.1-2-gfad0