summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorFabian INGREMEAU <fabian.ingremeau@outlook.com>2022-01-23 18:08:44 +0100
committerBrian Gianforcaro <b.gianfo@gmail.com>2022-01-25 00:11:14 +0000
commitdaf7f72ff36f56886ebcf4d61397dab4f69cc9f1 (patch)
tree7217209878c1c2e0afc5267cef83e63c77125cf5 /Userland
parent96db8a061bbfa0a56ad7d5ef1b0b32e2e83089b1 (diff)
downloadserenity-daf7f72ff36f56886ebcf4d61397dab4f69cc9f1.zip
tail: Port to LibMain
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Utilities/CMakeLists.txt1
-rw-r--r--Userland/Utilities/tail.cpp24
2 files changed, 8 insertions, 17 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt
index 9c530e78aa..f46251b48d 100644
--- a/Userland/Utilities/CMakeLists.txt
+++ b/Userland/Utilities/CMakeLists.txt
@@ -157,6 +157,7 @@ target_link_libraries(stat LibMain)
target_link_libraries(strace LibMain)
target_link_libraries(tac LibMain)
target_link_libraries(su LibCrypt LibMain)
+target_link_libraries(tail LibMain)
target_link_libraries(tar LibArchive LibCompress)
target_link_libraries(telws LibProtocol LibLine)
target_link_libraries(test-fuzz LibCore LibGemini LibGfx LibHTTP LibIPC LibJS LibMarkdown LibShell)
diff --git a/Userland/Utilities/tail.cpp b/Userland/Utilities/tail.cpp
index cb668801ac..5e0d7ae458 100644
--- a/Userland/Utilities/tail.cpp
+++ b/Userland/Utilities/tail.cpp
@@ -6,7 +6,8 @@
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
-#include <stdio.h>
+#include <LibCore/System.h>
+#include <LibMain/Main.h>
#include <stdlib.h>
#include <unistd.h>
@@ -71,12 +72,9 @@ static off_t find_seek_pos(Core::File& file, int wanted_lines)
return pos;
}
-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"));
bool follow = false;
int line_count = DEFAULT_LINE_COUNT;
@@ -87,18 +85,10 @@ int main(int argc, char* argv[])
args_parser.add_option(follow, "Output data as it is written to the file", "follow", 'f');
args_parser.add_option(line_count, "Fetch the specified number of lines", "lines", 'n', "number");
args_parser.add_positional_argument(file, "File path", "file");
- args_parser.parse(argc, argv);
-
- auto f = Core::File::construct(file);
- if (!f->open(Core::OpenMode::ReadOnly)) {
- warnln("Failed to open {}: {}", f->name(), f->error_string());
- exit(1);
- }
+ args_parser.parse(arguments);
- if (pledge("stdio", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ auto f = TRY(Core::File::open(file, Core::OpenMode::ReadOnly));
+ TRY(Core::System::pledge("stdio"));
auto pos = find_seek_pos(*f, line_count);
return tail_from_pos(*f, pos, follow);