[libc-commits] [libc] [libc] Support _IONBF buffering for read_unlocked (PR #120677)
Jack Huang via libc-commits
libc-commits at lists.llvm.org
Mon Jan 6 22:50:22 PST 2025
================
@@ -209,12 +220,22 @@ FileIOResult File::read_unlocked(void *data, size_t len) {
for (size_t i = 0; i < available_data; ++i)
dataref[i] = bufref[i + pos];
read_limit = pos = 0; // Reset the pointers.
+
+ return available_data;
+}
+
+FileIOResult File::read_unlocked_fbf(uint8_t *data, size_t len) {
+ // Read data from the buffer first.
+ size_t available_data = copy_data_from_buf(data, len);
+ if (available_data == len)
+ return available_data;
+
// Update the dataref to reflect that fact that we have already
// copied |available_data| into |data|.
- dataref = cpp::span<uint8_t>(dataref.data() + available_data,
- dataref.size() - available_data);
-
size_t to_fetch = len - available_data;
+ cpp::span<uint8_t> dataref(static_cast<uint8_t *>(data) + available_data,
+ to_fetch);
+
if (to_fetch > bufsize) {
auto result = platform_read(this, dataref.data(), to_fetch);
size_t fetched_size = result.value;
----------------
jackhong12 wrote:
Got it. I also change the line 286 from `result.has_error()` to `result.error`. I think it has the same problem.
https://github.com/llvm/llvm-project/pull/120677
More information about the libc-commits
mailing list