Update our FreeBSD realpath(3) to upstream head.
Change-Id: I8c89728184ecd2c1a28a05cefa84a5037d28b552
This commit is contained in:
parent
1f7d5ac538
commit
31e072fc9b
@ -132,26 +132,7 @@ realpath(const char * __restrict path, char * __restrict resolved)
|
|||||||
resolved[resolved_len] = '\0';
|
resolved[resolved_len] = '\0';
|
||||||
}
|
}
|
||||||
if (next_token[0] == '\0') {
|
if (next_token[0] == '\0') {
|
||||||
/*
|
/* Handle consequential slashes. */
|
||||||
* Handle consequential slashes. The path
|
|
||||||
* before slash shall point to a directory.
|
|
||||||
*
|
|
||||||
* Only the trailing slashes are not covered
|
|
||||||
* by other checks in the loop, but we verify
|
|
||||||
* the prefix for any (rare) "//" or "/\0"
|
|
||||||
* occurence to not implement lookahead.
|
|
||||||
*/
|
|
||||||
if (lstat(resolved, &sb) != 0) {
|
|
||||||
if (m)
|
|
||||||
free(resolved);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
if (!S_ISDIR(sb.st_mode)) {
|
|
||||||
if (m)
|
|
||||||
free(resolved);
|
|
||||||
errno = ENOTDIR;
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (strcmp(next_token, ".") == 0)
|
else if (strcmp(next_token, ".") == 0)
|
||||||
@ -236,6 +217,11 @@ realpath(const char * __restrict path, char * __restrict resolved)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
left_len = strlcpy(left, symlink, sizeof(left));
|
left_len = strlcpy(left, symlink, sizeof(left));
|
||||||
|
} else if (!S_ISDIR(sb.st_mode) && p != NULL) {
|
||||||
|
if (m)
|
||||||
|
free(resolved);
|
||||||
|
errno = ENOTDIR;
|
||||||
|
return (NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +99,18 @@ TEST(stdlib, realpath__ENOENT) {
|
|||||||
ASSERT_EQ(ENOENT, errno);
|
ASSERT_EQ(ENOENT, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(stdlib, realpath__component_after_non_directory) {
|
||||||
|
errno = 0;
|
||||||
|
char* p = realpath("/dev/null/.", NULL);
|
||||||
|
ASSERT_TRUE(p == NULL);
|
||||||
|
ASSERT_EQ(ENOTDIR, errno);
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
p = realpath("/dev/null/..", NULL);
|
||||||
|
ASSERT_TRUE(p == NULL);
|
||||||
|
ASSERT_EQ(ENOTDIR, errno);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(stdlib, realpath) {
|
TEST(stdlib, realpath) {
|
||||||
// Get the name of this executable.
|
// Get the name of this executable.
|
||||||
char executable_path[PATH_MAX];
|
char executable_path[PATH_MAX];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user