]> git.saurik.com Git - apple/libc.git/blobdiff - gen/FreeBSD/getcwd.c.patch
Libc-763.13.tar.gz
[apple/libc.git] / gen / FreeBSD / getcwd.c.patch
index ac2f9cd0798c89f00aba6aeef86a131850017903..bd22ed845e4b56035c292b13970c50782a9e47fc 100644 (file)
@@ -1,6 +1,6 @@
---- getcwd.c.orig      2006-01-19 18:35:45.000000000 -0800
-+++ getcwd.c   2006-02-08 17:53:41.000000000 -0800
-@@ -54,7 +54,81 @@
+--- getcwd.c.bsdnew    2009-11-08 15:25:00.000000000 -0800
++++ getcwd.c   2009-11-08 15:30:17.000000000 -0800
+@@ -50,12 +50,87 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/get
        (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \
            (dp->d_name[1] == '.' && dp->d_name[2] == '\0')))
  
@@ -43,7 +43,9 @@
 +              }
 +      } else
 +              b = buf;
-+
+-char *
+-getcwd(pt, size)
 +      err = fcntl(fd, F_GETPATH, b);
 +      if (err) {
 +              save = errno;
 +      }
 +      return 0;
 +}
- char *
- getcwd(pt, size)
-@@ -91,31 +165,23 @@
++
++__private_extern__ char *
++__private_getcwd(pt, size, usegetpath)
+       char *pt;
+       size_t size;
++      int usegetpath;
+ {
+       struct dirent *dp;
+       DIR *dir = NULL;
+@@ -87,33 +162,27 @@ getcwd(pt, size)
                }
                ept = pt + size;
        } else {
--              if ((pt = malloc(ptsize = 1024 - 4)) == NULL)
+-              if ((pt = malloc(ptsize = PATH_MAX)) == NULL)
 +              if ((pt = malloc(ptsize = MAXPATHLEN)) == NULL)
                        return (NULL);
                ept = pt + ptsize;
        }
-       if (__getcwd(pt, ept - pt) == 0) {
+-      if (__getcwd(pt, ept - pt) == 0) {
 -              if (*pt != '/') {
 -                      bpt = pt;
 -                      ept = pt + strlen(pt) - 1;
 -                              *ept-- = c;
 -                      }
 -              }
-               return (pt);
--      }
-+      } else if (errno == ERANGE) /* failed because buffer too small */
-+              return NULL;
+-              return (pt);
++      if (usegetpath) {
++              if (__getcwd(pt, ept - pt) == 0) {
++                      return (pt);
++              } else if (errno == ERANGE) /* failed because buffer too small */
++                      return NULL;
+       }
        bpt = ept - 1;
        *bpt = '\0';
  
        /*
--       * Allocate bytes (1024 - malloc space) for the string of "../"'s.
-+       * Allocate bytes MAXPATHLEN) for the string of "../"'s.
-        * Should always be enough (it's 340 levels).  If it's not, allocate
+-       * Allocate 1024 bytes for the string of "../"'s.
++       * Allocate MAXPATHLEN bytes for the string of "../"'s.
+        * Should always be enough.  If it's not, allocate
         * as necessary.  Special case the first stat, it's ".", not "..".
         */
--      if ((up = malloc(upsize = 1024 - 4)) == NULL)
+-      if ((up = malloc(upsize = 1024)) == NULL)
 +      if ((up = malloc(upsize = MAXPATHLEN)) == NULL)
                goto err;
-       eup = up + MAXPATHLEN;
+-      eup = up + upsize;
++      eup = up + MAXPATHLEN;
        bup = up;
+       up[0] = '.';
+       up[1] = '\0';
+@@ -255,3 +324,11 @@ err:
+       errno = save_errno;
+       return (NULL);
+ }
++
++char *
++getcwd(pt, size)
++      char *pt;
++      size_t size;
++{
++      return __private_getcwd(pt, size, 1);
++}