[libc-commits] [libc] [llvm] [libc] Fix FILE mutex, buffering (PR #238618)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Mon Nov 16 01:46:19 PST 2026


================
@@ -303,6 +304,28 @@ size_t File::copy_data_from_buf(uint8_t *data, size_t len) {
   return available_data;
 }
 
+FileIOResult File::read_from_platform(uint8_t *dst, size_t min_bytes,
+                                      size_t max_bytes) {
+  LIBC_ASSERT(min_bytes <= max_bytes);
+  size_t total_read = 0;
+  cpp::span<uint8_t> dstref(dst, max_bytes);
+  while (total_read < min_bytes) {
+    FileIOResult result = platform_read(this, dstref.data(), dstref.size());
+    size_t fetched_size = result.value;
+    LIBC_ASSERT(fetched_size <= dstref.size());
+    total_read += fetched_size;
+    if (result.has_error() || fetched_size == 0) {
+      if (!result.has_error())
----------------
labath wrote:

I see this is just copied, but I think it'd be easier to read if this condition is inverted (no double negation).

https://github.com/llvm/llvm-project/pull/238618


More information about the libc-commits mailing list