From a8d8f72370f62b7bc9346104d1af4e2444e8cd2c Mon Sep 17 00:00:00 2001 From: burnus Date: Wed, 23 May 2012 08:34:06 +0000 Subject: [PATCH] 2012-05-23 Tobias Burnus 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@187796 138bc75d-0d04-0410-961f-82ee72b054a4 --- libgfortran/ChangeLog | 11 ++++++++++ libgfortran/acinclude.m4 | 26 +++++++++++++++++++++++ libgfortran/config.h.in | 5 ++++- libgfortran/configure | 52 ++++++++++++++++++++++++++++++++++++++++++--- libgfortran/configure.ac | 5 ++++- libgfortran/runtime/error.c | 4 ++++ 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 + + 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 * 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 + #include ], + [char s[128]; strerror_r(5, s, 128);], + AC_DEFINE(HAVE_STRERROR_R, 1, + [Define if strerror_r is available in .]),) + 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 + #include ], + [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 .]),) + 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 . */ #undef HAVE_STRERROR_R +/* Define if strerror_r takes two arguments and is available in . */ +#undef HAVE_STRERROR_R_2ARGS + /* Define to 1 if you have the 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 + #include +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 + #include +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. */ -- 2.7.4