Commit 14bef49e by Francois-Xavier Coudert Committed by François-Xavier Coudert

re PR libfortran/47439 (Fun with scratch files on Windows MKTEMP only allows for 26 files)

	PR libfortran/47439

	* io/unix.c (tempfile): Work around poor mktemp() implementations.

	* gfortran.dg/scratch_1.f90: New test.

From-SVN: r171178
parent 5bd4cd72
2011-03-16 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR libfortran/47439
* gfortran.dg/scratch_1.f90: New test.
2011-03-18 Joseph Myers <joseph@codesourcery.com> 2011-03-18 Joseph Myers <joseph@codesourcery.com>
* gcc.dg/c1x-typedef-1.c: Expect errors for redefinitions of * gcc.dg/c1x-typedef-1.c: Expect errors for redefinitions of
......
! { dg-do run }
! Check that we can open more than 26 scratch files concurrently
integer :: i
do i = 1, 3000
print *, i
open(100+i,status="scratch")
end do
end
2011-03-19 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR libfortran/47439
* io/unix.c (tempfile): Work around poor mktemp() implementations.
2011-03-16 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> 2011-03-16 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR libfortran/47883 PR libfortran/47883
......
...@@ -1022,6 +1022,12 @@ tempfile (st_parameter_open *opp) ...@@ -1022,6 +1022,12 @@ tempfile (st_parameter_open *opp)
char *template; char *template;
const char *slash = "/"; const char *slash = "/";
int fd; int fd;
size_t tempdirlen;
#ifndef HAVE_MKSTEMP
int count;
size_t slashlen;
#endif
tempdir = getenv ("GFORTRAN_TMPDIR"); tempdir = getenv ("GFORTRAN_TMPDIR");
#ifdef __MINGW32__ #ifdef __MINGW32__
...@@ -1046,16 +1052,19 @@ tempfile (st_parameter_open *opp) ...@@ -1046,16 +1052,19 @@ tempfile (st_parameter_open *opp)
if (tempdir == NULL) if (tempdir == NULL)
tempdir = DEFAULT_TEMPDIR; tempdir = DEFAULT_TEMPDIR;
#endif #endif
/* Check for special case that tempdir contains slash /* Check for special case that tempdir contains slash
or backslash at end. */ or backslash at end. */
if (*tempdir == 0 || tempdir[strlen (tempdir) - 1] == '/' tempdirlen = strlen (tempdir);
if (*tempdir == 0 || tempdir[tempdirlen - 1] == '/'
#ifdef __MINGW32__ #ifdef __MINGW32__
|| tempdir[strlen (tempdir) - 1] == '\\' || tempdir[tempdirlen - 1] == '\\'
#endif #endif
) )
slash = ""; slash = "";
template = get_mem (strlen (tempdir) + 20); // Take care that the template is longer in the mktemp() branch.
template = get_mem (tempdirlen + 23);
#ifdef HAVE_MKSTEMP #ifdef HAVE_MKSTEMP
sprintf (template, "%s%sgfortrantmpXXXXXX", tempdir, slash); sprintf (template, "%s%sgfortrantmpXXXXXX", tempdir, slash);
...@@ -1064,11 +1073,30 @@ tempfile (st_parameter_open *opp) ...@@ -1064,11 +1073,30 @@ tempfile (st_parameter_open *opp)
#else /* HAVE_MKSTEMP */ #else /* HAVE_MKSTEMP */
fd = -1; fd = -1;
count = 0;
slashlen = strlen (slash);
do do
{ {
sprintf (template, "%s%sgfortrantmpXXXXXX", tempdir, slash); sprintf (template, "%s%sgfortrantmpaaaXXXXXX", tempdir, slash);
if (!mktemp (template)) if (count > 0)
{
int c = count;
template[tempdirlen + slashlen + 13] = 'a' + (c% 26);
c /= 26;
template[tempdirlen + slashlen + 12] = 'a' + (c % 26);
c /= 26;
template[tempdirlen + slashlen + 11] = 'a' + (c % 26);
if (c >= 26)
break; break;
}
if (!mktemp (template))
{
errno = EEXIST;
count++;
continue;
}
#if defined(HAVE_CRLF) && defined(O_BINARY) #if defined(HAVE_CRLF) && defined(O_BINARY)
fd = open (template, O_RDWR | O_CREAT | O_EXCL | O_BINARY, fd = open (template, O_RDWR | O_CREAT | O_EXCL | O_BINARY,
S_IREAD | S_IWRITE); S_IREAD | S_IWRITE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment