diff options
author | WormHeamer | 2025-02-06 03:17:08 -0500 |
---|---|---|
committer | WormHeamer | 2025-02-06 03:17:08 -0500 |
commit | 0782fdab9d99a1d6a198245c681c46db65a71808 (patch) | |
tree | eb67430abb34c5a00e412b5a8d42dfb443e62ac0 | |
parent | 628a2a17b64097c884630e1cc02e1e10e8b97020 (diff) |
add strio.h with read_whole_file()
-rw-r--r-- | strio.h | 25 |
1 files changed, 25 insertions, 0 deletions
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 |