From 3f1863254a35fca88825ef6d71ef464ebf105efa Mon Sep 17 00:00:00 2001 From: ktietz Date: Sat, 24 Apr 2010 12:24:33 +0000 Subject: [PATCH 1/1] 2010-04-24 Kai Tietz PR/43844 * io/unix.c (tempfile): Correct logic for mktemp case. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@158686 138bc75d-0d04-0410-961f-82ee72b054a4 --- libgfortran/ChangeLog | 5 +++++ libgfortran/io/unix.c | 46 +++++++++++----------------------------------- 2 files changed, 16 insertions(+), 35 deletions(-) diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 78c6b04e9c9..2c38ba39af1 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,8 @@ +2010-04-24 Kai Tietz + + PR/43844 + * io/unix.c (tempfile): Correct logic for mktemp case. + 2010-04-06 Tobias Burnus PR fortran/39997 diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index f0cd3b9b16c..b3bd438c32d 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -3,7 +3,7 @@ Contributed by Andy Vaught F2003 I/O support contributed by Jerry DeLisle -This file is part of the GNU Fortran runtime library (libgfortran). +This file is part of the GNU Fortran 95 runtime library (libgfortran). Libgfortran is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -308,7 +308,7 @@ raw_truncate (unix_stream * s, gfc_offset length) errno = EBADF; return -1; } - h = (HANDLE) _get_osfhandle (s->fd); + h = _get_osfhandle (s->fd); if (h == INVALID_HANDLE_VALUE) { errno = EBADF; @@ -351,7 +351,7 @@ raw_close (unix_stream * s) retval = close (s->fd); else retval = 0; - free (s); + free_mem (s); return retval; } @@ -564,7 +564,7 @@ buf_close (unix_stream * s) { if (buf_flush (s) != 0) return -1; - free (s->buffer); + free_mem (s->buffer); return raw_close (s); } @@ -739,7 +739,7 @@ static int mem_close (unix_stream * s) { if (s != NULL) - free (s); + free_mem (s); return 0; } @@ -877,45 +877,20 @@ tempfile (st_parameter_open *opp) { const char *tempdir; char *template; - const char *slash = "/"; int fd; tempdir = getenv ("GFORTRAN_TMPDIR"); -#ifdef __MINGW32__ - if (tempdir == NULL) - { - char buffer[MAX_PATH + 1]; - DWORD ret; - ret = GetTempPath (MAX_PATH, buffer); - /* If we are not able to get a temp-directory, we use - current directory. */ - if (ret > MAX_PATH || !ret) - buffer[0] = 0; - else - buffer[ret] = 0; - tempdir = strdup (buffer); - } -#else if (tempdir == NULL) tempdir = getenv ("TMP"); if (tempdir == NULL) tempdir = getenv ("TEMP"); if (tempdir == NULL) tempdir = DEFAULT_TEMPDIR; -#endif - /* Check for special case that tempdir contains slash - or backslash at end. */ - if (*tempdir == 0 || tempdir[strlen (tempdir) - 1] == '/' -#ifdef __MINGW32__ - || tempdir[strlen (tempdir) - 1] == '\\' -#endif - ) - slash = ""; template = get_mem (strlen (tempdir) + 20); #ifdef HAVE_MKSTEMP - sprintf (template, "%s%sgfortrantmpXXXXXX", tempdir, slash); + sprintf (template, "%s/gfortrantmpXXXXXX", tempdir); fd = mkstemp (template); @@ -923,7 +898,7 @@ tempfile (st_parameter_open *opp) fd = -1; do { - sprintf (template, "%s%sgfortrantmpXXXXXX", tempdir, slash); + sprintf (template, "%s/gfortrantmpXXXXXX", tempdir); if (!mktemp (template)) break; #if defined(HAVE_CRLF) && defined(O_BINARY) @@ -934,10 +909,11 @@ tempfile (st_parameter_open *opp) #endif } while (fd == -1 && errno == EEXIST); + #endif /* HAVE_MKSTEMP */ if (fd < 0) - free (template); + free_mem (template); else { opp->file = template; @@ -1395,7 +1371,7 @@ retry: __gthread_mutex_lock (&unit_lock); __gthread_mutex_unlock (&u->lock); if (predec_waiting_locked (u) == 0) - free (u); + free_mem (u); goto retry; } @@ -1460,7 +1436,7 @@ flush_all_units (void) __gthread_mutex_lock (&unit_lock); __gthread_mutex_unlock (&u->lock); if (predec_waiting_locked (u) == 0) - free (u); + free_mem (u); } } while (1); -- 2.11.0