Commit 10c682a0 by Francois-Xavier Coudert Committed by François-Xavier Coudert

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
parent ec53fc93
2005-08-27 Francois-Xavier Coudert <coudert@clipper.ens.fr>
* 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.
2005-08-17 Kelley Cook <kcook@gcc.gnu.org> 2005-08-17 Kelley Cook <kcook@gcc.gnu.org>
* All files: Update FSF address. * All files: Update FSF address.
......
# Makefile.in generated by automake 1.9.5 from Makefile.am. # Makefile.in generated by automake 1.9.4 from Makefile.am.
# @configure_input@ # @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005 Free Software Foundation, Inc. # 2003, 2004 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation # This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it, # gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved. # with or without modifications, as long as this notice is preserved.
...@@ -174,7 +174,7 @@ LTPPFCCOMPILE = $(LIBTOOL) --mode=compile $(FC) $(DEFS) \ ...@@ -174,7 +174,7 @@ LTPPFCCOMPILE = $(LIBTOOL) --mode=compile $(FC) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_FCFLAGS) $(FCFLAGS) $(AM_FCFLAGS) $(FCFLAGS)
FCLD = $(FC) FCLD = $(FC)
FCLINK = $(LIBTOOL) --mode=link $(FCLD) $(AM_FCFLAGS) $(FCFLAGS) \ FCLINK = $(LIBTOOL) --mode=link $(FCLD) $(AM_FFLAGS) $(FCFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@ $(AM_LDFLAGS) $(LDFLAGS) -o $@
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
......
...@@ -148,3 +148,38 @@ extern void bar(void) __attribute__((alias(ULP "foo")));], ...@@ -148,3 +148,38 @@ extern void bar(void) __attribute__((alias(ULP "foo")));],
AC_DEFINE(HAVE_ATTRIBUTE_ALIAS, 1, AC_DEFINE(HAVE_ATTRIBUTE_ALIAS, 1,
[Define to 1 if the target supports __attribute__((alias(...))).]) [Define to 1 if the target supports __attribute__((alias(...))).])
fi]) fi])
dnl Check whether target can unlink a file still open.
AC_DEFUN([LIBGFOR_CHECK_UNLINK_OPEN_FILE], [
AC_CACHE_CHECK([whether the target can unlink an open file],
have_unlink_open_file, [
AC_TRY_RUN([
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
int main ()
{
int fd;
fd = open ("testfile", O_RDWR | O_CREAT, S_IWRITE | S_IREAD);
if (fd <= 0)
return 0;
if (unlink ("testfile") == -1)
return 1;
write (fd, "This is a test\n", 15);
close (fd);
if (open ("testfile", O_RDONLY, S_IWRITE | S_IREAD) == -1 && errno == ENOENT)
return 0;
else
return 1;
}], have_unlink_open_file=yes, have_unlink_open_file=no, [
case "${target}" in
*mingw*) have_unlink_open_file=no ;;
*) have_unlink_open_file=yes;;
esac])])
if test x"$have_unlink_open_file" = xyes; then
AC_DEFINE(HAVE_UNLINK_OPEN_FILE, 1, [Define if target can unlink open files.])
fi])
...@@ -291,6 +291,9 @@ ...@@ -291,6 +291,9 @@
/* Define to 1 if you have the <unistd.h> header file. */ /* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H #undef HAVE_UNISTD_H
/* Define if target can unlink open files. */
#undef HAVE_UNLINK_OPEN_FILE
/* libm includes y0 */ /* libm includes y0 */
#undef HAVE_Y0 #undef HAVE_Y0
......
...@@ -258,6 +258,9 @@ LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY ...@@ -258,6 +258,9 @@ LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY
LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT
LIBGFOR_CHECK_ATTRIBUTE_ALIAS LIBGFOR_CHECK_ATTRIBUTE_ALIAS
# Various other checks on target
LIBGFOR_CHECK_UNLINK_OPEN_FILE
AC_CACHE_SAVE AC_CACHE_SAVE
if test ${multilib} = yes; then if test ${multilib} = yes; then
......
...@@ -30,6 +30,7 @@ Boston, MA 02110-1301, USA. */ ...@@ -30,6 +30,7 @@ Boston, MA 02110-1301, USA. */
#include "config.h" #include "config.h"
#include "libgfortran.h" #include "libgfortran.h"
#include "io.h" #include "io.h"
#include <limits.h>
typedef enum typedef enum
{ CLOSE_DELETE, CLOSE_KEEP, CLOSE_UNSPECIFIED } { CLOSE_DELETE, CLOSE_KEEP, CLOSE_UNSPECIFIED }
...@@ -50,6 +51,11 @@ st_close (void) ...@@ -50,6 +51,11 @@ st_close (void)
{ {
close_status status; close_status status;
gfc_unit *u; gfc_unit *u;
#if !HAVE_UNLINK_OPEN_FILE
char * path;
path = NULL;
#endif
library_start (); library_start ();
...@@ -68,14 +74,30 @@ st_close (void) ...@@ -68,14 +74,30 @@ st_close (void)
if (status == CLOSE_KEEP) if (status == CLOSE_KEEP)
generate_error (ERROR_BAD_OPTION, generate_error (ERROR_BAD_OPTION,
"Can't KEEP a scratch file on CLOSE"); "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 else
{ {
if (status == CLOSE_DELETE) 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); close_unit (u);
#if !HAVE_UNLINK_OPEN_FILE
if (path != NULL)
unlink (path);
#endif
} }
library_end (); library_end ();
......
...@@ -505,6 +505,9 @@ internal_proto(stream_ttyname); ...@@ -505,6 +505,9 @@ internal_proto(stream_ttyname);
extern int unit_to_fd (int); extern int unit_to_fd (int);
internal_proto(unit_to_fd); internal_proto(unit_to_fd);
extern int unpack_filename (char *, const char *, int);
internal_proto(unpack_filename);
/* unit.c */ /* unit.c */
extern void insert_unit (gfc_unit *); extern void insert_unit (gfc_unit *);
......
...@@ -952,7 +952,7 @@ unit_to_fd(int unit) ...@@ -952,7 +952,7 @@ unit_to_fd(int unit)
* buffer that is PATH_MAX characters, convert the fortran string to a * buffer that is PATH_MAX characters, convert the fortran string to a
* C string in the buffer. Returns nonzero if this is not possible. */ * C string in the buffer. Returns nonzero if this is not possible. */
static int int
unpack_filename (char *cstring, const char *fstring, int len) unpack_filename (char *cstring, const char *fstring, int len)
{ {
len = fstrlen (fstring, len); len = fstrlen (fstring, len);
...@@ -1136,8 +1136,11 @@ open_external (unit_flags *flags) ...@@ -1136,8 +1136,11 @@ open_external (unit_flags *flags)
fd = tempfile (); fd = tempfile ();
if (flags->action == ACTION_UNSPECIFIED) if (flags->action == ACTION_UNSPECIFIED)
flags->action = ACTION_READWRITE; flags->action = ACTION_READWRITE;
#if HAVE_UNLINK_OPEN_FILE
/* We can unlink scratch files now and it will go away when closed. */ /* We can unlink scratch files now and it will go away when closed. */
unlink (ioparm.file); unlink (ioparm.file);
#endif
} }
else else
{ {
......
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