Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ukma!rutgers!bpa!cbmvax!ditto From: ditto@cbmvax.UUCP (Michael "Ford" Ditto) Newsgroups: comp.bugs.4bsd Subject: Re: ungetc will put characters back into an _IOSTRG input stream Summary: Alternative code Keywords: writable strings, shared strings (text segment), sscanf, ungetc Message-ID: <5969@cbmvax.UUCP> Date: 14 Feb 89 02:43:58 GMT References: <20282@lll-winken.LLNL.GOV> Reply-To: ditto@cbmvax.UUCP (Michael "Ford" Ditto) Organization: Commodore Technology, West Chester, PA Lines: 21 In article <20282@lll-winken.LLNL.GOV> casey@lll-crg.llnl.gov (Casey Leedom) writes: > ! if (iop->_flag & _IOSTRG) > ! --iop->_ptr; > ! else > ! *--iop->_ptr = c; As an alternative to the above four lines, why not: if (*--iop->_ptr != (char)c) *iop->ptr = c; This will give anyone ungetc'ing something weird into a readonly string the segmentation fault they deserve, and still allow ungetc'ing into a writable string (even though nobody should be doing that). -- -=] Ford [=- "The number of Unix installations (In Real Life: Mike Ditto) has grown to 10, with more expected." ford@kenobi.cts.com - The Unix Programmer's Manual, ...!sdcsvax!crash!elgar!ford 2nd Edition, June, 1972. ditto@cbmvax.commodore.com