Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libc/src/__support/File/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ FileIOResult File::write_unlocked_fbf(const uint8_t *data, size_t len) {

FileIOResult result =
platform_write(this, remainder.data(), remainder.size());
size_t bytes_written = buf_result.value;
size_t bytes_written = result.value;

// If less bytes were written than expected, then an error occurred. Return
// the number of bytes that have been written from |data|.
Expand Down
18 changes: 18 additions & 0 deletions libc/test/src/__support/File/file_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,21 @@ TEST(LlvmLibcFileTest, WriteNothing) {
ASSERT_EQ(f_lbf->close(), 0);
ASSERT_EQ(f_nbf->close(), 0);
}

TEST(LlvmLibcFileTest, WriteSplit) {
constexpr size_t FILE_BUFFER_SIZE = 8;
char file_buffer[FILE_BUFFER_SIZE];
StringFile *f =
new_string_file(file_buffer, FILE_BUFFER_SIZE, _IOFBF, false, "w");

static constexpr size_t AVAIL = 12;
f->seek(-AVAIL, SEEK_END);

const char data[] = "hello";
ASSERT_EQ(sizeof(data) - 1, f->write(data, sizeof(data) - 1).value);

const char data2[] = " extra data";
static constexpr size_t WR_EXPECTED = AVAIL - (sizeof(data) - 1);
ASSERT_EQ(WR_EXPECTED, f->write(data2, sizeof(data2) - 1).value);
EXPECT_TRUE(f->error());
}
Loading