1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:37:44 +00:00

find: Port to LibMain

This commit is contained in:
Tim Schumacher 2021-11-23 12:32:41 +01:00 committed by Andreas Kling
parent c3c2fe153b
commit 4ca35ac1b8
2 changed files with 7 additions and 8 deletions

View file

@ -74,6 +74,7 @@ target_link_libraries(echo LibMain)
target_link_libraries(expr LibRegex) target_link_libraries(expr LibRegex)
target_link_libraries(fdtdump LibDeviceTree) target_link_libraries(fdtdump LibDeviceTree)
target_link_libraries(file LibGfx LibIPC LibCompress) target_link_libraries(file LibGfx LibIPC LibCompress)
target_link_libraries(find LibMain)
target_link_libraries(fortune LibMain) target_link_libraries(fortune LibMain)
target_link_libraries(functrace LibDebug LibX86) target_link_libraries(functrace LibDebug LibX86)
target_link_libraries(gml-format LibGUI) target_link_libraries(gml-format LibGUI)

View file

@ -10,6 +10,8 @@
#include <AK/NonnullOwnPtr.h> #include <AK/NonnullOwnPtr.h>
#include <AK/OwnPtr.h> #include <AK/OwnPtr.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
#include <dirent.h> #include <dirent.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
@ -563,17 +565,13 @@ static void walk_tree(FileData& root_data, Command& command)
closedir(dir); closedir(dir);
} }
int main(int argc, char* argv[]) ErrorOr<int> serenity_main(Main::Arguments arguments)
{ {
LexicalPath root_path(parse_options(argc, argv)); LexicalPath root_path(parse_options(arguments.argc, arguments.argv));
String dirname = root_path.dirname(); String dirname = root_path.dirname();
String basename = root_path.basename(); String basename = root_path.basename();
int dirfd = open(dirname.characters(), O_RDONLY | O_DIRECTORY | O_CLOEXEC); int dirfd = TRY(Core::System::open(dirname, O_RDONLY | O_DIRECTORY | O_CLOEXEC));
if (dirfd < 0) {
perror(dirname.characters());
return 1;
}
FileData file_data { FileData file_data {
root_path, root_path,
@ -583,7 +581,7 @@ int main(int argc, char* argv[])
false, false,
DT_UNKNOWN, DT_UNKNOWN,
}; };
auto command = parse_all_commands(argv); auto command = parse_all_commands(arguments.argv);
walk_tree(file_data, *command); walk_tree(file_data, *command);
close(dirfd); close(dirfd);
return g_there_was_an_error ? 1 : 0; return g_there_was_an_error ? 1 : 0;