diff options
author | Pedro Pereira <pmh.pereira@gmail.com> | 2021-11-22 22:29:16 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-22 23:44:55 +0100 |
commit | fb5ea617f1fdee05e81f9f3c284c405b11cb08f4 (patch) | |
tree | 7a37903ea31df689725aaa296b1cd8938289349f | |
parent | 6e6228d40d86a39ceeede0bd0a5c07d029885704 (diff) | |
download | serenity-fb5ea617f1fdee05e81f9f3c284c405b11cb08f4.zip |
2048: Port to LibMain
Simplified two pledge() and two unveil() by using TRY().
-rw-r--r-- | Userland/Games/2048/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Userland/Games/2048/main.cpp | 28 |
2 files changed, 9 insertions, 21 deletions
diff --git a/Userland/Games/2048/CMakeLists.txt b/Userland/Games/2048/CMakeLists.txt index e31191c05a..27bed755f7 100644 --- a/Userland/Games/2048/CMakeLists.txt +++ b/Userland/Games/2048/CMakeLists.txt @@ -12,4 +12,4 @@ set(SOURCES ) serenity_app(2048 ICON app-2048) -target_link_libraries(2048 LibConfig LibGUI) +target_link_libraries(2048 LibConfig LibGUI LibMain) diff --git a/Userland/Games/2048/main.cpp b/Userland/Games/2048/main.cpp index 7294f4b353..b428be3f74 100644 --- a/Userland/Games/2048/main.cpp +++ b/Userland/Games/2048/main.cpp @@ -19,40 +19,28 @@ #include <LibGUI/Statusbar.h> #include <LibGUI/Window.h> #include <LibGfx/Painter.h> +#include <LibMain/Main.h> +#include <LibSystem/Wrappers.h> #include <stdio.h> #include <time.h> -#include <unistd.h> -int main(int argc, char** argv) +ErrorOr<int> serenity_main(Main::Arguments arguments) { - if (pledge("stdio rpath recvfd sendfd unix", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(System::pledge("stdio rpath recvfd sendfd unix", nullptr)); srand(time(nullptr)); - auto app = GUI::Application::construct(argc, argv); + auto app = GUI::Application::construct(arguments.argc, arguments.argv); auto app_icon = GUI::Icon::default_icon("app-2048"); auto window = GUI::Window::construct(); Config::pledge_domains("2048"); - if (pledge("stdio rpath recvfd sendfd", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(System::pledge("stdio rpath recvfd sendfd", nullptr)); - if (unveil("/res", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } + TRY(System::unveil("/res", "r")); + TRY(System::unveil(nullptr, nullptr)); size_t board_size = Config::read_i32("2048", "", "board_size", 4); u32 target_tile = Config::read_i32("2048", "", "target_tile", 2048); |