# HG changeset patch # User Eric Blake # Date 1306358114 21600 # Node ID a57aca916cfdc321d38862dd0c360765d15fb53d # Parent 82b7de24fe12bb9be29c6c3b9ba9c4b7138e1588 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 diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-05-25 Eric Blake + + 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 test-intprops: disable -Wtype-limits diagnostics diff --git a/doc/posix-functions/getcwd.texi b/doc/posix-functions/getcwd.texi --- 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}: diff --git a/lib/getcwd-lgpl.c b/lib/getcwd-lgpl.c --- 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) {