What happens if a replacement string happens to be split in the middle
by the fgets buffering? I think it'll fail to be replaced. This
applies to both versions.
In the stringinfo version it seemed to me that using pnstrdup is
possible to avoid copying trailing bytes.
If you're asking for opinion, mine is that StringInfo looks to be the
better approach, and also you don't need to keep API compatibility.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services