From 527d6c46b6ef777cb401e090eabd997b2d372c71 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Wed, 25 May 2011 15:15:14 -0600 Subject: [PATCH] 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 (cherry picked from commit 1622b36b4ae889ea79ddc444e86fea31cd91755b) --- ChangeLog | 7 +++++++ doc/posix-functions/getcwd.texi | 4 ++++ lib/getcwd-lgpl.c | 9 ++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a8b7e96ec..951081676 100644 --- 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 index a49a8990d..ffb5086ff 100644 --- a/doc/posix-functions/getcwd.texi +++ b/doc/posix-functions/getcwd.texi @@ -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}: diff --git a/lib/getcwd-lgpl.c b/lib/getcwd-lgpl.c index 53c556235..27614228a 100644 --- a/lib/getcwd-lgpl.c +++ b/lib/getcwd-lgpl.c @@ -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) { -- 2.11.0