summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormjz19910 <matthias291999@gmail.com>2022-01-03 22:15:52 -0700
committerBrian Gianforcaro <b.gianfo@gmail.com>2022-01-04 07:33:23 +0000
commit7f9bd34d07a1f2c96299b9596d71574b5580f36d (patch)
tree8e09fdc9a8224da3556b037dcf62cd74de25d2d4
parentfc78bbe78cdbefa07d70e99985de311db28caa18 (diff)
downloadserenity-7f9bd34d07a1f2c96299b9596d71574b5580f36d.zip
wc: Port to LibMain
-rw-r--r--Userland/Utilities/CMakeLists.txt1
-rw-r--r--Userland/Utilities/wc.cpp15
2 files changed, 6 insertions, 10 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt
index 3f62f9860d..9203f2d4ed 100644
--- a/Userland/Utilities/CMakeLists.txt
+++ b/Userland/Utilities/CMakeLists.txt
@@ -162,6 +162,7 @@ target_link_libraries(cpp-parser LibCpp LibGUI)
target_link_libraries(cpp-preprocessor LibCpp LibGUI)
target_link_libraries(w LibMain)
target_link_libraries(wasm LibWasm LibLine)
+target_link_libraries(wc LibMain)
target_link_libraries(which LibMain)
target_link_libraries(whoami LibMain)
target_link_libraries(watch LibMain)
diff --git a/Userland/Utilities/wc.cpp b/Userland/Utilities/wc.cpp
index dc36e768c5..c0270d21f9 100644
--- a/Userland/Utilities/wc.cpp
+++ b/Userland/Utilities/wc.cpp
@@ -8,6 +8,7 @@
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibCore/ArgsParser.h>
+#include <LibCore/System.h>
#include <ctype.h>
#include <stdio.h>
#include <sys/stat.h>
@@ -85,12 +86,9 @@ static Count get_total_count(const Vector<Count>& counts)
return total_count;
}
-int main(int argc, char** argv)
+ErrorOr<int> serenity_main(Main::Arguments arguments)
{
- if (pledge("stdio rpath", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(Core::System::pledge("stdio rpath"));
Vector<const char*> file_specifiers;
@@ -99,7 +97,7 @@ int main(int argc, char** argv)
args_parser.add_option(g_output_byte, "Output byte count", "bytes", 'c');
args_parser.add_option(g_output_word, "Output word count", "words", 'w');
args_parser.add_positional_argument(file_specifiers, "File to process", "file", Core::ArgsParser::Required::No);
- args_parser.parse(argc, argv);
+ args_parser.parse(arguments);
if (!g_output_line && !g_output_byte && !g_output_word)
g_output_line = g_output_byte = g_output_word = true;
@@ -108,10 +106,7 @@ int main(int argc, char** argv)
for (const auto& file_specifier : file_specifiers)
counts.append(get_count(file_specifier));
- if (pledge("stdio", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(Core::System::pledge("stdio"));
if (file_specifiers.is_empty())
counts.append(get_count("-"));