Merge commit 'stable/20110609'
[gnulib.git] / lib / strerror_r.c
index dc7ea88..1fa52d9 100644 (file)
@@ -1,6 +1,6 @@
 /* strerror_r.c --- POSIX compatible system error routine
 
-   Copyright (C) 2010 Free Software Foundation, Inc.
+   Copyright (C) 2010-2011 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -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
@@ -98,7 +103,7 @@ strerror_r (int errnum, char *buf, size_t buflen)
   extern int __xpg_strerror_r (int errnum, char *buf, size_t buflen);
 
   int ret = __xpg_strerror_r (errnum, buf, buflen);
-  return (ret < 0 ? errno : 0);
+  return (ret < 0 ? errno : ret);
 }
 
 #else /* (__GLIBC__ >= 2 || defined __UCLIBC__ ? !HAVE___XPG_STRERROR_R : !HAVE_DECL_STRERROR_R) || EXTEND_STRERROR_R */