On 4/16/22 2:58 PM, Rob Landley via austin-group-l at The Open Group wrote:
Q) "How do I switch from FILE * to fd via fileno() without losing data."

A) "Don't use FILE *"

That's not the question I asked?

The answer is correct, but incomplete. The missing piece is that if you
want to use FILE *, the operation you want, and the information you need to
implement it, are not part of the public API.

Other than using a strategy like Geoff suggested early on, or trying
something like setvbuf to turn off buffering on the FILE * completely, the
buffer associated with a FILE * and the indexes into it that say how much
data you've consumed from the underlying source are opaque. If you want to
manipulate that information, or expose it to a caller, you can't use FILE *
(or, if you want a direct answer, "you can't").

I found it easier to write my own buffered input package to satisfy the
POSIX read ahead requirements than try to coerce stdio into doing it.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/

Reply via email to