From 56d6664559f449af25f0d331457b014b02324d65 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Wed, 17 Aug 2011 17:51:47 -0600 Subject: [PATCH] getcwd: fix test failures on mingw The GPL getcwd replacement now kicks in for mingw thanks to the signature check, but does not have to do anything. However, because the code was not taking an early exit for ERANGE when a buffer size was given, it instead tried to second-guess mingw's cwd algorithm, which doesn't work. After fixing that, the tests still failed, even though mingw getcwd doesn't have any problems with long paths (since they can't be created in the first place). * lib/getcwd.c (__getcwd): Early exit for ERANGE. * tests/test-getcwd.c (test_abort_bug, test_long_name): Don't fail test if long directory cannot be created, and allow mingw errno. Signed-off-by: Eric Blake --- ChangeLog | 5 +++++ lib/getcwd.c | 2 +- tests/test-getcwd.c | 8 +++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 465a31f81..6d9ab92c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2011-08-17 Eric Blake + getcwd: fix test failures on mingw + * lib/getcwd.c (__getcwd): Early exit for ERANGE. + * tests/test-getcwd.c (test_abort_bug, test_long_name): Don't fail + test if long directory cannot be created, and allow mingw errno. + getcwd-lgpl: fix m4 to match relaxed test for BSD * m4/getcwd.m4 (gl_FUNC_GETCWD_NULL): Relax probe. (gl_FUNC_GETCWD_SIGNATURE): New macro. diff --git a/lib/getcwd.c b/lib/getcwd.c index f09fc3e8d..cf155214a 100644 --- a/lib/getcwd.c +++ b/lib/getcwd.c @@ -146,7 +146,7 @@ __getcwd (char *buf, size_t size) # undef getcwd dir = getcwd (buf, size); - if (dir) + if (dir || (size && errno == ERANGE)) return dir; /* Solaris getcwd (NULL, 0) fails with errno == EINVAL, but it has diff --git a/tests/test-getcwd.c b/tests/test-getcwd.c index 6e8e67ade..e9832f0ea 100644 --- a/tests/test-getcwd.c +++ b/tests/test-getcwd.c @@ -68,7 +68,8 @@ test_abort_bug (void) { if (mkdir (dir_name, S_IRWXU) < 0 || chdir (dir_name) < 0) { - fail = 3; /* Unable to construct deep hierarchy. */ + if (! (errno == ERANGE || errno == ENAMETOOLONG || errno == ENOENT)) + fail = 3; /* Unable to construct deep hierarchy. */ break; } } @@ -77,7 +78,8 @@ test_abort_bug (void) results in a failed assertion. */ cwd = getcwd (NULL, 0); if (cwd == NULL) - fail = 4; /* getcwd failed. This is ok, and expected. */ + fail = 4; /* getcwd didn't assert, but it failed for a long name + where the answer could have been learned. */ free (cwd); /* Call rmdir first, in case the above chdir failed. */ @@ -149,7 +151,7 @@ test_long_name (void) errors, be pessimistic and consider that as a failure, too. */ if (mkdir (DIR_NAME, S_IRWXU) < 0 || chdir (DIR_NAME) < 0) { - if (! (errno == ERANGE || errno == ENAMETOOLONG)) + if (! (errno == ERANGE || errno == ENAMETOOLONG || errno == ENOENT)) fail = 20; break; } -- 2.11.0