X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/cards/%7B%7Bcard_id%7D%7D/form?a=blobdiff_plain;f=src%2Fcommon%2Freadwrite.h;h=eddd0e66e1875922f5bc7b15be06305080b07d73;hb=6ac951c41a091ffc723840894ddf1e774739511d;hp=d616a193a31f95f9982ea7242f97e041ee4b9d50;hpb=e1cdb7bd32c3622659a56a2ecc5c883fda0c92b7;p=plomrogue diff --git a/src/common/readwrite.h b/src/common/readwrite.h index d616a19..eddd0e6 100644 --- a/src/common/readwrite.h +++ b/src/common/readwrite.h @@ -22,17 +22,26 @@ extern void try_fputc(uint8_t c, FILE * file, char * f); /* Wrapper to calling fgetc() and fgets() from function "f". The return code is * returned unless ferror() indicates an error (i.e. to signify an end of file, - * fgetc() may return an EOF and fgets() a NULL. + * fgetc() may return an EOF and fgets() a NULL). try_fgetc() calls clearerr() + * on "file" before fgetc(), because some Unixes fgetc() remember old EOFs and + * only return those until explicitely cleared. */ extern int try_fgetc(FILE * file, char * f); extern char * try_fgets(char * line, int size, FILE * file, char * f); -/* Wrapper to successive call of fclose() from function called "f" on "file", - * then unlink() on file at path "p2" if it exists, then rename() from path "p1" - * to "p2". Used for handling atomic saving of files via temp files. +/* Write to "path_tmp" "path" + "_tmp" and return a new file at that "path_tmp" + * open for writing. "path_tmp" is malloc()'d, must be freed externally. +*/ +extern FILE * atomic_write_start(char * path, char ** path_tmp); + +/* Finish atomic writing started in atomic_write_start(). Wraps successive calls + * of fclose() on "file", then unlink() on file at path "path" if it exists, + * then rename() from "path_tmp" to "path", then free() on "path_tmp". */ -extern void try_fclose_unlink_rename(FILE * file, char * p1, char * p2, - char * f); +extern void atomic_write_finish(FILE * file, char * path, char * path_tmp); + +/* Check for temp file leftover of atomic writing of "path", abort if found. */ +extern void detect_atomic_leftover(char * path); /* Return largest line length from "file" (including newline chars). */ extern uint32_t textfile_width(FILE * file);