* fix io

* fix io

* comment
This commit is contained in:
Awni Hannun 2024-08-21 13:14:46 -07:00 committed by GitHub
parent d40e76809f
commit 8ae751d3da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -70,7 +70,7 @@ class FileReader : public Reader {
void read(char* data, size_t n) override { void read(char* data, size_t n) override {
while (n != 0) { while (n != 0) {
auto m = ::read(fd_, data, n); auto m = ::read(fd_, data, std::min(n, static_cast<size_t>(INT32_MAX)));
if (m <= 0) { if (m <= 0) {
std::ostringstream msg; std::ostringstream msg;
msg << "[read] Unable to read " << n << " bytes from file."; msg << "[read] Unable to read " << n << " bytes from file.";
@ -123,7 +123,7 @@ class FileWriter : public Writer {
void write(const char* data, size_t n) override { void write(const char* data, size_t n) override {
while (n != 0) { while (n != 0) {
auto m = ::write(fd_, data, n); auto m = ::write(fd_, data, std::min(n, static_cast<size_t>(INT32_MAX)));
if (m <= 0) { if (m <= 0) {
std::ostringstream msg; std::ostringstream msg;
msg << "[write] Unable to write " << n << " bytes to file."; msg << "[write] Unable to write " << n << " bytes to file.";