A bunch of protocols (git, http, mbox, etc) start with lines of data followed by
a block of data, so it's natural to want to call getline() and then handle the
data block. But getline() takes a FILE * and things like zlib and sendfile()
take an integer file descriptor.

Posix lets me get the file descriptor out of a FILE * with fileno(), but the
point of FILE * is to readahead and buffer. How do I get the buffered data out
without reading more from the file descriptor?

I can't find a portable way to do this?

In musl I can #include <stdio_ext.h> and then use __freadahead(fp) to get the
number of bytes. Various other packages do an if/else staircase mucking with the
internals of every libc they personally know, ala:

https://sources.debian.org/src/m4/1.4.18-2/lib/freadahead.c

But I can't find a portable way to do this?

Rob

Reply via email to