mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:07:36 +00:00
tail: Port to LibMain
This commit is contained in:
parent
96db8a061b
commit
daf7f72ff3
2 changed files with 8 additions and 17 deletions
|
@ -157,6 +157,7 @@ target_link_libraries(stat LibMain)
|
||||||
target_link_libraries(strace LibMain)
|
target_link_libraries(strace LibMain)
|
||||||
target_link_libraries(tac LibMain)
|
target_link_libraries(tac LibMain)
|
||||||
target_link_libraries(su LibCrypt LibMain)
|
target_link_libraries(su LibCrypt LibMain)
|
||||||
|
target_link_libraries(tail LibMain)
|
||||||
target_link_libraries(tar LibArchive LibCompress)
|
target_link_libraries(tar LibArchive LibCompress)
|
||||||
target_link_libraries(telws LibProtocol LibLine)
|
target_link_libraries(telws LibProtocol LibLine)
|
||||||
target_link_libraries(test-fuzz LibCore LibGemini LibGfx LibHTTP LibIPC LibJS LibMarkdown LibShell)
|
target_link_libraries(test-fuzz LibCore LibGemini LibGfx LibHTTP LibIPC LibJS LibMarkdown LibShell)
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <stdio.h>
|
#include <LibCore/System.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -71,12 +72,9 @@ static off_t find_seek_pos(Core::File& file, int wanted_lines)
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
if (pledge("stdio rpath", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio rpath"));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool follow = false;
|
bool follow = false;
|
||||||
int line_count = DEFAULT_LINE_COUNT;
|
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(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_option(line_count, "Fetch the specified number of lines", "lines", 'n', "number");
|
||||||
args_parser.add_positional_argument(file, "File path", "file");
|
args_parser.add_positional_argument(file, "File path", "file");
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
auto f = Core::File::construct(file);
|
auto f = TRY(Core::File::open(file, Core::OpenMode::ReadOnly));
|
||||||
if (!f->open(Core::OpenMode::ReadOnly)) {
|
TRY(Core::System::pledge("stdio"));
|
||||||
warnln("Failed to open {}: {}", f->name(), f->error_string());
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pledge("stdio", nullptr) < 0) {
|
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto pos = find_seek_pos(*f, line_count);
|
auto pos = find_seek_pos(*f, line_count);
|
||||||
return tail_from_pos(*f, pos, follow);
|
return tail_from_pos(*f, pos, follow);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue