ungetc will put characters back into an _IOSTRG input stream
Hitoshi Aida
aida at porthos.csl.sri.com
Tue Feb 14 04:24:20 AEST 1989
In article <20282 at lll-winken.LLNL.GOV> casey at lll-crg.llnl.gov (Casey Leedom) writes:
>Fix:
> Debatable. I fixed ungetc, but who knows? Maybe we do want to
> be able to do ungetc's on a string argument. Currently _IOSTRG
> is only used internally for sscanf and sprintf, so changing ungetc
> doesn't break anything now.
>
> Another option would be to replace all uses of ungetc in doscan
> with fseek(iop, -1L, 1) but I don't think fseek works on _IOSTRG
> arguments and I think it's a lot more expensive to call.
>
> Another option is to separate out the IO stream backup function
> from putting a [possibly different] character back on the stream.
> But this involves either defining a new interface, or extending
> the definition of ungetc's interface to accept something like
> ungetc(__IOS_BACKUP);
I think this is the correct option. I prefer a new interface.
Anyway, for the moment, following is more consistent.
*** lib/libc/stdio/ungetc.c-dist Wed Mar 26 18:08:43 1986
--- lib/libc/stdio/ungetc.c Sun Feb 12 13:45:30 1989
***************
*** 18,24 ****
return (EOF);
iop->_cnt++;
! *--iop->_ptr = c;
return (c);
}
--- 18,31 ----
return (EOF);
iop->_cnt++;
! if (iop->_flag & _IOSTRG) {
! if ((*--iop->_ptr & 0377) != c) {
! iop->_cnt--;
! iop->_ptr++;
! return (EOF);
! }
! } else
! *--iop->_ptr = c;
return (c);
}
Hitoshi AIDA (aida at csl.sri.com)
Computer Science Laboratory, SRI International
More information about the Comp.bugs.4bsd.ucb-fixes
mailing list