summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-09-14 17:36:26 +0100
committerLinus Groh <mail@linusgroh.de>2022-11-19 17:00:10 +0000
commit8d798c27164f4321ed9882f699173aef6df85aa4 (patch)
tree2b7e0cc605c1e4dea385557565cb62b8ec72ec83
parent6d7435d25186f2c20eff1b4a4f14c415c753f651 (diff)
downloadserenity-8d798c27164f4321ed9882f699173aef6df85aa4.zip
utmpupdate: Port to Core::Stream
-rw-r--r--Userland/Utilities/utmpupdate.cpp23
1 files changed, 6 insertions, 17 deletions
diff --git a/Userland/Utilities/utmpupdate.cpp b/Userland/Utilities/utmpupdate.cpp
index a54a7da84b..d91c6a1ce2 100644
--- a/Userland/Utilities/utmpupdate.cpp
+++ b/Userland/Utilities/utmpupdate.cpp
@@ -10,7 +10,7 @@
#include <AK/JsonValue.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/DateTime.h>
-#include <LibCore/File.h>
+#include <LibCore/Stream.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
#include <unistd.h>
@@ -42,9 +42,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
dbgln("Updating utmp from UID={} GID={} EGID={} PID={}", getuid(), getgid(), getegid(), pid);
- auto file = TRY(Core::File::open("/var/run/utmp", Core::OpenMode::ReadWrite));
+ auto file = TRY(Core::Stream::File::open("/var/run/utmp"sv, Core::Stream::OpenMode::ReadWrite));
- auto file_contents = file->read_all();
+ auto file_contents = TRY(file->read_all());
auto previous_json = TRY(JsonValue::from_string(file_contents));
JsonObject json;
@@ -70,20 +70,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
json.remove(tty_name);
}
- if (!file->seek(0)) {
- dbgln("Seek failed");
- return 1;
- }
-
- if (!file->truncate(0)) {
- dbgln("Truncation failed");
- return 1;
- }
-
- if (!file->write(json.to_string())) {
- dbgln("Write failed");
- return 1;
- }
+ TRY(file->seek(0, Core::Stream::SeekMode::SetPosition));
+ TRY(file->truncate(0));
+ TRY(file->write(json.to_string().bytes()));
return 0;
}