On 05/22/2012 03:06 PM, Tobias Burnus wrote:
The attached patches fix compilation issues on VxWorks.
a) VxWorks has strerror_r but contrary to POSIX, the function in
VxWorks (at least in older versions) takes only two arguments: errnum
and buf and not also the buffer length. I added a configure check for
that variant.
I forgot to attach that patch. Now with patch and automake 1.11.1 for
the generated files.
Tobias
2012-05-22 Tobias Burnus <bur...@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.
diff --git a/libgfortran/runtime/error.c b/libgfortran/runtime/error.c
index 7e523bc..8e8d80d 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,14 @@ gf_strerror (int errnum,
strerror_r (errnum, buf, buflen),
/* POSIX strerror_r () */
(strerror_r (errnum, buf, buflen), buf));
+#elif defined(HAVE_STRERROR_R_2ARGS)
+ return
+ __builtin_choose_expr (__builtin_classify_type (strerror_r (0, buf))
+ == 5,
+ /* char*-returning strerror_r() */
+ strerror_r (errnum, buf),
+ /* int-returning strerror_r () */
+ (strerror_r (errnum, buf), buf));
#else
/* strerror () is not necessarily thread-safe, but should at least
be available everywhere. */
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/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])