From cf207ad9388bdc3bb2ea539c121677f87606a57e Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Sun, 30 Jan 2022 19:37:08 +0100 Subject: [PATCH] mount: Use more StringView instead of const char* --- Userland/Utilities/mount.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Userland/Utilities/mount.cpp b/Userland/Utilities/mount.cpp index 60be5f5cc7..5943f91eaf 100644 --- a/Userland/Utilities/mount.cpp +++ b/Userland/Utilities/mount.cpp @@ -41,12 +41,12 @@ static int parse_options(StringView options) return flags; } -static bool is_source_none(const char* source) +static bool is_source_none(StringView source) { - return !strcmp("none", source); + return source == "none"sv; } -static int get_source_fd(const char* source) +static int get_source_fd(StringView source) { if (is_source_none(source)) return -1; @@ -84,16 +84,16 @@ static ErrorOr mount_all() continue; } - const char* mountpoint = parts[1].characters(); - const char* fstype = parts[2].characters(); + auto mountpoint = parts[1]; + auto fstype = parts[2]; int flags = parts.size() >= 4 ? parse_options(parts[3]) : 0; - if (strcmp(mountpoint, "/") == 0) { + if (mountpoint == "/") { dbgln("Skipping mounting root"); continue; } - const char* filename = parts[0].characters(); + auto filename = parts[0]; int fd = get_source_fd(filename); @@ -153,10 +153,10 @@ static ErrorOr print_mounts() ErrorOr serenity_main(Main::Arguments arguments) { - const char* source = nullptr; - const char* mountpoint = nullptr; - const char* fs_type = nullptr; - const char* options = nullptr; + StringView source; + StringView mountpoint; + StringView fs_type; + StringView options; bool should_mount_all = false; Core::ArgsParser args_parser; @@ -170,13 +170,13 @@ ErrorOr serenity_main(Main::Arguments arguments) if (should_mount_all) TRY(mount_all()); - if (!source && !mountpoint) + if (source.is_empty() && mountpoint.is_empty()) TRY(print_mounts()); - if (source && mountpoint) { - if (!fs_type) + if (!source.is_empty() && !mountpoint.is_empty()) { + if (fs_type.is_empty()) fs_type = "ext2"; - int flags = options ? parse_options(options) : 0; + int flags = !options.is_empty() ? parse_options(options) : 0; int fd = get_source_fd(source);