Serenity Operating System
at master 33 lines 835 B view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <LibCore/ArgsParser.h> 8#include <LibCore/System.h> 9#include <LibMain/Main.h> 10#include <stdio.h> 11#include <unistd.h> 12 13ErrorOr<int> serenity_main(Main::Arguments arguments) 14{ 15 TRY(Core::System::pledge("stdio rpath")); 16 17 DeprecatedString path; 18 19 Core::ArgsParser args_parser; 20 args_parser.set_general_help( 21 "Show the 'real' path of a file, by resolving all symbolic links along the way."); 22 args_parser.add_positional_argument(path, "Path to resolve", "path"); 23 args_parser.parse(arguments); 24 25 char* value = realpath(path.characters(), nullptr); 26 if (value == nullptr) { 27 perror("realpath"); 28 return 1; 29 } 30 outln("{}", value); 31 free(value); 32 return 0; 33}