summaryrefslogtreecommitdiff
path: root/src/sort.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1995-10-26 05:14:41 +0000
committerJim Meyering <jim@meyering.net>1995-10-26 05:14:41 +0000
commit039942bfc13e6ef0cc3ee767d907ed37d0e1cc97 (patch)
tree33d444a3c867ddbe47fa5f2b479fbbb5b516c0ab /src/sort.c
parenta94e341d85e24ed071107087348563c72671e32f (diff)
downloadcoreutils-039942bfc13e6ef0cc3ee767d907ed37d0e1cc97.tar.xz
(xfopen): Rewrite using open/fdopen in order to set
proper permissions on temporary files. Reported by Erik Corry (erik@kroete2.freinet.de).
Diffstat (limited to 'src/sort.c')
-rw-r--r--src/sort.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/sort.c b/src/sort.c
index be9ba38a5..1a5d98302 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -294,16 +294,26 @@ xrealloc (char *p, unsigned int n)
}
static FILE *
-xfopen (char *file, char *how)
+xfopen (const char *file, const char *how)
{
- FILE *fp = strcmp (file, "-") ? fopen (file, how) : stdin;
+ FILE *fp;
- if (fp == 0)
+ if (strcmp (file, "-") == 0)
{
- error (0, errno, "%s", file);
- cleanup ();
- exit (2);
+ fp = stdin;
}
+ else
+ {
+ int fd;
+ fd = open (file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+ if (fd < 0 || (fp = fdopen (fd, how)) == NULL)
+ {
+ error (0, errno, "%s", file);
+ cleanup ();
+ exit (2);
+ }
+ }
+
if (fp == stdin)
have_read_stdin = 1;
return fp;