Serious bug in stdio on some ``System V'' derivatives

John Buck john at polyof.UUCP
Fri Oct 7 11:59:42 AEST 1988


Aside from the NOFILE vs. _NFILE size problems, fdopen() introduces
another little (possibly confusing) side effect to stdio.  Namely,

	fd = open("somefile", 2);
	...
	fp1 = fdopen(fd, "r");
	fp2 = fdopen(fd, "r+");

	Problem here is that fp1 and fp2 SHARE the same IO buffer, since
the way "stdio" determines the buffer is via the bufendtab[file_descriptor].
If two "file handles" (FILE *'s) are open to the same file descriptor,
buffer clashing will occur.

This is something to watch out for, because I have been stung by it a couple
of times.

john at polyof.poly.edu
john at polygraf.bitnet
john@[128.238.10.100]   (polyof.poly.edu)

trixie!polyof!john



More information about the Comp.bugs.sys5 mailing list