}
static FILE *
+xtmpfopen (const char *file)
+{
+ FILE *fp;
+ int fd;
+
+ fd = open (file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+ if (fd < 0 || (fp = fdopen (fd, "w")) == NULL)
+ {
+ error (0, errno, "%s", file);
+ cleanup ();
+ exit (2);
+ }
+
+ return fp;
+}
+
+static FILE *
xfopen (const char *file, const char *how)
{
FILE *fp;
}
else
{
- int fd;
- fd = open (file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
- if (fd < 0 || (fp = fdopen (fd, how)) == NULL)
+ if ((fp = fopen (file, how)) == NULL)
{
error (0, errno, "%s", file);
cleanup ();
{
for (j = 0; j < NMERGE; ++j)
fps[j] = xfopen (files[i * NMERGE + j], "r");
- tfp = xfopen (temp = tempname (), "w");
+ tfp = xtmpfopen (temp = tempname ());
mergefps (fps, NMERGE, tfp);
xfclose (tfp);
for (j = 0; j < NMERGE; ++j)
}
for (j = 0; j < nfiles % NMERGE; ++j)
fps[j] = xfopen (files[i * NMERGE + j], "r");
- tfp = xfopen (temp = tempname (), "w");
+ tfp = xtmpfopen (temp = tempname ());
mergefps (fps, nfiles % NMERGE, tfp);
xfclose (tfp);
for (j = 0; j < nfiles % NMERGE; ++j)
else
{
++n_temp_files;
- tfp = xfopen (tempname (), "w");
+ tfp = xtmpfopen (tempname ());
}
for (i = 0; i < lines.used; ++i)
if (!unique || i == 0
fp = xfopen (files[i], "r");
tmp = tempname ();
- ofp = xfopen (tmp, "w");
+ ofp = xtmpfopen (tmp);
while ((cc = fread (buf, 1, sizeof buf, fp)) > 0)
xfwrite (buf, 1, cc, ofp);
if (ferror (fp))
files[i] = tmp;
}
}
- ofp = xfopen (outfile, "w");
+ ofp = xtmpfopen (outfile);
}
else
ofp = stdout;