Kernel: Shell fix file reading

We were reading 8 bytes at a time instead of the 1024 we were
supposed to :DD
This commit is contained in:
Bananymous 2023-04-19 14:09:23 +03:00
parent 51e299c7e3
commit cd03a95128
1 changed files with 7 additions and 4 deletions

View File

@ -561,11 +561,12 @@ argument_done:
int fd = TRY(Process::current().open(arguments[1], O_RDONLY)); int fd = TRY(Process::current().open(arguments[1], O_RDONLY));
BAN::ScopeGuard _([fd] { MUST(Process::current().close(fd)); }); BAN::ScopeGuard _([fd] { MUST(Process::current().close(fd)); });
char* buffer = new char[1024]; constexpr size_t buffer_size = 1024;
char* buffer = new char[buffer_size];
BAN::ScopeGuard buffer_guard([buffer] { delete[] buffer; }); BAN::ScopeGuard buffer_guard([buffer] { delete[] buffer; });
ASSERT(buffer); ASSERT(buffer);
while (size_t n_read = TRY(Process::current().read(fd, buffer, sizeof(buffer)))) while (size_t n_read = TRY(Process::current().read(fd, buffer, buffer_size)))
TTY_PRINT("{}", BAN::StringView(buffer, n_read)); TTY_PRINT("{}", BAN::StringView(buffer, n_read));
TTY_PRINTLN(""); TTY_PRINTLN("");
} }
@ -628,7 +629,9 @@ argument_done:
return {}; return {};
} }
uint8_t* buffer = new uint8_t[1024]; constexpr size_t buffer_size = 1024;
uint8_t* buffer = new uint8_t[buffer_size];
BAN::ScopeGuard buffer_guard([buffer] { delete[] buffer; }); BAN::ScopeGuard buffer_guard([buffer] { delete[] buffer; });
ASSERT(buffer); ASSERT(buffer);
@ -642,7 +645,7 @@ argument_done:
while (true) while (true)
{ {
size_t n_read = TRY(Process::current().read(fd, buffer, sizeof(buffer))); size_t n_read = TRY(Process::current().read(fd, buffer, buffer_size));
if (n_read == 0) if (n_read == 0)
break; break;
for (size_t j = 0; j < n_read; j++) for (size_t j = 0; j < n_read; j++)