2020-06-16 22:03:19 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-16 22:03:19 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibCore/ArgsParser.h>
|
|
|
|
#include <LibCore/File.h>
|
|
|
|
#include <stdio.h>
|
2021-03-12 19:29:37 +03:00
|
|
|
#include <unistd.h>
|
2020-06-16 22:03:19 +03:00
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
if (pledge("stdio rpath", nullptr) < 0) {
|
|
|
|
perror("pledge");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool no_newline = false;
|
|
|
|
Vector<const char*> paths;
|
|
|
|
|
|
|
|
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");
|
|
|
|
args_parser.parse(argc, argv);
|
|
|
|
|
|
|
|
for (const char* path : paths) {
|
|
|
|
auto destination = Core::File::read_link(path);
|
|
|
|
if (destination.is_null()) {
|
|
|
|
perror(path);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
printf("%s", destination.characters());
|
|
|
|
if (!no_newline)
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|