[libc-commits] [libc] [libc] Support dynamically-grown lines in FlatFileDatabase (PR #223811)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Wed Sep 16 12:01:37 PDT 2026


================
@@ -189,6 +319,52 @@ template <typename EntryType> class FlatFileDatabase {
     if (!res.has_value())
       return Error(res.error());
 
+    ScopedDynamicBuffer scratch_buf;
+    while (true) {
+      auto next_res = getnext(entry, buffer);
+      if (next_res.has_value()) {
+        if (!next_res.value())
+          return false; // EOF without match
+        if (matcher(*entry))
+          return true;
+        continue;
+      }
+
+      if (next_res.error() != ERANGE)
+        return Error(next_res.error());
+
+      // The record at last_line_start exceeded buffer. Check whether it is
----------------
kaladron wrote:

I turned to Gemini for the other-libc analysis as I don't want to accidentally reference glibc source code.

glibc and FreeBSD follows option c, and they expect the caller's ERANGE handler to double the buffer and retry.

musl does option the same as us, and internally reallocs.

Looking at these, this is a good simplfication.  I'll make the change.

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


More information about the libc-commits mailing list