Loading...
--- Libc/Libc-763.12/stdlib/FreeBSD/realpath.c.patch
+++ Libc/Libc-498/stdlib/FreeBSD/realpath.c.patch
@@ -1,6 +1,6 @@
---- realpath.c.orig 2010-06-24 17:32:55.000000000 -0700
-+++ realpath.c 2010-06-25 13:46:50.000000000 -0700
-@@ -35,13 +35,41 @@ __FBSDID("$FreeBSD: src/lib/libc/stdlib/
+--- realpath.c.orig 2006-09-16 19:12:28.000000000 -0700
++++ realpath.c 2006-09-16 20:18:25.000000000 -0700
+@@ -35,13 +35,41 @@
#include "namespace.h"
#include <sys/param.h>
#include <sys/stat.h>
@@ -42,12 +42,9 @@
/*
* char *realpath(const char *path, char resolved[PATH_MAX]);
*
-@@ -50,36 +78,89 @@ __FBSDID("$FreeBSD: src/lib/libc/stdlib/
- * in which case the path which caused trouble is left in (resolved).
- */
+@@ -52,24 +80,55 @@
char *
--realpath(const char *path, char resolved[PATH_MAX])
-+realpath(const char *path, char inresolved[PATH_MAX])
+ realpath(const char *path, char resolved[PATH_MAX])
{
+ struct attrs attrs;
struct stat sb;
@@ -63,7 +60,6 @@
+ static dev_t rootdev;
+ static int rootdev_inited = 0;
+ ino_t inode;
-+ char *resolved;
+ if (path == NULL) {
+ errno = EINVAL;
@@ -75,25 +71,11 @@
+ return (NULL);
+ }
+#endif /* __DARWIN_UNIX03 */
-+ /*
-+ * Extension to the standard; if inresolved == NULL, allocate memory
-+ */
-+ if (!inresolved) {
-+ if ((resolved = malloc(PATH_MAX)) == NULL) return (NULL);
-+ } else {
-+ resolved = inresolved;
-+ }
+ if (!rootdev_inited) {
+ rootdev_inited = 1;
+ if (stat("/", &sb) < 0) {
-+error_return:
-+ if (!inresolved) {
-+ int e = errno;
-+ free(resolved);
-+ errno = e;
-+ }
+ return (NULL);
-+ }
++ }
+ rootdev = sb.st_dev;
+ }
serrno = errno;
@@ -118,20 +100,15 @@
+#endif /* !VARIANT_DARWINEXTSN && __DARWIN_UNIX03 */
+ {
strlcpy(resolved, ".", PATH_MAX);
-- return (NULL);
-+ goto error_return;
- }
- resolved_len = strlen(resolved);
- left_len = strlcpy(left, path, sizeof(left));
- }
- if (left_len >= sizeof(left) || resolved_len >= PATH_MAX) {
+ return (NULL);
+ }
+@@ -80,6 +139,13 @@
errno = ENAMETOOLONG;
-- return (NULL);
-+ goto error_return;
+ return (NULL);
}
+ if (resolved_len > 1) {
+ if (stat(resolved, &sb) < 0) {
-+ goto error_return;
++ return (NULL);
+ }
+ lastdev = sb.st_dev;
+ } else
@@ -139,25 +116,7 @@
/*
* Iterate over path components in `left'.
-@@ -93,7 +174,7 @@ realpath(const char *path, char resolved
- s = p ? p : left + left_len;
- if (s - left >= sizeof(next_token)) {
- errno = ENAMETOOLONG;
-- return (NULL);
-+ goto error_return;
- }
- memcpy(next_token, left, s - left);
- next_token[s - left] = '\0';
-@@ -103,7 +184,7 @@ realpath(const char *path, char resolved
- if (resolved[resolved_len - 1] != '/') {
- if (resolved_len + 1 >= PATH_MAX) {
- errno = ENAMETOOLONG;
-- return (NULL);
-+ goto error_return;
- }
- resolved[resolved_len++] = '/';
- resolved[resolved_len] = '\0';
-@@ -127,6 +208,13 @@ realpath(const char *path, char resolved
+@@ -127,6 +193,13 @@
}
/*
@@ -171,12 +130,9 @@
* Append the next path component and lstat() it. If
* lstat() fails we still can return successfully if
* there are no more path components left.
-@@ -134,27 +222,89 @@ realpath(const char *path, char resolved
- resolved_len = strlcat(resolved, next_token, PATH_MAX);
- if (resolved_len >= PATH_MAX) {
+@@ -136,25 +209,87 @@
errno = ENAMETOOLONG;
-- return (NULL);
-+ goto error_return;
+ return (NULL);
}
- if (lstat(resolved, &sb) != 0) {
+ if (getattrlist(resolved, &_rp_alist, &attrs, sizeof(attrs), FSOPT_NOFOLLOW) == 0) {
@@ -198,9 +154,8 @@
errno = serrno;
return (resolved);
}
-- return (NULL);
+#endif /* !__DARWIN_UNIX03 */
-+ goto error_return;
+ return (NULL);
}
- if (S_ISLNK(sb.st_mode)) {
+ if (dev != lastdev) {
@@ -223,7 +178,7 @@
+ * that each component of the mountpoint
+ * is a directory (and not a symlink)
+ */
-+ char temp[sizeof(sfs.f_mntonname)];
++ char temp[MNAMELEN];
+ char *cp;
+ int ok = 1;
+
@@ -251,14 +206,12 @@
+ if (islink) {
if (symlinks++ > MAXSYMLINKS) {
errno = ELOOP;
-- return (NULL);
-+ goto error_return;
+ return (NULL);
}
slen = readlink(resolved, symlink, sizeof(symlink) - 1);
- if (slen < 0)
-- return (NULL);
+ if (slen < 0) {
-+ goto error_return;
+ return (NULL);
+ }
symlink[slen] = '\0';
if (symlink[0] == '/') {
@@ -268,21 +221,7 @@
} else if (resolved_len > 1) {
/* Strip the last path component. */
resolved[resolved_len - 1] = '\0';
-@@ -172,7 +322,7 @@ realpath(const char *path, char resolved
- if (symlink[slen - 1] != '/') {
- if (slen + 1 >= sizeof(symlink)) {
- errno = ENAMETOOLONG;
-- return (NULL);
-+ goto error_return;
- }
- symlink[slen] = '/';
- symlink[slen + 1] = 0;
-@@ -180,11 +330,34 @@ realpath(const char *path, char resolved
- left_len = strlcat(symlink, left, sizeof(left));
- if (left_len >= sizeof(left)) {
- errno = ENAMETOOLONG;
-- return (NULL);
-+ goto error_return;
+@@ -184,7 +319,30 @@
}
}
left_len = strlcpy(left, symlink, sizeof(left));
@@ -295,7 +234,7 @@
+ resolved_len = strlcat(resolved, (const char *)&attrs.name + attrs.name.attr_dataoffset, PATH_MAX);
+ if (resolved_len >= PATH_MAX) {
+ errno = ENAMETOOLONG;
-+ goto error_return;
++ return (NULL);
+ }
}
+ /*