Fix build error and implement AT_SYMLINK_NO_FOLLOW in fstatat() by calling lstat()

This commit is contained in:
John Scipione 2012-03-08 15:29:18 -05:00
parent 6ad9d01a41
commit bffc978823

View File

@ -204,7 +204,7 @@ fchownat(int fd, const char* path, uid_t owner, gid_t group, int flag)
if (fd == AT_FDCWD || path != NULL && path[0] == '/') { if (fd == AT_FDCWD || path != NULL && path[0] == '/') {
// call chown() ignoring fd // call chown() ignoring fd
return (flag & AT_SYMLINK_NOFOLLOW) != 0 ? lchown(path, owner, group) return (flag & AT_SYMLINK_NOFOLLOW) != 0 ? lchown(path, owner, group)
: (chown(path, owner, group); : chown(path, owner, group);
} }
char *fullPath = (char *)malloc(MAXPATHLEN); char *fullPath = (char *)malloc(MAXPATHLEN);
@ -220,7 +220,7 @@ fchownat(int fd, const char* path, uid_t owner, gid_t group, int flag)
} }
int status = (flag & AT_SYMLINK_NOFOLLOW) != 0 int status = (flag & AT_SYMLINK_NOFOLLOW) != 0
? lchown(fullPath, owner, group) : (chown(fullPath, owner, group); ? lchown(fullPath, owner, group) : chown(fullPath, owner, group);
free(fullPath); free(fullPath);
return status; return status;
} }
@ -229,20 +229,16 @@ fchownat(int fd, const char* path, uid_t owner, gid_t group, int flag)
int int
fstatat(int fd, const char *path, struct stat *st, int flag) fstatat(int fd, const char *path, struct stat *st, int flag)
{ {
if ((flag & AT_SYMLINK_NOFOLLOW) != 0) { if ((flag & AT_SYMLINK_NOFOLLOW) == 0 && flag != 0) {
// do not dereference, instead return information about the link // invalid flag
// itself
// CURRENTLY UNSUPPORTED
errno = ENOTSUP;
return -1;
} else if (flag != 0) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
if (fd == AT_FDCWD || path != NULL && path[0] == '/') { if (fd == AT_FDCWD || path != NULL && path[0] == '/') {
// path is absolute, call stat() ignoring fd // call stat() or lstat() ignoring fd
return stat(path, st); return (flag & AT_SYMLINK_NOFOLLOW) != 0 ? lstat(path, st)
: stat(path, st);
} }
if (fd < 0) { if (fd < 0) {
@ -263,7 +259,8 @@ fstatat(int fd, const char *path, struct stat *st, int flag)
return -1; return -1;
} }
int status = stat(fullPath, st); int status = (flag & AT_SYMLINK_NOFOLLOW) != 0 ? lstat(fullPath, st)
: stat(fullPath, st);
free(fullPath); free(fullPath);
return status; return status;
} }