From b79d34835799d78d05b99916bfc363850905601c Mon Sep 17 00:00:00 2001
From: Eric Blake <eblake@redhat.com>
Date: Thu, 19 May 2011 12:51:36 -0600
Subject: [PATCH] strerror_r: fix on newer cygwin

* lib/strerror_r.c (rpl_strerror_r): Cygwin now has
__xpg_strerror_r, use it.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 ChangeLog        |  6 ++++++
 lib/strerror_r.c | 12 ++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4e22ecba26..f5e455b44f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-05-19  Eric Blake  <eblake@redhat.com>
+
+	strerror_r: fix on newer cygwin
+	* lib/strerror_r.c (rpl_strerror_r): Cygwin now has
+	__xpg_strerror_r, use it.
+
 2011-05-19  Bruno Haible  <bruno@clisp.org>
 
 	strerror_r: Avoid clobbering the strerror buffer when possible.
diff --git a/lib/strerror_r.c b/lib/strerror_r.c
index c4aa5d9d14..fe1185ba4e 100644
--- a/lib/strerror_r.c
+++ b/lib/strerror_r.c
@@ -34,7 +34,11 @@
 # endif
 
 
-#if HAVE_DECL_STRERROR_R && !(__GLIBC__ >= 2 || defined __UCLIBC__)
+#if (__GLIBC__ >= 2 || defined __UCLIBC__ || defined __CYGWIN__) && HAVE___XPG_STRERROR_R /* glibc >= 2.3.4, cygwin >= 1.7.9 */
+
+# define USE_XPG_STRERROR_R 1
+
+#elif HAVE_DECL_STRERROR_R && !(__GLIBC__ >= 2 || defined __UCLIBC__)
 
 /* The system's strerror_r function is OK, except that its third argument
    is 'int', not 'size_t', or its return type is wrong.  */
@@ -43,10 +47,6 @@
 
 # define USE_SYSTEM_STRERROR_R 1
 
-#elif (__GLIBC__ >= 2 || defined __UCLIBC__) && HAVE___XPG_STRERROR_R /* glibc >= 2.3.4 */
-
-# define USE_XPG_STRERROR_R 1
-
 #else /* (__GLIBC__ >= 2 || defined __UCLIBC__ ? !HAVE___XPG_STRERROR_R : !HAVE_DECL_STRERROR_R) */
 
 /* Use the system's strerror().  */
@@ -446,7 +446,7 @@ strerror_r (int errnum, char *buf, size_t buflen)
         ret = strerror_r (errnum, buf, buflen);
     }
 # elif defined __CYGWIN__
-    /* Cygwin only provides the glibc interface, is thread-safe, and
+    /* Cygwin 1.7.8 only provides the glibc interface, is thread-safe, and
        always succeeds (although it may truncate). */
     strerror_r (errnum, buf, buflen);
     ret = 0;
-- 
2.39.5