[phobos] escaping FILE's buffering tyranny

Lars Tandle Kyllingstad lars at kyllingen.net
Sat Sep 11 01:23:31 PDT 2010


On Fri, 2010-09-10 at 11:11 -0500, Andrei Alexandrescu wrote:
> I looked a bit yesterday into figuring out to better control FILE's 
> buffering behavior. The problem is unpleasant enough that Lars had to 
> define a whole separate type UnbufferedFile.
> 
> Background: FILE has only setbuf() (uninteresting) and setvbuf() to 
> control buffering. There's no getvbuf() or generally any way to query 
> what buffering mode and what buffer size has been set etc.
> 
> I've been looking at the actual definition of the FILE structure and it 
> turns out it is possible (and quite easily) to define query functions 
> that have OS-independent signatures and OS-dependent implementation.
> 
> This doesn't add much to the system-specific implementation because the 
> FILE structure itself (which stores information regarding buffering 
> etc.) is already defined in a system-specific manner in core.stdc.stdio.


How standardised is the FILE structure?  Are we sure it's the same
across different C stdlibs on the various platforms?  (Or is D defined
to work only with GNU's C library on POSIX, like it is with DMC on
Windows?)

-Lars



More information about the phobos mailing list