From 86781f0c085c607c9e22cbab8e929ea6bb2ad320 Mon Sep 17 00:00:00 2001 From: Cameron Youell Date: Mon, 27 Mar 2023 00:39:52 +0000 Subject: [PATCH] Documentation: Update `readlink.md` to use `LibFileSystem` api --- Base/usr/share/man/man2/readlink.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Base/usr/share/man/man2/readlink.md b/Base/usr/share/man/man2/readlink.md index e4c7c24e62..a4845198f6 100644 --- a/Base/usr/share/man/man2/readlink.md +++ b/Base/usr/share/man/man2/readlink.md @@ -26,12 +26,12 @@ and sets `errno` to describe the error. ## Notes The underlying system call always returns the full size of the target path on -success, not the number of bytes written. `Core::DeprecatedFile::read_link()` makes use +success, not the number of bytes written. `FileSystem::read_link()` makes use of this to provide an alternative way to read links that doesn't require the caller to pick a buffer size and allocate a buffer straight up. Since it's essentially impossible to guess the right buffer size for reading -links, it's strongly recommended that everything uses `Core::DeprecatedFile::read_link()` +links, it's strongly recommended that everything uses `FileSystem::read_link()` instead. ## Examples @@ -40,7 +40,7 @@ The following example demonstrates how one could implement an alternative version of `getpid(2)` which reads the calling process ID from ProcFS: ```c++ -#include +#include #include pid_t read_pid_using_readlink() @@ -53,11 +53,9 @@ pid_t read_pid_using_readlink() return atoi(buffer); } -pid_t read_pid_using_core_file() +ErrorOr read_pid_using_core_file() { - auto target = Core::DeprecatedFile::read_link("/proc/self"); - if (target.is_null()) - return -1; + auto target = TRY(File::read_link("/proc/self"sv)); auto pid = target.to_uint(); ASSERT(pid.has_value()); return pid.value();