1 --- realpath.c.orig Fri Aug 15 19:22:17 2003
2 +++ realpath.c Tue Dec 9 14:36:32 2003
8 +#include <sys/vnode.h>
9 #include "un-namespace.h"
13 + attrreference_t name;
18 +static struct attrlist alist = {
21 + ATTR_CMN_NAME | ATTR_CMN_OBJTYPE,
29 * char *realpath(const char *path, char resolved[PATH_MAX]);
33 realpath(const char *path, char resolved[PATH_MAX])
38 - size_t left_len, resolved_len;
39 + size_t left_len, resolved_len, save_resolved_len;
42 + int serrno, slen, useattrs, islink;
43 char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX];
50 + * Save resolved_len, so that we can later null out
51 + * the the appended next_token, and replace with the
52 + * real name (matters on case-insensitive filesystems).
54 + save_resolved_len = resolved_len;
57 * Append the next path component and lstat() it. If
58 * lstat() fails we still can return successfully if
59 * there are no more path components left.
64 - if (lstat(resolved, &sb) != 0) {
65 + if (getattrlist(resolved, &alist, &attrs, sizeof(attrs), FSOPT_NOFOLLOW) == 0) {
67 + islink = (attrs.type == VLNK);
68 + } else if (errno == EOPNOTSUPP || errno == EINVAL) {
69 + if ((useattrs = lstat(resolved, &sb)) == 0)
70 + islink = S_ISLNK(sb.st_mode);
74 if (errno == ENOENT && p == NULL) {
80 - if (S_ISLNK(sb.st_mode)) {
82 if (symlinks++ > MAXSYMLINKS) {
88 left_len = strlcpy(left, symlink, sizeof(left));
89 + } else if (useattrs) {
91 + * attrs already has the real name.
94 + resolved[save_resolved_len] = '\0';
95 + resolved_len = strlcat(resolved, (const char *)&attrs.name + attrs.name.attr_dataoffset, PATH_MAX);
96 + if (resolved_len >= PATH_MAX) {
97 + errno = ENAMETOOLONG;
102 + * For the case of useattrs == 0, we could scan the directory
103 + * and try to match the inode. There are many problems with
104 + * this: (1) the directory may not be readable, (2) for multiple
105 + * hard links, we would find the first, but not necessarily
106 + * the one specified in the path, (3) we can't try to do
107 + * a case-insensitive search to match the right one in (2),
108 + * because the underlying filesystem may do things like
109 + * decompose composed characters. For most cases, doing
110 + * nothing is the right thing when useattrs == 0, so we punt