goto error;
/* Create the file on disk. */
- w->rf = replace_file_start (fh_get_file_name (fh), "w", 0666,
+ w->rf = replace_file_start (fh, "w", 0666,
&w->file, NULL);
if (w->rf == NULL)
{
#include <unistd.h>
#include "data/file-name.h"
+#include "data/file-handle-def.h"
#include "libpspp/ll.h"
#include "libpspp/message.h"
char *file_name;
char *tmp_name;
};
-
+
static struct ll_list all_files = LL_INITIALIZER (all_files);
static void free_replace_file (struct replace_file *);
static void unlink_replace_files (void);
struct replace_file *
-replace_file_start (const char *file_name, const char *mode,
+replace_file_start (const struct file_handle *fh, const char *mode,
mode_t permissions, FILE **fp, char **tmp_name)
{
static bool registered;
int fd;
int saved_errno = errno;
+ const char *file_name = fh_get_file_name (fh);
+
/* If FILE_NAME represents a special file, write to it directly
instead of trying to replace it. */
if (stat (file_name, &s) == 0 && !S_ISREG (s.st_mode))
#include <stdio.h>
#include <sys/types.h>
+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.
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,
+struct replace_file *replace_file_start (const struct file_handle *fh,
const char *mode, mode_t permissions,
FILE **fp, char **tmp_name);
mode = 0444;
if (opts.create_writeable)
mode |= 0222;
- w->rf = replace_file_start (fh_get_file_name (fh), "w", mode,
+ w->rf = replace_file_start (fh, "w", mode,
&w->file, NULL);
if (w->rf == NULL)
{
mode = 0444;
if (opts.create_writeable)
mode |= 0222;
- w->rf = replace_file_start (fh_get_file_name (fh), "wb", mode,
- &w->file, NULL);
+ w->rf = replace_file_start (fh, "wb", mode, &w->file, NULL);
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 (fh_get_file_name (w->fh), "wb", 0666,
+ w->rf = replace_file_start (w->fh, "wb", 0666,
&w->file, NULL);
w->encoding = xstrdup (encoding);
w->line_ends = fh_get_line_ends (fh);