1 /* src/common/readwrite.h:
3 * Routines for reading and writing files.
9 #include <stdint.h> /* uint8_t, uint32_t */
10 #include <stdio.h> /* FILE */
14 /* Wrappers to fopen(), fclose(), fgets() and fwrite() from function called "f",
15 * calling exit_err() upon error with appropriate error messages.
17 extern FILE * try_fopen(char * path, char * mode, char * f);
18 extern void try_fclose(FILE * file, char * f);
19 extern void try_fwrite(void * ptr, size_t size, size_t nmemb, FILE * stream,
21 extern void try_fputc(uint8_t c, FILE * file, char * f);
23 /* Wrapper to calling fgetc() and fgets() from function "f". The return code is
24 * returned unless ferror() indicates an error (i.e. to signify an end of file,
25 * fgetc() may return an EOF and fgets() a NULL.
27 extern int try_fgetc(FILE * file, char * f);
28 extern char * try_fgets(char * line, int size, FILE * file, char * f);
30 /* Wrapper to successive call of fclose() from function called "f" on "file",
31 * then unlink() on file at path "p2" if it exists, then rename() from path "p1"
32 * to "p2". Used for handling atomic saving of files via temp files.
34 extern void try_fclose_unlink_rename(FILE * file, char * p1, char * p2,
37 /* Return largest line length from "file" the largest line length (including
40 extern uint32_t textfile_width(FILE * file);