Is Unix stdio slow?

Chris Torek chris at mimsy.UUCP
Wed Oct 5 01:22:03 AEST 1988


In article <26315 at ucbvax.BERKELEY.EDU> edward at ucbarpa.Berkeley.EDU
(Edward Wang) writes:
>I should point out that [Chris Torek's expansion] is not 4.3 putc().
>The real 4.3 putc looks like this
>
>#define putc(x, p)	(--(p)->_cnt >= 0 ?\
>	(int)(*(unsigned char *)(p)->_ptr++ = (x)) :\
>	(((p)->_flag & _IOLBF) && -(p)->_cnt < (p)->_bufsiz ?\
[rest deleted]
>The block buffered path is the second line and does not
>check the _IOLBF bit.  It is, in fact, exactly as fast
>as the old putc.  Of course this doesn't mean the C compiler
>generates good code for it.

And, also of course, it does not mean that the code is right!  4.3BSD
putc and printf (actually _doprnt) do not speak to each other.  _doprnt
assumes that a negative _cnt field is an error, and clobbers the
count.  Every once in a while, this results in putc scribbling all over
memory.  Fortunately, instances of this bug are rare (it requires
mixing calls to printf and calls to putc in a particular way).  This is
fixed in 4.3BSD-tahoe, which no longer has _doprnt in Vax assembly.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.wizards mailing list