aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/io
diff options
context:
space:
mode:
authorFrancois-Xavier Coudert <coudert@clipper.ens.fr>2005-08-27 18:01:54 +0200
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>2005-08-27 16:01:54 +0000
commit10c682a0cb57e9ed0d5bb47a20af7932486b56a5 (patch)
tree3714317919d36904c407fd6ec57fe25087da4709 /libgfortran/io
parentec53fc93d0fbfac2037da571ce5e637ef0c437ee (diff)
downloadgcc-10c682a0cb57e9ed0d5bb47a20af7932486b56a5.zip
gcc-10c682a0cb57e9ed0d5bb47a20af7932486b56a5.tar.gz
gcc-10c682a0cb57e9ed0d5bb47a20af7932486b56a5.tar.bz2
acinclude.m4 (LIBGFOR_CHECK_UNLINK_OPEN_FILE): Add check to see if target can unlink open files.
* acinclude.m4 (LIBGFOR_CHECK_UNLINK_OPEN_FILE): Add check to see if target can unlink open files. * configure.ac: Use this new test. * config.h.in: Regenerate. * configure: Regenerate. * Makefile.in: Regenerate. * aclocal.ac: Regenerate. * io/io.h: Add prototype for unpack_filename. * io/close.c (st_close): Delete file after closing unit if HAVE_UNLINK_OPEN_FILE is not defined. * io/unix.c (unpack_filename): Unlink scratch file after opening it only if HAVE_UNLINK_OPEN_FILE is defined. From-SVN: r103566
Diffstat (limited to 'libgfortran/io')
-rw-r--r--libgfortran/io/close.c24
-rw-r--r--libgfortran/io/io.h3
-rw-r--r--libgfortran/io/unix.c5
3 files changed, 30 insertions, 2 deletions
diff --git a/libgfortran/io/close.c b/libgfortran/io/close.c
index f814bd5..6010e92 100644
--- a/libgfortran/io/close.c
+++ b/libgfortran/io/close.c
@@ -30,6 +30,7 @@ Boston, MA 02110-1301, USA. */
#include "config.h"
#include "libgfortran.h"
#include "io.h"
+#include <limits.h>
typedef enum
{ CLOSE_DELETE, CLOSE_KEEP, CLOSE_UNSPECIFIED }
@@ -50,6 +51,11 @@ st_close (void)
{
close_status status;
gfc_unit *u;
+#if !HAVE_UNLINK_OPEN_FILE
+ char * path;
+
+ path = NULL;
+#endif
library_start ();
@@ -68,14 +74,30 @@ st_close (void)
if (status == CLOSE_KEEP)
generate_error (ERROR_BAD_OPTION,
"Can't KEEP a scratch file on CLOSE");
+#if !HAVE_UNLINK_OPEN_FILE
+ path = (char *) gfc_alloca (u->file_len + 1);
+ unpack_filename (path, u->file, u->file_len);
+#endif
}
else
{
if (status == CLOSE_DELETE)
- delete_file (u);
+ {
+#if HAVE_UNLINK_OPEN_FILE
+ delete_file (u);
+#else
+ path = (char *) gfc_alloca (u->file_len + 1);
+ unpack_filename (path, u->file, u->file_len);
+#endif
+ }
}
close_unit (u);
+
+#if !HAVE_UNLINK_OPEN_FILE
+ if (path != NULL)
+ unlink (path);
+#endif
}
library_end ();
diff --git a/libgfortran/io/io.h b/libgfortran/io/io.h
index 46b1835..a09c9b4 100644
--- a/libgfortran/io/io.h
+++ b/libgfortran/io/io.h
@@ -505,6 +505,9 @@ internal_proto(stream_ttyname);
extern int unit_to_fd (int);
internal_proto(unit_to_fd);
+extern int unpack_filename (char *, const char *, int);
+internal_proto(unpack_filename);
+
/* unit.c */
extern void insert_unit (gfc_unit *);
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c
index bcf50f3..a0ed7b6 100644
--- a/libgfortran/io/unix.c
+++ b/libgfortran/io/unix.c
@@ -952,7 +952,7 @@ unit_to_fd(int unit)
* buffer that is PATH_MAX characters, convert the fortran string to a
* C string in the buffer. Returns nonzero if this is not possible. */
-static int
+int
unpack_filename (char *cstring, const char *fstring, int len)
{
len = fstrlen (fstring, len);
@@ -1136,8 +1136,11 @@ open_external (unit_flags *flags)
fd = tempfile ();
if (flags->action == ACTION_UNSPECIFIED)
flags->action = ACTION_READWRITE;
+
+#if HAVE_UNLINK_OPEN_FILE
/* We can unlink scratch files now and it will go away when closed. */
unlink (ioparm.file);
+#endif
}
else
{