1 #ifndef UTIL_READFILE_H
2 #define UTIL_READFILE_H
3 
4 #include <errno.h>
5 #include <sys/stat.h>
6 #include <sys/types.h>
7 #include "macros.h"
8 #include "string-view.h"
9 
10 ssize_t stat_read_file(const char *filename, char **bufp, struct stat *st);
11 
12 // Returns size of file or -1 on error.
13 // For empty files *bufp is NULL, otherwise *bufp is NUL-terminated.
read_file(const char * filename,char ** bufp)14 static inline ssize_t read_file(const char *filename, char **bufp)
15 {
16     struct stat st;
17     return stat_read_file(filename, bufp, &st);
18 }
19 
20 char *buf_next_line(char *buf, size_t *posp, size_t size);
21 StringView buf_slice_next_line(const char *buf, size_t *posp, size_t size);
22 
23 #endif
24