aboutsummaryrefslogtreecommitdiff
path: root/libgfortran
diff options
context:
space:
mode:
authorTobias Burnus <burnus@net-b.de>2012-05-23 10:34:06 +0200
committerTobias Burnus <burnus@gcc.gnu.org>2012-05-23 10:34:06 +0200
commit4179e59afafbe4c5eb00b0a82da11db7cc5a1a8c (patch)
treed08f712df5fe7cd79a42d70f17fd6a12386816f3 /libgfortran
parentf883872b10c06e67e59d3e0f192b804dc5ec3121 (diff)
downloadgcc-4179e59afafbe4c5eb00b0a82da11db7cc5a1a8c.zip
gcc-4179e59afafbe4c5eb00b0a82da11db7cc5a1a8c.tar.gz
gcc-4179e59afafbe4c5eb00b0a82da11db7cc5a1a8c.tar.bz2
re PR libfortran/53444 (Accommodate non-compliant strerror_r() on VxWorks.)
2012-05-23 Tobias Burnus <burnus@net-b.de> PR libfortran/53444 * acinclude.m4 (LIBGFOR_CHECK_STRERROR_R): Add configure checks * for two- and three-argument versions of strerror_r. * configure.ac (LIBGFOR_CHECK_STRERROR_R): Use it. * runtime/error.c (gf_strerror): Handle two-argument version of strerror_r. * config.h.in: Regenerate. * configure: Regenerate. From-SVN: r187796
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/ChangeLog11
-rw-r--r--libgfortran/acinclude.m426
-rw-r--r--libgfortran/config.h.in5
-rwxr-xr-xlibgfortran/configure52
-rw-r--r--libgfortran/configure.ac5
-rw-r--r--libgfortran/runtime/error.c4
6 files changed, 98 insertions, 5 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index a6cf6fd..12cf5f1 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,14 @@
+2012-05-23 Tobias Burnus <burnus@net-b.de>
+
+ PR libfortran/53444
+ * acinclude.m4 (LIBGFOR_CHECK_STRERROR_R): Add configure checks for
+ two- and three-argument versions of strerror_r.
+ * configure.ac (LIBGFOR_CHECK_STRERROR_R): Use it.
+ * runtime/error.c (gf_strerror): Handle two-argument version
+ of strerror_r.
+ * config.h.in: Regenerate.
+ * configure: Regenerate.
+
2012-05-16 H.J. Lu <hongjiu.lu@intel.com>
* configure: Regenerated.
diff --git a/libgfortran/acinclude.m4 b/libgfortran/acinclude.m4
index 1b11e6a..d101261 100644
--- a/libgfortran/acinclude.m4
+++ b/libgfortran/acinclude.m4
@@ -362,3 +362,29 @@ AC_DEFUN([LIBGFOR_CHECK_FLOAT128], [
dnl We need a conditional for the Makefile
AM_CONDITIONAL(LIBGFOR_BUILD_QUAD, [test "x$libgfor_cv_have_float128" = xyes])
])
+
+
+dnl Check whether we have strerror_r
+AC_DEFUN([LIBGFOR_CHECK_STRERROR_R], [
+ dnl Check for three-argument POSIX version of strerror_r
+ ac_save_CFLAGS="$CFLAGS"
+ CFLAGS="-Wimplicit-function-declaration -Werror"
+ AC_TRY_COMPILE([#define _GNU_SOURCE 1
+ #include <string.h>
+ #include <locale.h>],
+ [char s[128]; strerror_r(5, s, 128);],
+ AC_DEFINE(HAVE_STRERROR_R, 1,
+ [Define if strerror_r is available in <string.h>.]),)
+ CFLAGS="$ac_save_CFLAGS"
+
+ dnl Check for two-argument version of strerror_r (e.g. for VxWorks)
+ ac_save_CFLAGS="$CFLAGS"
+ CFLAGS="-Wimplicit-function-declaration -Werror"
+ AC_TRY_COMPILE([#define _GNU_SOURCE 1
+ #include <string.h>
+ #include <locale.h>],
+ [char s[128]; strerror_r(5, s);],
+ AC_DEFINE(HAVE_STRERROR_R_2ARGS, 1,
+ [Define if strerror_r takes two arguments and is available in <string.h>.]),)
+ CFLAGS="$ac_save_CFLAGS"
+])
diff --git a/libgfortran/config.h.in b/libgfortran/config.h.in
index b75fa96..43ba025 100644
--- a/libgfortran/config.h.in
+++ b/libgfortran/config.h.in
@@ -696,9 +696,12 @@
/* Define to 1 if you have the `strcasestr' function. */
#undef HAVE_STRCASESTR
-/* Define to 1 if you have the `strerror_r' function. */
+/* Define if strerror_r is available in <string.h>. */
#undef HAVE_STRERROR_R
+/* Define if strerror_r takes two arguments and is available in <string.h>. */
+#undef HAVE_STRERROR_R_2ARGS
+
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
diff --git a/libgfortran/configure b/libgfortran/configure
index 80bfe84..ca33870 100755
--- a/libgfortran/configure
+++ b/libgfortran/configure
@@ -2581,7 +2581,6 @@ as_fn_append ac_func_list " dup"
as_fn_append ac_func_list " getcwd"
as_fn_append ac_func_list " localtime_r"
as_fn_append ac_func_list " gmtime_r"
-as_fn_append ac_func_list " strerror_r"
as_fn_append ac_func_list " getpwuid_r"
as_fn_append ac_func_list " ttyname_r"
as_fn_append ac_func_list " clock_gettime"
@@ -12328,7 +12327,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 12331 "configure"
+#line 12330 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -12434,7 +12433,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 12437 "configure"
+#line 12436 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -16547,6 +16546,53 @@ done
+# Check strerror_r, cannot be above as versions with two and three arguments exist
+
+ ac_save_CFLAGS="$CFLAGS"
+ CFLAGS="-Wimplicit-function-declaration -Werror"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#define _GNU_SOURCE 1
+ #include <string.h>
+ #include <locale.h>
+int
+main ()
+{
+char s[128]; strerror_r(5, s, 128);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+$as_echo "#define HAVE_STRERROR_R 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ CFLAGS="$ac_save_CFLAGS"
+
+ ac_save_CFLAGS="$CFLAGS"
+ CFLAGS="-Wimplicit-function-declaration -Werror"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#define _GNU_SOURCE 1
+ #include <string.h>
+ #include <locale.h>
+int
+main ()
+{
+char s[128]; strerror_r(5, s);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+$as_echo "#define HAVE_STRERROR_R_2ARGS 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ CFLAGS="$ac_save_CFLAGS"
# Check for C99 (and other IEEE) math functions
diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
index 41bef72..fc58a5c 100644
--- a/libgfortran/configure.ac
+++ b/libgfortran/configure.ac
@@ -265,9 +265,12 @@ AC_CHECK_FUNCS_ONCE(getrusage times mkstemp strtof strtold snprintf \
ftruncate chsize chdir getlogin gethostname kill link symlink sleep ttyname \
alarm access fork execl wait setmode execve pipe dup2 close \
strcasestr getrlimit gettimeofday stat fstat lstat getpwuid vsnprintf dup \
-getcwd localtime_r gmtime_r strerror_r getpwuid_r ttyname_r clock_gettime \
+getcwd localtime_r gmtime_r getpwuid_r ttyname_r clock_gettime \
readlink getgid getpid getppid getuid geteuid umask getegid __secure_getenv)
+# Check strerror_r, cannot be above as versions with two and three arguments exist
+LIBGFOR_CHECK_STRERROR_R
+
# Check for C99 (and other IEEE) math functions
GCC_CHECK_MATH_FUNC([acosf])
GCC_CHECK_MATH_FUNC([acos])
diff --git a/libgfortran/runtime/error.c b/libgfortran/runtime/error.c
index 7e523bc..3955e44 100644
--- a/libgfortran/runtime/error.c
+++ b/libgfortran/runtime/error.c
@@ -212,6 +212,7 @@ gf_strerror (int errnum,
size_t buflen __attribute__((unused)))
{
#ifdef HAVE_STRERROR_R
+ /* POSIX returns an "int", GNU a "char*". */
return
__builtin_choose_expr (__builtin_classify_type (strerror_r (0, buf, 0))
== 5,
@@ -219,6 +220,9 @@ gf_strerror (int errnum,
strerror_r (errnum, buf, buflen),
/* POSIX strerror_r () */
(strerror_r (errnum, buf, buflen), buf));
+#elif defined(HAVE_STRERROR_R_2ARGS)
+ strerror_r (errnum, buf);
+ return buf;
#else
/* strerror () is not necessarily thread-safe, but should at least
be available everywhere. */