reboot: Port to LibMain

First commit to the project! :^)
This commit is contained in:
Wuzado 2022-03-03 23:51:39 +01:00 committed by Brian Gianforcaro
parent 58a865f349
commit 6302ca0043
Notes: sideshowbarker 2024-07-17 17:58:41 +09:00
2 changed files with 10 additions and 14 deletions

View file

@ -162,6 +162,7 @@ target_link_libraries(profile LibMain)
target_link_libraries(ps LibMain)
target_link_libraries(pwd LibMain)
target_link_libraries(realpath LibMain)
target_link_libraries(reboot LibMain)
target_link_libraries(rev LibMain)
target_link_libraries(rm LibMain)
target_link_libraries(rmdir LibMain)

View file

@ -5,21 +5,16 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <LibCore/Stream.h>
#include <LibMain/Main.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 = "1";
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 = "1";
TRY(file->write(file_contents.bytes()));
file->close();
return 0;
}