Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion libc-bottom-half/sources/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ __wasilibc_link(const char *oldpath, const char *newpath, int flags)
char *old_relative_path;
char *new_relative_path;
int old_dirfd = find_relpath(oldpath, &old_relative_path);
int new_dirfd = find_relpath(newpath, &new_relative_path);
int new_dirfd = find_relpath_alt(newpath, &new_relative_path);

// If we can't find a preopen for it, fail as if we can't find the path.
if (old_dirfd == -1 || new_dirfd == -1) {
Expand Down
25 changes: 25 additions & 0 deletions test/src/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,34 @@ int main(void)
close(fd);

TEST(link(tmp, tmp1)==0);
TEST(unlink(tmp1) != -1);

TEST(linkat(AT_FDCWD, tmp, AT_FDCWD, tmp1, 0)==0);
TEST(unlink(tmp1) != -1);

TEST(unlink(tmp) != -1);

char src[] = "/dir/a";
char dst[] = "/dir/b";

TEST(mkdir("dir", 0700) == 0);
TEST((fd = open(src, flags | O_WRONLY | O_CREAT | O_EXCL, 0600)) > 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tab/space issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hoping to work on clang-format after #685 is merged but for now it's a bit messy all the style in the repo, this is I believe not the first test with this for example.

close(fd);

TEST(link(src, dst)==0);
TEST(unlink(dst) != -1);

TEST(linkat(AT_FDCWD, src, AT_FDCWD, dst, 0) == 0);
TEST(unlink(dst) != -1);

TEST(chdir("/dir") == 0);

TEST(linkat(AT_FDCWD, "a", AT_FDCWD, "b", 0) == 0);
TEST(unlink("b") != -1);

TEST(chdir("/") == 0);

TEST(unlink(src) != -1);

return t_status;
}