goto error;
/* Create the file on disk. */
- w->rf = replace_file_start (fh, "w", 0666,
- &w->file, NULL);
+ w->rf = replace_file_start (fh, "w", 0666, &w->file);
if (w->rf == NULL)
{
msg (ME, _("Error opening `%s' for writing as a system file: %s."),
#include <config.h>
#include "data/make-file.h"
+#include "libpspp/i18n.h"
#include <assert.h>
#include <errno.h>
struct replace_file *
replace_file_start (const struct file_handle *fh, const char *mode,
- mode_t permissions, FILE **fp, char **tmp_name)
+ mode_t permissions, FILE **fp)
{
static bool registered;
struct stat s;
rf = xmalloc (sizeof *rf);
rf->file_name = NULL;
rf->tmp_name = xstrdup (file_name);
- if (tmp_name != NULL)
- *tmp_name = rf->tmp_name;
return rf;
}
ll_push_head (&all_files, &rf->ll);
unblock_fatal_signals ();
- if (tmp_name != NULL)
- *tmp_name = rf->tmp_name;
-
return rf;
error:
unblock_fatal_signals ();
free_replace_file (rf);
*fp = NULL;
- if (tmp_name != NULL)
- *tmp_name = NULL;
errno = saved_errno;
return NULL;
}
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 in the same directory as *FILE_NAME.
+ 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
+ If successful, stores 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.
+ all resources to be released. The return value must not be
+ explicitly freed.
+
+ The caller is responsible for closing *FP */
- The caller is responsible for closing *FP, but *TMP_NAME is
- owned by the callee. */
struct replace_file *replace_file_start (const struct file_handle *fh,
const char *mode, mode_t permissions,
- FILE **fp, char **tmp_name);
+ FILE **fp);
/* Commits or aborts the replacement of a (potentially) existing
file by a new file, using the ticket returned by
if (opts.create_writeable)
mode |= 0222;
w->rf = replace_file_start (fh, "w", mode,
- &w->file, NULL);
+ &w->file);
if (w->rf == NULL)
{
msg (ME, _("Error opening `%s' for writing as a portable file: %s."),
mode = 0444;
if (opts.create_writeable)
mode |= 0222;
- w->rf = replace_file_start (fh, "wb", mode, &w->file, NULL);
+ w->rf = replace_file_start (fh, "wb", mode, &w->file);
if (w->rf == NULL)
{
msg (ME, _("Error opening `%s' for writing as a system file: %s."),
w = xmalloc (sizeof *w);
w->fh = fh_ref (fh);
w->lock = lock;
- w->rf = replace_file_start (w->fh, "wb", 0666,
- &w->file, NULL);
+ w->rf = replace_file_start (w->fh, "wb", 0666, &w->file);
w->encoding = xstrdup (encoding);
w->line_ends = fh_get_line_ends (fh);
w->unit = ei.unit;