projects
/
pspp
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
69dfeed
)
replace_file_start: Now takes a file handle instead of a file name
author
John Darrington
<john@darrington.wattle.id.au>
Wed, 7 Oct 2015 18:22:25 +0000
(20:22 +0200)
committer
John Darrington
<john@darrington.wattle.id.au>
Fri, 9 Oct 2015 05:34:15 +0000
(07:34 +0200)
src/data/csv-file-writer.c
patch
|
blob
|
history
src/data/make-file.c
patch
|
blob
|
history
src/data/make-file.h
patch
|
blob
|
history
src/data/por-file-writer.c
patch
|
blob
|
history
src/data/sys-file-writer.c
patch
|
blob
|
history
src/language/data-io/data-writer.c
patch
|
blob
|
history
diff --git
a/src/data/csv-file-writer.c
b/src/data/csv-file-writer.c
index 8e52df50756cdf1b3f75d0d4ea7c020bc3477f49..99fe41351063516cb752b4b9d3acfc436eac83b9 100644
(file)
--- a/
src/data/csv-file-writer.c
+++ b/
src/data/csv-file-writer.c
@@
-154,7
+154,7
@@
csv_writer_open (struct file_handle *fh, const struct dictionary *dict,
goto error;
/* Create the file on disk. */
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)
{
&w->file, NULL);
if (w->rf == NULL)
{
diff --git
a/src/data/make-file.c
b/src/data/make-file.c
index 9e84306cfb04a36d6482a3f740a03290ac9cd960..be1a0127493586d42262c022d705c0c2e2657d2d 100644
(file)
--- a/
src/data/make-file.c
+++ b/
src/data/make-file.c
@@
-28,6
+28,7
@@
#include <unistd.h>
#include "data/file-name.h"
#include <unistd.h>
#include "data/file-name.h"
+#include "data/file-handle-def.h"
#include "libpspp/ll.h"
#include "libpspp/message.h"
#include "libpspp/ll.h"
#include "libpspp/message.h"
@@
-45,14
+46,14
@@
struct replace_file
char *file_name;
char *tmp_name;
};
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 *
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;
mode_t permissions, FILE **fp, char **tmp_name)
{
static bool registered;
@@
-61,6
+62,8
@@
replace_file_start (const char *file_name, const char *mode,
int fd;
int saved_errno = errno;
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))
/* 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))
diff --git
a/src/data/make-file.h
b/src/data/make-file.h
index 3861f35109af866978b5938d0bbc34389e6c059b..2e424fefdf8f4d8716617950c932d6bc2874b861 100644
(file)
--- a/
src/data/make-file.h
+++ b/
src/data/make-file.h
@@
-21,6
+21,8
@@
#include <stdio.h>
#include <sys/types.h>
#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.
/* 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.
@@
-37,7
+39,7
@@
The caller is responsible for closing *FP, but *TMP_NAME is
owned by the callee. */
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);
const char *mode, mode_t permissions,
FILE **fp, char **tmp_name);
diff --git
a/src/data/por-file-writer.c
b/src/data/por-file-writer.c
index 778b8e402f3a303157ee597380872caa87cfb000..7a3c971dec614e92091bcabfb54c41439780c8b7 100644
(file)
--- a/
src/data/por-file-writer.c
+++ b/
src/data/por-file-writer.c
@@
-153,7
+153,7
@@
pfm_open_writer (struct file_handle *fh, struct dictionary *dict,
mode = 0444;
if (opts.create_writeable)
mode |= 0222;
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)
{
&w->file, NULL);
if (w->rf == NULL)
{
diff --git
a/src/data/sys-file-writer.c
b/src/data/sys-file-writer.c
index e0c6eade4b158d81e457bdb263b490828500d6a8..0f970190d4733fb8dd763370653c5717a738ae03 100644
(file)
--- a/
src/data/sys-file-writer.c
+++ b/
src/data/sys-file-writer.c
@@
-251,8
+251,7
@@
sfm_open_writer (struct file_handle *fh, struct dictionary *d,
mode = 0444;
if (opts.create_writeable)
mode |= 0222;
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."),
if (w->rf == NULL)
{
msg (ME, _("Error opening `%s' for writing as a system file: %s."),
diff --git
a/src/language/data-io/data-writer.c
b/src/language/data-io/data-writer.c
index 5f87d0060ac589a27c0713ba8cfc38ca91329642..8ae72513391bd8949a52e3180e89cf7c63467f62 100644
(file)
--- a/
src/language/data-io/data-writer.c
+++ b/
src/language/data-io/data-writer.c
@@
-92,7
+92,7
@@
dfm_open_writer (struct file_handle *fh, const char *encoding)
w = xmalloc (sizeof *w);
w->fh = fh_ref (fh);
w->lock = lock;
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);
&w->file, NULL);
w->encoding = xstrdup (encoding);
w->line_ends = fh_get_line_ends (fh);