summaryrefslogtreecommitdiff
path: root/m4/strerror.m4
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2011-05-18 18:16:59 -0600
committerEric Blake <eblake@redhat.com>2011-05-19 09:33:59 -0600
commit1608fbc0104136faf98fcd89416a6c2ab4bff692 (patch)
tree970b3afaef4ca7ec4b870a602c53b530ff7f9233 /m4/strerror.m4
parent4b0606ce6847d6070a6f138145f3f5660fb9d97c (diff)
downloadgnulib-1608fbc0104136faf98fcd89416a6c2ab4bff692.tar.gz
strerror: enforce POSIX ruling on strerror(0)
http://austingroupbugs.net/view.php?id=382 requires that strerror(0) succeed, but FreeBSD reports "Unknown error: 0" and fails with EINVAL. * m4/strerror.m4 (gl_FUNC_STRERROR_SEPARATE): Expose BSD bug. * m4/strerror_r.m4 (gl_FUNC_STRERROR_R): Likewise. * lib/strerror_r.c (rpl_strerror_r): Work around it. * doc/posix-functions/strerror.texi (strerror): Document it. * doc/posix-functions/strerror_r.texi (strerror_r): Likewise. * tests/test-strerror.c (main): Strengthen test. * tests/test-strerror_r.c (main): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'm4/strerror.m4')
-rw-r--r--m4/strerror.m421
1 files changed, 10 insertions, 11 deletions
diff --git a/m4/strerror.m4 b/m4/strerror.m4
index 73d1d54d81..d891031f61 100644
--- a/m4/strerror.m4
+++ b/m4/strerror.m4
@@ -1,4 +1,4 @@
-# strerror.m4 serial 9
+# strerror.m4 serial 10
dnl Copyright (C) 2002, 2007-2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -25,19 +25,18 @@ AC_DEFUN([gl_FUNC_STRERROR_SEPARATE],
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
[[#include <string.h>
+ #include <errno.h>
]],
- [[return !*strerror (-2);]])],
+ [[int result = 0;
+ if (!*strerror (-2)) result |= 1;
+ errno = 0;
+ if (!*strerror (0)) result |= 2;
+ if (errno) result |= 4;
+ return result;]])],
[gl_cv_func_working_strerror=yes],
[gl_cv_func_working_strerror=no],
- [dnl Assume crossbuild works if it compiles.
- AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [[#include <string.h>
- ]],
- [[return !*strerror (-2);]])],
- [gl_cv_func_working_strerror=yes],
- [gl_cv_func_working_strerror=no])
- ])
+ [dnl Be pessimistic on cross-compiles for now.
+ gl_cv_func_working_strerror=no])
])
if test $gl_cv_func_working_strerror = no; then
dnl The system's strerror() fails to return a string for out-of-range