mirror of
git://gcc.gnu.org/git/gcc.git
synced 2024-12-18 13:49:32 +08:00
mkstemps.c (mkstemps): If open failed with errno other than EEXIST, return immediately.
* mkstemps.c (mkstemps): If open failed with errno other than EEXIST, return immediately. * make-temp-file.c: Include errno.h. (make_temp_file): If mkstemps failed, print an error message before aborting. From-SVN: r138429
This commit is contained in:
parent
93cc82d1f3
commit
a23eb008dc
@ -1,3 +1,11 @@
|
||||
2008-07-31 Denys Vlasenko <dvlasenk@redhat.com>
|
||||
|
||||
* mkstemps.c (mkstemps): If open failed with errno other than
|
||||
EEXIST, return immediately.
|
||||
* make-temp-file.c: Include errno.h.
|
||||
(make_temp_file): If mkstemps failed, print an error message
|
||||
before aborting.
|
||||
|
||||
2008-07-24 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
|
||||
|
||||
* maint-tool (deps): Output config.h instead of stamp-h.
|
||||
|
@ -23,6 +23,7 @@ Boston, MA 02110-1301, USA. */
|
||||
|
||||
#include <stdio.h> /* May get P_tmpdir. */
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@ -166,11 +167,14 @@ make_temp_file (const char *suffix)
|
||||
strcpy (temp_filename + base_len + TEMP_FILE_LEN, suffix);
|
||||
|
||||
fd = mkstemps (temp_filename, suffix_len);
|
||||
/* If mkstemps failed, then something bad is happening. Maybe we should
|
||||
issue a message about a possible security attack in progress? */
|
||||
/* Mkstemps failed. It may be EPERM, ENOSPC etc. */
|
||||
if (fd == -1)
|
||||
{
|
||||
fprintf (stderr, "Cannot create temporary file in %s: %s\n",
|
||||
base, strerror (errno));
|
||||
abort ();
|
||||
/* Similarly if we can not close the file. */
|
||||
}
|
||||
/* We abort on failed close out of sheer paranoia. */
|
||||
if (close (fd))
|
||||
abort ();
|
||||
return temp_filename;
|
||||
|
@ -127,6 +127,9 @@ mkstemps (char *pattern, int suffix_len)
|
||||
if (fd >= 0)
|
||||
/* The file does not exist. */
|
||||
return fd;
|
||||
if (errno != EEXIST)
|
||||
/* Fatal error (EPERM, ENOSPC etc). Doesn't make sense to loop. */
|
||||
break;
|
||||
|
||||
/* This is a random value. It is only necessary that the next
|
||||
TMP_MAX values generated by adding 7777 to VALUE are different
|
||||
|
Loading…
Reference in New Issue
Block a user