[libc-commits] [libc] [libc] Support dynamically-grown lines in FlatFileDatabase (PR #223811)
Alexey Samsonov via libc-commits
libc-commits at lists.llvm.org
Tue Sep 15 15:50:26 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
----------------
vonosmas wrote:
It's a bit sad that we necessarily trigger allocations even if we operate on a static buffers (from `<pwd.h>` functions) and the next line just ends up being too big. You mention above that this behavior is POSIX-compliant, do you know if other libc implementations are (a) doing the same, or (b) smart enough to distinguish malformed lines when they can't fit into the provided buffer, or (c) may return `ERANGE` where they don't need to.
https://github.com/llvm/llvm-project/pull/223811
More information about the libc-commits
mailing list