Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unistd: fix _resolve_abspath() errno setting #395

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions unistd/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,16 @@ static int _resolve_abspath(char *path, char *result, int resolve_last_symlink,
const size_t readlink_max_len = p - path;

/* (hackish) save some messsaging by not calling lstat, but directly readlink() and checking error code */
int errsave = errno;
ssize_t symlink_len = _readlink_abs(result, path, readlink_max_len);

if (symlink_len < 0) {
if (errno == EINVAL) { /* not a symlink */
errno = errsave;
continue;
}
else if ((errno == ENOENT) && (is_leaf != 0) && (allow_missing_leaf != 0)) { /* non-esixting leaf */
errno = errsave;
break;
}
else {
Expand Down Expand Up @@ -491,10 +494,6 @@ static ssize_t _readlink_abs(const char *path, char *buf, size_t bufsiz)
return SET_ERRNO(msg.o.err);
}

if (msg.o.err < 0) {
return SET_ERRNO(msg.o.err);
}

if (!S_ISLNK(msg.o.attr.val)) {
return SET_ERRNO(-EINVAL);
}
Expand Down
Loading