getcwd: work around mingw bug
authorEric Blake <eblake@redhat.com>
Wed, 25 May 2011 21:15:14 +0000 (15:15 -0600)
committerIan Beckwith <ianb@erislabs.net>
Thu, 9 Jun 2011 19:01:00 +0000 (20:01 +0100)
mingw getcwd(buf, 0) fails with ERANGE, instead of the required
EINVAL.  Since we're already replacing getcwd on mingw, the
workaround is trivial.

* lib/getcwd-lgpl.c (rpl_getcwd): Guarantee correct error.
* doc/posix-functions/getcwd.texi (getcwd): Document it.
Reported by Matthias Bolte.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 1622b36b4ae889ea79ddc444e86fea31cd91755b)

ChangeLog
doc/posix-functions/getcwd.texi
lib/getcwd-lgpl.c

index a8b7e96..9510816 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-05-25  Eric Blake  <eblake@redhat.com>
+
+       getcwd: work around mingw bug
+       * lib/getcwd-lgpl.c (rpl_getcwd): Guarantee correct error.
+       * doc/posix-functions/getcwd.texi (getcwd): Document it.
+       Reported by Matthias Bolte.
+
 2011-05-24  Paul Eggert  <eggert@cs.ucla.edu>
 
        test-intprops: disable -Wtype-limits diagnostics
index a49a899..ffb5086 100644 (file)
@@ -16,6 +16,10 @@ On some other platforms, this call is not allowed.
 On some platforms, the prototype for @code{getcwd} uses @code{int}
 instead of @code{size_t} for the size argument:
 mingw.
+@item
+On some platforms, @code{getcwd (buf, 0)} fails with @code{ERANGE}
+instead of the required @code{EINVAL}:
+mingw.
 @end itemize
 
 Portability problems fixed by Gnulib module @code{getcwd}:
index 53c5562..2761422 100644 (file)
@@ -45,7 +45,14 @@ rpl_getcwd (char *buf, size_t size)
 
   /* Handle single size operations.  */
   if (buf)
-    return getcwd (buf, size);
+    {
+      if (!size)
+        {
+          errno = EINVAL;
+          return NULL;
+        }
+      return getcwd (buf, size);
+    }
 
   if (size)
     {