stdio broken in SysV?

Rob Warnock rpw3 at rigden.wpd.sgi.com
Sat Feb 24 17:08:28 AEST 1990


In article <2010 at sauron.Columbia.NCR.COM> wescott at micky.columbia.ncr.com
(Mike Wescott) writes:
+---------------
| I am trying to port a program.  It blows up in fprintf because SysV stdio
| has the implicit assumption that a given file descriptor will be used by
| no more than one stdio stream.  Which is broken? The program that does:
| 		fpin = fdopen(fd,"r");
| 		fpot = fdopen(fd,"w");
| Or the stdio that blows up in memcpy() called from doprnt() called by
| fprintf() in the same program?
+---------------

This is a well-known problem to anyone who has ported any Berkeley networking
applications to System V. IMHO, Sys5's broken, but it's that way in all the
S5R2's I've seen. (Did it make it into S5R3? Will it still be there in S5R4?)

+---------------
| BTW the "implicit assumption" mentioned above is due to the fact that
| the array _bufendtab[] is indexed by fp->_file rather than by fp-_iob
| or built into the FILE structure itself.
+---------------

Your diagnosis is exactly correct. On the other hand, Berkeley Unix stores
the bufend pointers in the FILE struct (no problem).

By the way, a simple workaround for this problem (*hack* *hack*) is:

 		fpin = fdopen(fd,"r");
 		fpot = fdopen(dup(fd),"w");

-Rob


-----
Rob Warnock, MS-9U/510		rpw3 at sgi.com		rpw3 at pei.com
Silicon Graphics, Inc.		(415)335-1673		Protocol Engines, Inc.
2011 N. Shoreline Blvd.
Mountain View, CA  94039-7311



More information about the Comp.unix.wizards mailing list