X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fmake-file.h;h=19d33ebe76bfc070b0f28aed4c11bc61c89b7111;hb=fd0c595927a23ea0373551a1eed4570388ea0fc5;hp=ce56758ee87d2b9abc9d80f57e0958a636d30e5c;hpb=43b1296aafe7582e7dbe6c2b6a8b478d7d9b0fcf;p=pspp-builds.git diff --git a/src/data/make-file.h b/src/data/make-file.h index ce56758e..19d33ebe 100644 --- a/src/data/make-file.h +++ b/src/data/make-file.h @@ -29,4 +29,31 @@ int make_temp_file (int *fd, char **file_name); responsible for freeing *FILE_NAME. */ int make_unique_file_stream (FILE **fp, char **file_name) ; + +/* Prepares to atomically replace a (potentially) existing file + by a new file, by creating a temporary file with the given + PERMISSIONS bits in the same directory as *FILE_NAME. + + Special files are an exception: they are not atomically + replaced but simply opened for writing. + + If successful, stores the temporary file's name in *TMP_NAME + and a stream for it opened according to MODE (which should be + "w" or "wb") in *FP. Returns a ticket that can be used to + commit or abort the file replacement. If neither action has + yet been taken, program termination via signal will cause + *TMP_FILE to be unlinked. + + The caller is responsible for closing *FP, but *TMP_NAME is + owned by the callee. */ +struct replace_file *replace_file_start (const char *file_name, + const char *mode, mode_t permissions, + FILE **fp, char **tmp_name); + +/* Commits or aborts the replacement of a (potentially) existing + file by a new file, using the ticket returned by + replace_file_start. Returns success. */ +bool replace_file_commit (struct replace_file *); +bool replace_file_abort (struct replace_file *); + #endif /* make-file.h */