3 ms·
How I think it should work: associate with each file descriptor (or should I say file handle / struct file) a “buffering” state, initially blank, with IOCTLs to
by skissane 4y ago
How I think it should work: associate with each file descriptor (or should I say file handle / struct file) a “buffering” state, initially blank, with IOCTLs to get/set it. In the stdio implementation, call the get IOCTL at startup on stdin/stdout/stderr, and also on any fdopen. If get IOCTL returns non-blank buffering settings, stdio adopts them for the FILE* pointing to that fd.
Advantages: No mucking around with LD_PRELOAD and associated security-related restrictions. Even works for static binaries, so long as they are linked with a stdio which supports this feature (and running under a kernel with that IOCTL).
(Actually, I was thinking you could even have an IOCTL to get/set arbitrary metadata attributes on a file handle - unlike xattrs, this would only be for each opening of the file, not the file on disk. As well as controlling stdio buffering, one can imagine other potential uses - for example, content type negotiation in pipelines.)