diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 459ac94dfe..70a3a7b3c5 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -770,6 +770,24 @@ ErrorOr isatty(int fd) return rc == 1; } +ErrorOr link(StringView old_path, StringView new_path) +{ +#ifdef __serenity__ + Syscall::SC_link_params params { + .old_path = { old_path.characters_without_null_termination(), old_path.length() }, + .new_path = { new_path.characters_without_null_termination(), new_path.length() }, + }; + int rc = syscall(SC_link, ¶ms); + HANDLE_SYSCALL_RETURN_VALUE("link", rc, {}); +#else + String old_path_string = old_path; + String new_path_string = new_path; + if (::link(old_path_string.characters(), new_path_string.characters()) < 0) + return Error::from_syscall("link"sv, -errno); + return {}; +#endif +} + ErrorOr symlink(StringView target, StringView link_path) { #ifdef __serenity__ diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index d183682dd6..7875d8737d 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -144,6 +144,7 @@ ErrorOr setpgid(pid_t pid, pid_t pgid); ErrorOr setsid(); ErrorOr drop_privileges(); ErrorOr isatty(int fd); +ErrorOr link(StringView old_path, StringView new_path); ErrorOr symlink(StringView target, StringView link_path); ErrorOr mkdir(StringView path, mode_t); ErrorOr chdir(StringView path);