mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-17 18:02:09 +03:00
(xfopen): Rewrite using open/fdopen in order to set
proper permissions on temporary files. Reported by Erik Corry (erik@kroete2.freinet.de).
This commit is contained in:
1 parent
a94e341d85
commit
039942bfc1
1 file changed
+16
-6
+16
-6
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user