getcwd: work around mingw bug
authorEric Blake <eblake@redhat.com>
Wed, 25 May 2011 21:15:14 +0000 (15:15 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 25 May 2011 21:19:16 +0000 (15:19 -0600)
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>
ChangeLog
doc/posix-functions/getcwd.texi
lib/getcwd-lgpl.c

index 390d4e808d2eaf4c3e9b4f6ad7991509510f8db1..e3c4d221a16929b1b5f825246779d85c2febd5da 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 a49a8990dc3d986bde59829d175409601fc836e0..ffb5086ffbc8b929dad119cf8bf1d9a9bb9b080d 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 53c5562357ca2138c5648e0e52c5abe5758b0330..27614228a0dafd13005453055035145583a9468e 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)
     {