1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 09:57:34 +00:00

Applets/Network: Port to Core::Stream

This commit is contained in:
Sam Atkins 2022-09-13 12:24:37 +01:00 committed by Brian Gianforcaro
parent 761f079a22
commit c8bfb07b41

View file

@ -5,7 +5,7 @@
*/ */
#include <LibCore/ArgsParser.h> #include <LibCore/ArgsParser.h>
#include <LibCore/File.h> #include <LibCore/Stream.h>
#include <LibCore/System.h> #include <LibCore/System.h>
#include <LibGUI/Action.h> #include <LibGUI/Action.h>
#include <LibGUI/Application.h> #include <LibGUI/Application.h>
@ -109,14 +109,19 @@ private:
{ {
StringBuilder adapter_info; StringBuilder adapter_info;
auto file = Core::File::construct("/proc/net/adapters"); auto file_or_error = Core::Stream::File::open("/proc/net/adapters"sv, Core::Stream::OpenMode::Read);
if (!file->open(Core::OpenMode::ReadOnly)) { if (file_or_error.is_error()) {
dbgln("Error: Could not open {}: {}", file->name(), file->error_string()); dbgln("Error: Could not open /proc/net/adapters: {}", file_or_error.error());
return adapter_info.to_string(); return "";
} }
auto file_contents = file->read_all(); auto file_contents_or_error = file_or_error.value()->read_all();
auto json = JsonValue::from_string(file_contents); if (file_contents_or_error.is_error()) {
dbgln("Error: Could not read /proc/net/adapters: {}", file_contents_or_error.error());
return "";
}
auto json = JsonValue::from_string(file_contents_or_error.value());
if (json.is_error()) if (json.is_error())
return adapter_info.to_string(); return adapter_info.to_string();