mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:48:11 +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(purge LibMain)
|
||||||
target_link_libraries(pwd LibMain)
|
target_link_libraries(pwd LibMain)
|
||||||
target_link_libraries(readelf LibMain)
|
target_link_libraries(readelf LibMain)
|
||||||
|
target_link_libraries(readlink LibMain)
|
||||||
target_link_libraries(realpath LibMain)
|
target_link_libraries(realpath LibMain)
|
||||||
target_link_libraries(reboot LibMain)
|
target_link_libraries(reboot LibMain)
|
||||||
target_link_libraries(rev LibMain)
|
target_link_libraries(rev LibMain)
|
||||||
|
|
|
@ -6,15 +6,12 @@
|
||||||
|
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <stdio.h>
|
#include <LibCore/System.h>
|
||||||
#include <unistd.h>
|
#include <LibMain/Main.h>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
if (pledge("stdio rpath", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio rpath"));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool no_newline = false;
|
bool no_newline = false;
|
||||||
Vector<const char*> paths;
|
Vector<const char*> paths;
|
||||||
|
@ -22,16 +19,10 @@ int main(int argc, char** argv)
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_option(no_newline, "Do not append a newline", "no-newline", 'n');
|
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.add_positional_argument(paths, "Symlink path", "path");
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
for (const char* path : paths) {
|
for (const char* path : paths) {
|
||||||
auto destination_or_error = Core::File::read_link(path);
|
auto destination = TRY(Core::File::read_link(path));
|
||||||
if (destination_or_error.is_error()) {
|
|
||||||
perror(path);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto destination = destination_or_error.release_value();
|
|
||||||
out("{}", destination);
|
out("{}", destination);
|
||||||
if (!no_newline)
|
if (!no_newline)
|
||||||
outln();
|
outln();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue