blob: 0395dd78240318627ddcc6a03d0aef983b420c28 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#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 <stdio.h>
string read_whole_file(FILE *f) {
string s;
DA_INIT_SZ(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
|