diff options
author | Jim Meyering <jim@meyering.net> | 1995-10-26 05:14:41 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1995-10-26 05:14:41 +0000 |
commit | 039942bfc13e6ef0cc3ee767d907ed37d0e1cc97 (patch) | |
tree | 33d444a3c867ddbe47fa5f2b479fbbb5b516c0ab /src | |
parent | a94e341d85e24ed071107087348563c72671e32f (diff) | |
download | coreutils-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')
-rw-r--r-- | src/sort.c | 22 |
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; |