From mboxrd@z Thu Jan 1 00:00:00 1970 From: William Josephson To: 9fans@cse.psu.edu Subject: Re: [9fans] snprint(), getfields() specification Message-ID: <20010510104430.B13515@honk.eecs.harvard.edu> References: <20010510135659.3B4A8199F0@mail.cse.psu.edu> <200105101425.KAA28328@egyptian-gods.MIT.EDU> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200105101425.KAA28328@egyptian-gods.MIT.EDU>; from ghudson@MIT.EDU on Thu, May 10, 2001 at 10:25:11AM -0400 Date: Thu, 10 May 2001 10:44:30 -0400 Topicbox-Message-UUID: 9d976db8-eac9-11e9-9e20-41e7f4b1d025 On Thu, May 10, 2001 at 10:25:11AM -0400, Greg Hudson wrote: > Rob Pike wrote: > > Really? Unix sprintf tells you what it printed and snprintf tells > > you what it *might* have printed? That's a scary inconsistency. > > They both return the length of the formatted string. Would it be any > less scary for sprintf to return the length of the formatted string > and snprintf to return something different and less informative? As you say, snprintf returns the length of the formatted string, not the length of the string it would have generated had the buffer not been of fixed length. This is not how I initially interpreted the description that Rob is responding to and I suspect it is not how he interpreted it either. Per the man page: snprintf() and vsnprintf() will write at most size-1 of the characters printed into the output string (the size'th character then gets the ter- minating `\0'); if the return value is greater than or equal to the size argument, the string was too short and some of the printed characters were discarded. -WJ