bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] getcwd: fix test failures on mingw


From: Eric Blake
Subject: [PATCH] getcwd: fix test failures on mingw
Date: Wed, 17 Aug 2011 17:57:47 -0600

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 <address@hidden>
---

This fixes test failures for getcwd on mingw, so I'm pushing.

 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 465a31f..6d9ab92 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2011-08-17  Eric Blake  <address@hidden>

+       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 f09fc3e..cf15521 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 6e8e67a..e9832f0 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;
         }
-- 
1.7.4.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]