changeset 15522:0c9c512b8944

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 <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Wed, 17 Aug 2011 17:51:47 -0600
parents 3d3ec1e46329
children 705e7cdfdeaf
files ChangeLog lib/getcwd.c tests/test-getcwd.c
diffstat 3 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2011-08-17  Eric Blake  <eblake@redhat.com>
 
+	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.
--- a/lib/getcwd.c
+++ b/lib/getcwd.c
@@ -146,7 +146,7 @@
 
 # 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
--- a/tests/test-getcwd.c
+++ b/tests/test-getcwd.c
@@ -68,7 +68,8 @@
     {
       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 @@
      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 @@
          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;
         }