diff options
author | alexmajor <5017286+alexmajor@users.noreply.github.com> | 2022-01-24 20:26:25 -0500 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2022-02-01 04:58:24 +0000 |
commit | 55496ab7fbf1e35c76e9fc9b4d591d24c0468a9a (patch) | |
tree | c66b2be1d63d320bae11ded233ec01ab4832fa4f | |
parent | 2f1717182e95433b6c065650f809d7b8df3bfcf4 (diff) | |
download | serenity-55496ab7fbf1e35c76e9fc9b4d591d24c0468a9a.zip |
shutdown: Port to LibMain
-rw-r--r-- | Userland/Utilities/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Utilities/shutdown.cpp | 21 |
2 files changed, 11 insertions, 11 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index e03f08c800..f04cf50568 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -160,6 +160,7 @@ target_link_libraries(rmdir LibMain) target_link_libraries(run-tests LibRegex LibCoredump) target_link_libraries(shot LibGUI LibMain) target_link_libraries(shuf LibMain) +target_link_libraries(shutdown LibMain) target_link_libraries(sql LibLine LibMain LibSQL LibIPC) target_link_libraries(sort LibMain) target_link_libraries(stat LibMain) diff --git a/Userland/Utilities/shutdown.cpp b/Userland/Utilities/shutdown.cpp index 80f724f4ce..130f74efa5 100644 --- a/Userland/Utilities/shutdown.cpp +++ b/Userland/Utilities/shutdown.cpp @@ -1,25 +1,24 @@ /* * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il> + * Copyright (c) 2022, Alex Major * * SPDX-License-Identifier: BSD-2-Clause */ +#include <LibCore/Stream.h> +#include <LibMain/Main.h> #include <fcntl.h> #include <stdio.h> #include <unistd.h> -int main(int, char**) +ErrorOr<int> serenity_main(Main::Arguments) { - int power_state_switch_node = open("/sys/firmware/power_state", O_WRONLY); - if (power_state_switch_node < 0) { - perror("open"); - return 1; - } - const char* value = "2"; - if (write(power_state_switch_node, value, 1) < 0) { - perror("write"); - return 1; - } + auto file = TRY(Core::Stream::File::open("/sys/firmware/power_state", Core::Stream::OpenMode::Write)); + + const String file_contents = "2"; + TRY(file->write(file_contents.bytes())); + file->close(); + return 0; } |