# HG changeset patch # User Eric Blake # Date 1296933359 25200 # Node ID 9dc44fa092bd35bf9f20fa68c0551d5b43fcd566 # Parent 2841c44d4d345c9351640c067f7c52559b50a94d strerror_r-posix: port to cygwin * lib/strerror_r.c (strerror_r) [__CYGWIN__]: Add cygwin implementation. * m4/strerror_r.m4 (gl_FUNC_STRERROR_R): Adjust comment. * tests/test-strerror_r.c (main): Fix test. * doc/posix-functions/strerror_r.texi (strerror_r): Document the issue. Signed-off-by: Eric Blake diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-02-05 Eric Blake + + strerror_r-posix: port to cygwin + * lib/strerror_r.c (strerror_r) [__CYGWIN__]: Add cygwin + implementation. + * m4/strerror_r.m4 (gl_FUNC_STRERROR_R): Adjust comment. + * tests/test-strerror_r.c (main): Fix test. + * doc/posix-functions/strerror_r.texi (strerror_r): Document the + issue. + 2011-02-05 Bruno Haible New module 'wmemchr'. diff --git a/doc/posix-functions/strerror_r.texi b/doc/posix-functions/strerror_r.texi --- a/doc/posix-functions/strerror_r.texi +++ b/doc/posix-functions/strerror_r.texi @@ -12,7 +12,8 @@ This function is missing on some platforms: NetBSD 3.0, HP-UX 11.23, IRIX 6.5, Solaris 9, mingw. @item -glibc has an incompatible version of this function. The POSIX compliant code +glibc and Cygwin have an incompatible version of this function. The +POSIX compliant code @smallexample char *s = (strerror_r (err, buf, buflen) == 0 ? buf : NULL); @end smallexample diff --git a/lib/strerror_r.c b/lib/strerror_r.c --- a/lib/strerror_r.c +++ b/lib/strerror_r.c @@ -27,7 +27,7 @@ #if HAVE_DECL_STRERROR_R && !(__GLIBC__ >= 2 || defined __UCLIBC__) && !EXTEND_STRERROR_R /* The system's strerror_r function is OK, except that its third argument - is 'int', not 'size_t'. */ + is 'int', not 'size_t', or its return type is wrong. */ # include @@ -61,6 +61,11 @@ else ret = strerror_r (errnum, buf, buflen); } +# elif defined __CYGWIN__ + /* Cygwin only provides the glibc interface, is thread-safe, and + always succeeds (although it may truncate). */ + strerror_r (errnum, buf, buflen); + ret = 0; # else ret = strerror_r (errnum, buf, buflen); # endif diff --git a/m4/strerror_r.m4 b/m4/strerror_r.m4 --- a/m4/strerror_r.m4 +++ b/m4/strerror_r.m4 @@ -24,7 +24,7 @@ if test $ac_cv_func_strerror_r = yes; then if test -z "$ERRNO_H"; then dnl The POSIX prototype is: int strerror_r (int, char *, size_t); - dnl glibc's prototype: char *strerror_r (int, char *, size_t); + dnl glibc, Cygwin: char *strerror_r (int, char *, size_t); dnl AIX 5.1, OSF/1 5.1: int strerror_r (int, char *, int); AC_CACHE_CHECK([for strerror_r with POSIX signature], [gl_cv_func_strerror_r_posix_signature], diff --git a/tests/test-strerror_r.c b/tests/test-strerror_r.c --- a/tests/test-strerror_r.c +++ b/tests/test-strerror_r.c @@ -74,8 +74,8 @@ if (ret == 0) { /* Truncated result. POSIX allows this, and it actually - happens on AIX 6.1. */ - ASSERT (strcmp (buf, "BADFACE") != 0); + happens on AIX 6.1 and Cygwin. */ + ASSERT ((strcmp (buf, "BADFACE") == 0) == (i == 0)); } else {