ladybird/Userland/Utilities/realpath.cpp

34 lines
817 B
C++
Raw Normal View History

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#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
const char* path;
Core::ArgsParser args_parser;
args_parser.set_general_help(
"Show the 'real' path of a file, by resolving all symbolic links along the way.");
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
char* value = realpath(path, nullptr);
2019-08-25 19:17:47 +03:00
if (value == nullptr) {
perror("realpath");
2019-08-25 19:17:47 +03:00
return 1;
}
outln("{}", value);
2019-08-25 19:17:47 +03:00
free(value);
return 0;
}