xgetcwd: Move AC_LIBOBJ invocations to module description.
[gnulib.git] / lib / strerror_r.c
index 93e33fa..46b47ed 100644 (file)
@@ -181,9 +181,8 @@ strerror_r (int errnum, char *buf, size_t buflen)
       {
         char stackbuf[STACKBUF_LEN];
 
-        /* strerror-impl.h is also affected if our choice of stackbuf
-           size is not large enough.  */
         if (strerror_r (errnum, stackbuf, sizeof stackbuf) == ERANGE)
+          /* STACKBUF_LEN should have been large enough.  */
           abort ();
         safe_copy (buf, buflen, stackbuf);
       }
@@ -198,7 +197,7 @@ strerror_r (int errnum, char *buf, size_t buflen)
         size_t len;
         strerror_r (errnum, stackbuf, sizeof stackbuf);
         len = strlen (stackbuf);
-        /* stackbuf should have been large enough.  */
+        /* STACKBUF_LEN should have been large enough.  */
         if (len + 1 == sizeof stackbuf)
           abort ();
         if (buflen <= len)
@@ -210,9 +209,16 @@ strerror_r (int errnum, char *buf, size_t buflen)
     if (ret < 0)
       ret = errno;
 
-    /* FreeBSD rejects 0; see http://austingroupbugs.net/view.php?id=382.  */
-    if (errnum == 0 && ret == EINVAL)
-      ret = safe_copy (buf, buflen, "Success");
+    /* FreeBSD rejects 0; see http://austingroupbugs.net/view.php?id=382.
+       MacOS X 10.5 strerror_r differs from the strerror string for 0.  */
+    if (errnum == 0)
+      {
+# if defined __APPLE__ && defined __MACH__
+        ret = EINVAL;
+# endif
+        if (ret == EINVAL)
+          ret = safe_copy (buf, buflen, "Success");
+      }
 
 #else /* USE_SYSTEM_STRERROR */