diff options
author | Andreas Kling <kling@serenityos.org> | 2021-02-02 19:49:24 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-02 20:13:44 +0100 |
commit | d57b4128a194066a03a3224473463d7756ade3f7 (patch) | |
tree | 3d4ba7a49f8294effecde785d4e9263b4269ae75 | |
parent | 1658df9b6e7441c49db005ea5812bbc10a562818 (diff) | |
download | serenity-d57b4128a194066a03a3224473463d7756ade3f7.zip |
LibCore: Use serenity_readlink() instead of making syscalls directly
-rw-r--r-- | Userland/Libraries/LibCore/File.cpp | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/Userland/Libraries/LibCore/File.cpp b/Userland/Libraries/LibCore/File.cpp index 991b15c834..44ba8d41d7 100644 --- a/Userland/Libraries/LibCore/File.cpp +++ b/Userland/Libraries/LibCore/File.cpp @@ -26,6 +26,7 @@ #ifdef __serenity__ # include <Kernel/API/Syscall.h> +# include <serenity.h> #endif #include <AK/ScopeGuard.h> #include <LibCore/File.h> @@ -172,15 +173,11 @@ String File::read_link(const StringView& link_path) { // First, try using a 64-byte buffer, that ought to be enough for anybody. char small_buffer[64]; - Syscall::SC_readlink_params small_params { - { link_path.characters_without_null_termination(), link_path.length() }, - { small_buffer, sizeof(small_buffer) } - }; - int rc = syscall(SC_readlink, &small_params); - if (rc < 0) { - errno = -rc; + + int rc = serenity_readlink(link_path.characters_without_null_termination(), link_path.length(), small_buffer, sizeof(small_buffer)); + if (rc < 0) return {}; - } + size_t size = rc; // If the call was successful, the syscall (unlike the LibC wrapper) // returns the full size of the link. Let's see if our small buffer @@ -190,15 +187,11 @@ String File::read_link(const StringView& link_path) // Nope, but at least now we know the right size. char* large_buffer_ptr; auto large_buffer = StringImpl::create_uninitialized(size, large_buffer_ptr); - Syscall::SC_readlink_params large_params { - { link_path.characters_without_null_termination(), link_path.length() }, - { large_buffer_ptr, (size_t)size } - }; - rc = syscall(SC_readlink, &large_params); - if (rc < 0) { - errno = -rc; + + rc = serenity_readlink(link_path.characters_without_null_termination(), link_path.length(), large_buffer_ptr, size); + if (rc < 0) return {}; - } + size_t new_size = rc; if (new_size == size) return { *large_buffer }; |