mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:54:58 +00:00
grep: Adapt maximum line size depending on file size
Otherwise, we would never stop trying to fetch new lines if the next newline is found beyond a range that the (default sized) buffer can hold.
This commit is contained in:
parent
ab794a199b
commit
c1004b095e
1 changed files with 10 additions and 1 deletions
|
@ -195,8 +195,17 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
|||
return false;
|
||||
}
|
||||
|
||||
auto file_size_or_error = Core::File::size(filename);
|
||||
if (file_size_or_error.is_error()) {
|
||||
if (!suppress_errors)
|
||||
warnln("Failed to retrieve size of {}: {}", filename, strerror(file_size_or_error.error().code()));
|
||||
return false;
|
||||
}
|
||||
|
||||
auto file_size = file_size_or_error.release_value();
|
||||
|
||||
for (size_t line_number = 1; file->can_read_line(); ++line_number) {
|
||||
auto line = file->read_line();
|
||||
auto line = file->read_line(file_size);
|
||||
auto is_binary = memchr(line.characters(), 0, line.length()) != nullptr;
|
||||
|
||||
if (matches(line, filename, line_number, print_filename, is_binary) && is_binary && binary_mode == BinaryFileMode::Binary)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue