mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:24:57 +00:00
readlink: Port to LibMain
This commit is contained in:
parent
4a57be824c
commit
45ac5e90b7
2 changed files with 7 additions and 15 deletions
|
@ -170,6 +170,7 @@ target_link_libraries(ps LibMain)
|
|||
target_link_libraries(purge LibMain)
|
||||
target_link_libraries(pwd LibMain)
|
||||
target_link_libraries(readelf LibMain)
|
||||
target_link_libraries(readlink LibMain)
|
||||
target_link_libraries(realpath LibMain)
|
||||
target_link_libraries(reboot LibMain)
|
||||
target_link_libraries(rev LibMain)
|
||||
|
|
|
@ -6,15 +6,12 @@
|
|||
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibMain/Main.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
if (pledge("stdio rpath", nullptr) < 0) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
}
|
||||
TRY(Core::System::pledge("stdio rpath"));
|
||||
|
||||
bool no_newline = false;
|
||||
Vector<const char*> paths;
|
||||
|
@ -22,16 +19,10 @@ int main(int argc, char** argv)
|
|||
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);
|
||||
args_parser.parse(arguments);
|
||||
|
||||
for (const char* path : paths) {
|
||||
auto destination_or_error = Core::File::read_link(path);
|
||||
if (destination_or_error.is_error()) {
|
||||
perror(path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto destination = destination_or_error.release_value();
|
||||
auto destination = TRY(Core::File::read_link(path));
|
||||
out("{}", destination);
|
||||
if (!no_newline)
|
||||
outln();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue