ladybird/Userland/Utilities/readlink.cpp

33 lines
829 B
C++
Raw Normal View History

2020-06-16 22:03:19 +03:00
/*
* Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
2020-06-16 22:03:19 +03:00
*/
#include <LibCore/ArgsParser.h>
#include <LibCore/DeprecatedFile.h>
2022-03-23 19:12:49 +03:00
#include <LibCore/System.h>
#include <LibMain/Main.h>
2020-06-16 22:03:19 +03:00
2022-03-23 19:12:49 +03:00
ErrorOr<int> serenity_main(Main::Arguments arguments)
2020-06-16 22:03:19 +03:00
{
2022-03-23 19:12:49 +03:00
TRY(Core::System::pledge("stdio rpath"));
2020-06-16 22:03:19 +03:00
bool no_newline = false;
Vector<StringView> paths;
2020-06-16 22:03:19 +03: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 19:12:49 +03:00
args_parser.parse(arguments);
2020-06-16 22:03:19 +03:00
for (auto path : paths) {
auto destination = TRY(Core::DeprecatedFile::read_link(path));
out("{}", destination);
2020-06-16 22:03:19 +03:00
if (!no_newline)
outln();
2020-06-16 22:03:19 +03:00
}
return 0;
}