🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.4bsd
Article #1338

Re: ungetc will put characters back into an _IOSTRG input stream

#1338
From: Hitoshi Aida
Date: Mon, 13 Feb 1989 18:24
49 lines
2100 bytes
In article <20282@lll-winken.LLNL.GOV> casey@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@csl.sri.com)
Computer Science Laboratory, SRI International
Technical Details
Message-ID: <8691@cslb.CSL.SRI.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!ames!joyce!cslb!porthos!aida
References: <20282@lll-winken.LLNL.GOV>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!ames!joyce!cslb!porthos!aida
From: aida@porthos.csl.sri.com (Hitoshi Aida)
Newsgroups: comp.bugs.4bsd
Subject: Re: ungetc will put characters back into an _IOSTRG input stream
Keywords: writable strings, shared strings (text segment), sscanf, ungetc
Message-ID: <8691@cslb.CSL.SRI.COM>
Date: 13 Feb 89 18:24:20 GMT
References: <20282@lll-winken.LLNL.GOV>
Sender: usenet@cslb.CSL.SRI.COM
Reply-To: aida@csl.sri.com (Hitoshi Aida)
Organization: Computer Science Lab, SRI International
Lines: 49