(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:
Jim Meyering committed 1995-10-26 05:14:41 +00:00
1 parent a94e341d85
commit 039942bfc1
1 file changed
+16 -6
+16 -6
View File
@@ -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;