bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] strerror_r-posix: port to cygwin


From: Eric Blake
Subject: [PATCH] strerror_r-posix: port to cygwin
Date: Sat, 5 Feb 2011 12:27:52 -0700

* 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 <address@hidden>
---

I'm pushing this now, and in parallel working on a patch for
cygwin 1.7.8 to provide __xpg_strerror_r with nicer behavior
(the POSIX recommended, but not mandated, behavior of ERANGE
when the buffer is too small and EINVAL when the errno resulted
in the unknown error message, all while still updating what
portion of the buffer it can).

 ChangeLog                           |   10 ++++++++++
 doc/posix-functions/strerror_r.texi |    3 ++-
 lib/strerror_r.c                    |    7 ++++++-
 m4/strerror_r.m4                    |    2 +-
 tests/test-strerror_r.c             |    4 ++--
 5 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 41497ea..b6c7b00 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-02-05  Eric Blake  <address@hidden>
+
+       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  <address@hidden>

        New module 'wmemchr'.
diff --git a/doc/posix-functions/strerror_r.texi 
b/doc/posix-functions/strerror_r.texi
index 383b6cb..ebdaf68 100644
--- a/doc/posix-functions/strerror_r.texi
+++ b/doc/posix-functions/strerror_r.texi
@@ -12,7 +12,8 @@ strerror_r
 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
index 57a7e8f..1fa52d9 100644
--- 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 <limits.h>

@@ -61,6 +61,11 @@ strerror_r (int errnum, char *buf, size_t buflen)
     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
index 3897da6..1883458 100644
--- a/m4/strerror_r.m4
+++ b/m4/strerror_r.m4
@@ -24,7 +24,7 @@ AC_DEFUN([gl_FUNC_STRERROR_R],
   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
index 2e25d8e..b2fdaf9 100644
--- a/tests/test-strerror_r.c
+++ b/tests/test-strerror_r.c
@@ -74,8 +74,8 @@ main (void)
         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
           {
-- 
1.7.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]