#ifndef STRIO_H #define STRIO_H /* optional I/O routines for strings */ #include "str.h" #ifndef STRIO_CHUNK_SIZE #define STRIO_CHUNK_SIZE 256 #endif string read_whole_file(FILE *f); #ifdef STR_IMPL #include string read_whole_file(FILE *f) { string s; DA_INIT_SIZE(s, STRIO_CHUNK_SIZE); while (!feof(f)) { char *buf = &s[DA_LEN(s)]; size_t n = fread(buf, 1, STRIO_CHUNK_SIZE, f); DA_FIT(s, DA_LEN(s) + n); DA_LEN(s) += n; } DA_PUSH(s, 0); return s; } #endif #endif