#include "data/make-file.h"
#include "libpspp/i18n.h"
-#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
static struct ll_list all_files = LL_INITIALIZER (all_files);
static void free_replace_file (struct replace_file *);
-static void unlink_replace_files (void);
+static void unlink_replace_files (int sig);
struct replace_file *
replace_file_start (const struct file_handle *fh, const char *mode,
rf->tmp_name = convert_to_filename_encoding (rf->tmp_name_verbatim, strlen (rf->tmp_name_verbatim), fh_get_file_name_encoding (fh));
/* Create file by that name. */
- fd = Topen (rf->tmp_name, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, permissions);
+ bool binary = strchr (mode, 'b') != NULL;
+ fd = Topen (rf->tmp_name,
+ O_WRONLY | O_CREAT | O_EXCL | (binary ? O_BINARY : O_TEXT),
+ permissions);
if (fd >= 0)
break;
if (errno != EEXIST)
}
static void
-unlink_replace_files (void)
+unlink_replace_files (int sig UNUSED)
{
struct replace_file *rf;