diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2023-03-01 00:11:43 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-03-01 10:47:19 +0100 |
commit | 500044906d1b90f1c8b1a2f5675a2f82ab92b758 (patch) | |
tree | 7d6aae259b188c1b6879c591eebdfd7f55d9b71c /Userland/Utilities/xargs.cpp | |
parent | 60908adcbe2afd611233957bb3126f736eb18e25 (diff) | |
download | serenity-500044906d1b90f1c8b1a2f5675a2f82ab92b758.zip |
LibCore+Everywhere: Remove ArgsParser::add*(char const*&)
This is not guaranteed to always work correctly as ArgsParser deals in
StringViews and might have a non-properly-null-terminated string as a
value. As a bonus, using StringView (and DeprecatedString where
necessary) leads to nicer looking code too :^)
Diffstat (limited to 'Userland/Utilities/xargs.cpp')
-rw-r--r-- | Userland/Utilities/xargs.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Userland/Utilities/xargs.cpp b/Userland/Utilities/xargs.cpp index a1afb74d87..cb7da7e58f 100644 --- a/Userland/Utilities/xargs.cpp +++ b/Userland/Utilities/xargs.cpp @@ -44,10 +44,10 @@ ErrorOr<int> serenity_main(Main::Arguments main_arguments) StringView placeholder; bool split_with_nulls = false; - char const* specified_delimiter = "\n"; + DeprecatedString specified_delimiter = "\n"sv; Vector<DeprecatedString> arguments; bool verbose = false; - char const* file_to_read = "-"; + DeprecatedString file_to_read = "-"sv; int max_lines_for_one_command = 0; int max_bytes_for_one_command = ARG_MAX; @@ -67,12 +67,12 @@ ErrorOr<int> serenity_main(Main::Arguments main_arguments) size_t max_bytes = min(ARG_MAX, max_bytes_for_one_command); size_t max_lines = max(max_lines_for_one_command, 0); - if (!split_with_nulls && strlen(specified_delimiter) > 1) { + if (!split_with_nulls && specified_delimiter.length() > 1) { warnln("xargs: the delimiter must be a single byte"); return 1; } - char entry_separator = split_with_nulls ? '\0' : *specified_delimiter; + char entry_separator = split_with_nulls ? '\0' : specified_delimiter[0]; if (!placeholder.is_empty()) max_lines = 1; @@ -87,7 +87,7 @@ ErrorOr<int> serenity_main(Main::Arguments main_arguments) if ("-"sv != file_to_read) { // A file was specified, try to open it. - fp = fopen(file_to_read, "re"); + fp = fopen(file_to_read.characters(), "re"); if (!fp) { perror("fopen"); return 1; |