fbuf: New data structure for buffered file I/O.
[pspp] / src / data / make-file.h
index 3861f35109af866978b5938d0bbc34389e6c059b..d908db336681c9b4179c126abe601f7b1c34f126 100644 (file)
 #include <stdio.h>
 #include <sys/types.h>
 
-/* 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.
+struct file_handle;
+
+/* Prepares to atomically replace a (potentially) existing file by a new file,
+   by creating a temporary file with the given PERMISSIONS bits.
 
    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);
+   If successful, returns a ticket that can be used to commit or abort the file
+   replacement.  If neither action is taken, program termination via signal
+   will abort.  Depending on the function, stores a file descriptor in *FD or a
+   stream in *FP for the newly opened file.  The descriptor or stream is opened
+   for writing a binary file if BINARY is true, otherwise a text file (this
+   disctinction only matters on Windows).
+
+   On error, returns NULL and stores NULL in *FP or -1 in *FD.
+
+   The caller is responsible for closing *FP or *FD. */
+
+struct replace_file *replace_file_start (const struct file_handle *fh,
+                                         bool binary, mode_t permissions,
+                                         FILE **fp);
+struct replace_file *replace_file_start_fd (const struct file_handle *fh,
+                                            bool binary,
+                                            mode_t permissions, int *fd);
 
 /* Commits or aborts the replacement of a (potentially) existing
    file by a new file, using the ticket returned by