From 2515e5a7a08bdb033e3fe6370774cf7359b9811e Mon Sep 17 00:00:00 2001 From: Francois-Xavier Coudert Date: Sat, 15 Sep 2007 14:52:46 +0000 Subject: [PATCH] re PR libfortran/21185 (Improve testsuite results on newlib targets) PR libfortran/21185 * runtime/compile_options.c (set_options): Fix typo. * runtime/main.c (store_exe_path): If getcwd is not available, don't use it. * intrinsics/getcwd.c: Same thing here. * io/unix.c (fallback_access): New fallback function for access. (fix_fd): Don't use dup if it's not available. * configure.ac: Check for dup and getcwd. * configure: Regenerate. * config.h.in: Regenerate. From-SVN: r128512 --- libgfortran/ChangeLog | 13 +++++++++++ libgfortran/config.h.in | 6 +++++ libgfortran/configure | 4 +++- libgfortran/configure.ac | 2 +- libgfortran/intrinsics/getcwd.c | 4 ++++ libgfortran/io/unix.c | 33 ++++++++++++++++++++++++++- libgfortran/runtime/compile_options.c | 4 ++-- libgfortran/runtime/main.c | 4 ++++ 8 files changed, 65 insertions(+), 5 deletions(-) diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index b2ab1f01a01..58943ae3ba3 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,16 @@ +2007-09-15 Francois-Xavier Coudert + + PR libfortran/21185 + * runtime/compile_options.c (set_options): Fix typo. + * runtime/main.c (store_exe_path): If getcwd is not available, + don't use it. + * intrinsics/getcwd.c: Same thing here. + * io/unix.c (fallback_access): New fallback function for access. + (fix_fd): Don't use dup if it's not available. + * configure.ac: Check for dup and getcwd. + * configure: Regenerate. + * config.h.in: Regenerate. + 2007-09-12 Francois-Xavier Coudert * io/io.h: Include libgfortran.h first. diff --git a/libgfortran/config.h.in b/libgfortran/config.h.in index 877fc5a6e01..f805c437695 100644 --- a/libgfortran/config.h.in +++ b/libgfortran/config.h.in @@ -273,6 +273,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H +/* Define to 1 if you have the `dup' function. */ +#undef HAVE_DUP + /* Define to 1 if you have the `dup2' function. */ #undef HAVE_DUP2 @@ -384,6 +387,9 @@ /* Define to 1 if you have the `ftruncate' function. */ #undef HAVE_FTRUNCATE +/* Define to 1 if you have the `getcwd' function. */ +#undef HAVE_GETCWD + /* libc includes geteuid */ #undef HAVE_GETEUID diff --git a/libgfortran/configure b/libgfortran/configure index f71c5900f2e..be685a43f18 100755 --- a/libgfortran/configure +++ b/libgfortran/configure @@ -18481,7 +18481,9 @@ done -for ac_func in gettimeofday stat fstat lstat getpwuid vsnprintf + + +for ac_func in gettimeofday stat fstat lstat getpwuid vsnprintf dup getcwd do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac index 8aa3b637785..a4588e17a7a 100644 --- a/libgfortran/configure.ac +++ b/libgfortran/configure.ac @@ -192,7 +192,7 @@ AC_CHECK_FUNCS(getrusage times mkstemp strtof strtold snprintf ftruncate chsize) AC_CHECK_FUNCS(chdir strerror getlogin gethostname kill link symlink perror) AC_CHECK_FUNCS(sleep time ttyname signal alarm ctime clock access fork execl) AC_CHECK_FUNCS(wait setmode execvp pipe dup2 close fdopen strcasestr getrlimit) -AC_CHECK_FUNCS(gettimeofday stat fstat lstat getpwuid vsnprintf) +AC_CHECK_FUNCS(gettimeofday stat fstat lstat getpwuid vsnprintf dup getcwd) # Check for glibc backtrace functions AC_CHECK_FUNCS(backtrace backtrace_symbols) diff --git a/libgfortran/intrinsics/getcwd.c b/libgfortran/intrinsics/getcwd.c index e0826808ec2..60ec6feb1fe 100644 --- a/libgfortran/intrinsics/getcwd.c +++ b/libgfortran/intrinsics/getcwd.c @@ -37,6 +37,8 @@ Boston, MA 02110-1301, USA. */ #include #endif +#ifdef HAVE_GETCWD + extern void getcwd_i4_sub (char *, GFC_INTEGER_4 *, gfc_charlen_type); iexport_proto(getcwd_i4_sub); @@ -82,3 +84,5 @@ PREFIX(getcwd) (char *cwd, gfc_charlen_type cwd_len) getcwd_i4_sub (cwd, &status, cwd_len); return status; } + +#endif diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index 8acc02e9399..6cb578f1cc0 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -211,13 +211,13 @@ move_pos_offset (stream* st, int pos_off) static int fix_fd (int fd) { +#ifdef HAVE_DUP int input, output, error; input = output = error = 0; /* Unix allocates the lowest descriptors first, so a loop is not required, but this order is. */ - if (fd == STDIN_FILENO) { fd = dup (fd); @@ -240,6 +240,7 @@ fix_fd (int fd) close (STDOUT_FILENO); if (error) close (STDERR_FILENO); +#endif return fd; } @@ -1775,6 +1776,36 @@ inquire_unformatted (const char *string, int len) } +#ifndef HAVE_ACCESS + +#ifndef W_OK +#define W_OK 2 +#endif + +#ifndef R_OK +#define R_OK 4 +#endif + +/* Fallback implementation of access() on systems that don't have it. + Only modes R_OK and W_OK are used in this file. */ + +static int +fallback_access (const char *path, int mode) +{ + if ((mode & R_OK) && open (path, O_RDONLY) < 0) + return -1; + + if ((mode & W_OK) && open (path, O_WRONLY) < 0) + return -1; + + return 0; +} + +#undef access +#define access fallback_access +#endif + + /* inquire_access()-- Given a fortran string, determine if the file is * suitable for access. */ diff --git a/libgfortran/runtime/compile_options.c b/libgfortran/runtime/compile_options.c index 94e1f604b2a..8e0a3fe30ce 100644 --- a/libgfortran/runtime/compile_options.c +++ b/libgfortran/runtime/compile_options.c @@ -108,8 +108,8 @@ set_options (int num, int options[]) /* If backtrace is required, we set signal handlers on most common signals. */ -#if defined(HAVE_SIGNAL_H) && (defined(SIGSEGV) || defined(SIGBUS) \ - || defined(SIGILL) || defined(SIGFPE)) +#if defined(HAVE_SIGNAL) && (defined(SIGSEGV) || defined(SIGBUS) \ + || defined(SIGILL) || defined(SIGFPE)) if (compile_options.backtrace) { #if defined(SIGSEGV) diff --git a/libgfortran/runtime/main.c b/libgfortran/runtime/main.c index be12c591529..86777d9c70e 100644 --- a/libgfortran/runtime/main.c +++ b/libgfortran/runtime/main.c @@ -120,7 +120,11 @@ store_exe_path (const char * argv0) } memset (buf, 0, sizeof (buf)); +#ifdef HAVE_GETCWD cwd = getcwd (buf, sizeof (buf)); +#else + cwd = ""; +#endif /* exe_path will be cwd + "/" + argv[0] + "\0" */ path = malloc (strlen (cwd) + 1 + strlen (argv0) + 1);