summaryrefslogtreecommitdiff
path: root/Userland/ls.cpp
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@serenityos.org>2020-06-16 22:01:50 +0300
committerAndreas Kling <kling@serenityos.org>2020-06-17 15:02:03 +0200
commiteb7af001526a93b2aebf80cac148acceca6e579f (patch)
tree6b62ce01d69e66ec13806a14995f3f70c9b90374 /Userland/ls.cpp
parentd89843f96fa7673f409bb8c33e043e2355b257f1 (diff)
downloadserenity-eb7af001526a93b2aebf80cac148acceca6e579f.zip
Userland: Use Core::File::read_link()
Diffstat (limited to 'Userland/ls.cpp')
-rw-r--r--Userland/ls.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/Userland/ls.cpp b/Userland/ls.cpp
index 0e369d900e..c4f2fb1bf5 100644
--- a/Userland/ls.cpp
+++ b/Userland/ls.cpp
@@ -33,6 +33,7 @@
#include <LibCore/ArgsParser.h>
#include <LibCore/DateTime.h>
#include <LibCore/DirIterator.h>
+#include <LibCore/File.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
@@ -208,13 +209,11 @@ size_t print_name(const struct stat& st, const String& name, const char* path_fo
}
if (S_ISLNK(st.st_mode)) {
if (path_for_link_resolution) {
- char linkbuf[PATH_MAX];
- ssize_t nread = readlink(path_for_link_resolution, linkbuf, sizeof(linkbuf) - 1);
- if (nread < 0) {
- perror("readlink failed");
+ auto link_destination = Core::File::read_link(path_for_link_resolution);
+ if (link_destination.is_null()) {
+ perror("readlink");
} else {
- linkbuf[nread] = '\0';
- nprinted += printf(" -> ") + print_escaped(linkbuf);
+ nprinted += printf(" -> ") + print_escaped(link_destination.characters());
}
} else {
nprinted += printf("@");