ladybird/Userland/Utilities/readlink.cpp

33 lines
821 B
C++
Raw Normal View History

2020-06-16 19:03:19 +00:00
/*
* Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
2020-06-16 19:03:19 +00:00
*/
#include <LibCore/ArgsParser.h>
2022-03-23 16:12:49 +00:00
#include <LibCore/System.h>
#include <LibFileSystem/FileSystem.h>
2022-03-23 16:12:49 +00:00
#include <LibMain/Main.h>
2020-06-16 19:03:19 +00:00
2022-03-23 16:12:49 +00:00
ErrorOr<int> serenity_main(Main::Arguments arguments)
2020-06-16 19:03:19 +00:00
{
2022-03-23 16:12:49 +00:00
TRY(Core::System::pledge("stdio rpath"));
2020-06-16 19:03:19 +00:00
bool no_newline = false;
Vector<StringView> paths;
2020-06-16 19:03:19 +00:00
Core::ArgsParser args_parser;
args_parser.add_option(no_newline, "Do not append a newline", "no-newline", 'n');
args_parser.add_positional_argument(paths, "Symlink path", "path");
2022-03-23 16:12:49 +00:00
args_parser.parse(arguments);
2020-06-16 19:03:19 +00:00
for (auto path : paths) {
auto destination = TRY(FileSystem::read_link(path));
out("{}", destination);
2020-06-16 19:03:19 +00:00
if (!no_newline)
outln();
2020-06-16 19:03:19 +00:00
}
return 0;
}