ungetc will put characters back into an _IOSTRG input stream

Robert Elz kre at cs.mu.oz.au
Tue Feb 14 03:59:46 AEST 1989


In article <20282 at lll-winken.LLNL.GOV>, casey at lll-crg.llnl.gov (Casey Leedom) writes:
> Description:
> 	Ungetc will put characters back into an _IOSTRG input stream. 
> Fix:
> 	Debatable.

Maybe better to have ungetc() look at the character that's in the
buffer - if its the same as the one being pushed back (which it
always will be in sscanf()) then don't do the write.  ungetc() is
rare enough that the extra mem read & test aren't going to matter.

That way you don't get a segmentaion violation with write only strings
if you're just doing sscanf(), but you will if you try random other
ungetc's on a string (somehow).

You may also win doing this with normal writeable buffers - if the buffer
is currently mapped shared read, copy on write, you may be able to avoid the
copy (yes, I know, that will happen once a century...)

kre



More information about the Comp.bugs.4bsd.ucb-fixes mailing list