bug-coreutils
[Top][All Lists]
Advanced

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

"make check" failure for pwd on Solaris 9 (+ patch)


From: Paul Eggert
Subject: "make check" failure for pwd on Solaris 9 (+ patch)
Date: Tue, 16 Nov 2004 19:45:49 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

With Coreutils CVS, "make check" failed on Solaris 9, because
its getcwd fails with errno==ERANGE even when the underlying
problem is that the working directory is longer than PATH_MAX bytes.

I installed this to try to work around the problem.  It's a bit of
a hack, though.

2004-11-16  Paul Eggert  <address@hidden>

        * lib/xgetcwd.c: Include <limits.h>, for PATH_MAX.
        (xgetcwd): Set errno correctly when failing.
        Work around Solaris 9 bug: getcwd sets errno==ERANGE even though
        the failure is actually due to a PATH_MAX problem.

Index: xgetcwd.c
===================================================================
RCS file: /fetish/cu/lib/xgetcwd.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -p -u -r1.18 -r1.19
--- xgetcwd.c   2 Aug 2004 22:47:00 -0000       1.18
+++ xgetcwd.c   17 Nov 2004 03:41:16 -0000      1.19
@@ -23,6 +23,7 @@
 # include <config.h>
 #endif
 
+#include <limits.h>
 #include <stdio.h>
 #include <errno.h>
 #include <sys/types.h>
@@ -60,6 +61,8 @@ xgetcwd (void)
   return cwd;
 #else
 
+  int saved_errno;
+
   /* The initial buffer size for the working directory.  A power of 2
      detects arithmetic overflow earlier, but is not required.  */
 # ifndef INITIAL_BUFFER_SIZE
@@ -72,16 +75,29 @@ xgetcwd (void)
     {
       char *buf = xmalloc (buf_size);
       char *cwd = getcwd (buf, buf_size);
-      int saved_errno;
       if (cwd)
        return cwd;
       saved_errno = errno;
       free (buf);
       if (saved_errno != ERANGE)
-       return NULL;
+       break;
+
+#ifdef PATH_MAX
+      if (PATH_MAX / 2 < buf_size)
+       {
+         if (PATH_MAX <= buf_size)
+           break;
+         buf_size = PATH_MAX;
+         continue;
+       }
+#endif
+
       buf_size *= 2;
       if (buf_size == 0)
        xalloc_die ();
     }
+
+  errno = saved_errno;
+  return NULL;
 #endif
 }




reply via email to

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