Path: utzoo!attcan!uunet!munnari!murtoa.cs.mu.oz.au!cs.mu.oz.au!kre From: kre@cs.mu.oz.au (Robert Elz) 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: <1231@murtoa.cs.mu.oz.au> Date: 13 Feb 89 17:59:46 GMT References: <20282@lll-winken.LLNL.GOV> Sender: news@cs.mu.oz.au Lines: 20 In article <20282@lll-winken.LLNL.GOV>, casey@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