[libc-commits] [libc] [libc] Add getc, ungetc, fflush to enable libc++ iostream on baremetal (PR #175530)

Volodymyr Turanskyy via libc-commits libc-commits at lists.llvm.org
Wed Jan 28 08:24:01 PST 2026


voltur01 wrote:

> we're treating `stdin` specially which may lead to inconsistent behavior

I tried not to create too much memory overhead and dependency on dynamic memory. What I can do is provide a fixed size map (a static array) to store ungetc state indexed by the cookie - this way it would work uniformly for all streams (within the capacity of the map).

> and I think we should consider introducing the embedding API for `ungetc` right away

Thinking a bit about this, I am afraid that creating extra API would make embedding harder, especially because there likely will be interaction between such new API for ungetc and existing reading API - reading will have to account for possible ungetc state.

>From this point of view, having the ungetc state and implementation in libc itself would be simpler, however may have limitation about how much data can be stored. This can be made into an extension point later, when fixed capacity becomes a problem.

The state can be stored in FILE itself as well, there may be a way to make it extensible this way, but this depends on the overall design for full FILE.

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


More information about the libc-commits mailing list