2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2020-08-05 21:36:42 +03:00
|
|
|
#include <LibCore/ArgsParser.h>
|
2022-02-09 13:43:21 +03:00
|
|
|
#include <LibCore/System.h>
|
|
|
|
#include <LibMain/Main.h>
|
2019-08-25 19:17:47 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2022-02-09 13:43:21 +03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2019-08-25 19:17:47 +03:00
|
|
|
{
|
2022-02-09 13:43:21 +03:00
|
|
|
TRY(Core::System::pledge("stdio rpath"));
|
2020-02-18 15:29:18 +03:00
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
char const* path;
|
2020-08-05 21:36:42 +03:00
|
|
|
|
|
|
|
Core::ArgsParser args_parser;
|
2020-12-05 18:22:58 +03:00
|
|
|
args_parser.set_general_help(
|
|
|
|
"Show the 'real' path of a file, by resolving all symbolic links along the way.");
|
2020-08-05 21:36:42 +03:00
|
|
|
args_parser.add_positional_argument(path, "Path to resolve", "path");
|
2022-02-09 13:43:21 +03:00
|
|
|
args_parser.parse(arguments);
|
2019-08-25 19:17:47 +03:00
|
|
|
|
2020-08-05 21:36:42 +03:00
|
|
|
char* value = realpath(path, nullptr);
|
2019-08-25 19:17:47 +03:00
|
|
|
if (value == nullptr) {
|
2020-08-05 21:36:42 +03:00
|
|
|
perror("realpath");
|
2019-08-25 19:17:47 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2021-05-31 17:43:25 +03:00
|
|
|
outln("{}", value);
|
2019-08-25 19:17:47 +03:00
|
|
|
free(value);
|
|
|
|
return 0;
|
|
|
|
}
|