[Accessibility] Portability of file descriptors and C streams

Samuel Thibault samuel.thibault at ens-lyon.org
Tue Jan 18 14:51:52 GMT 2005


Ronald S. Bultje, le mar 18 jan 2005 15:08:55 +0100, a dit :
> On Tue, 2005-01-18 at 13:59, Samuel Thibault wrote:
> > People may then very well use C streams over those file descriptors
> > (thanks to fdopen()) or whatever advanced stream in whatever langage,
> > provided they care about flushing (fflush()).
> 
> You mean fdatasync()? :).

No: that's the work of the operating system to get sure that file
descriptors' data is flushed shortly. When using C streams on top of
file descriptor, you have some trouble if you don't call fflush() as
appropriate:

int fd;
FILE *file;
fd=open(...)
file=fdopen(fd,...);

compare:

fprintf(file,"foo");
write(fd,"bar",3);

and

fprintf(file,"foo");
fflush(file);
write(fd,"bar",3);

In the first case, bar will often be written before foo, because fprintf
wouldn't always flush its output. In the second case, bar is always
written after foo, since fflush() asserts that FILE's buffer were
flushed before write() is done.

Regards,
Samuel



More information about the kde-multimedia mailing list