changeset 14826:a57aca916cfd

getcwd: work around mingw bug 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>
author Eric Blake <eblake@redhat.com>
date Wed, 25 May 2011 15:15:14 -0600
parents 82b7de24fe12
children 5e5b5b8d3078
files ChangeLog doc/posix-functions/getcwd.texi lib/getcwd-lgpl.c
diffstat 3 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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
--- a/doc/posix-functions/getcwd.texi
+++ b/doc/posix-functions/getcwd.texi
@@ -16,6 +16,10 @@
 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}:
--- a/lib/getcwd-lgpl.c
+++ b/lib/getcwd-lgpl.c
@@ -45,7 +45,14 @@
 
   /* Handle single size operations.  */
   if (buf)
-    return getcwd (buf, size);
+    {
+      if (!size)
+        {
+          errno = EINVAL;
+          return NULL;
+        }
+      return getcwd (buf, size);
+    }
 
   if (size)
     {