From b93d9fcf70d45a9a7cdfc01526acdab78e472493 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 3 Sep 2024 11:20:51 -0400 Subject: [PATCH] libroot: Clean up and unify link/linkat. * Move Haiku -> POSIX error mapping to linkat. * Implement link in terms of linkat. --- src/system/libroot/posix/unistd/link.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/system/libroot/posix/unistd/link.c b/src/system/libroot/posix/unistd/link.c index 1c395f6f83..c94993c971 100644 --- a/src/system/libroot/posix/unistd/link.c +++ b/src/system/libroot/posix/unistd/link.c @@ -77,19 +77,19 @@ unlinkat(int fd, const char *path, int flag) int link(const char *toPath, const char *linkPath) { - int status = _kern_create_link(-1, linkPath, -1, toPath, true); - // Haiku -> POSIX error mapping - if (status == B_UNSUPPORTED) - status = EPERM; - - RETURN_AND_SET_ERRNO(status); + return linkat(AT_FDCWD, toPath, AT_FDCWD, linkPath, 0); } int linkat(int toFD, const char *toPath, int linkFD, const char *linkPath, int flag) { - RETURN_AND_SET_ERRNO(_kern_create_link(linkFD, linkPath, toFD, toPath, - (flag & AT_SYMLINK_FOLLOW) != 0)); -} + int status = _kern_create_link(linkFD, linkPath, toFD, toPath, + (flag & AT_SYMLINK_FOLLOW) != 0); + // Haiku -> POSIX error mapping + if (status == B_UNSUPPORTED) + status = EPERM; + + RETURN_AND_SET_ERRNO(status); +}