9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: William Josephson <wkj@eecs.harvard.edu>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] snprint(), getfields() specification
Date: Thu, 10 May 2001 10:44:30 -0400	[thread overview]
Message-ID: <20010510104430.B13515@honk.eecs.harvard.edu> (raw)
In-Reply-To: <200105101425.KAA28328@egyptian-gods.MIT.EDU>; from ghudson@MIT.EDU on Thu, May 10, 2001 at 10:25:11AM -0400

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



  reply	other threads:[~2001-05-10 14:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-10 13:56 rob pike
2001-05-10 14:25 ` Greg Hudson
2001-05-10 14:44   ` William Josephson [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-05-10 17:56 rob pike
2001-05-10 17:51 forsyth
2001-05-10 17:40 erik quanstrom
2001-05-10 16:56 rob pike
     [not found] <rob@plan9.bell-labs.com>
2001-05-10 14:59 ` rob pike
2001-05-10 16:42   ` Scott Schwartz
2001-05-10 18:13   ` Steve Kilbane
2001-05-10 21:38     ` Boyd Roberts
2001-05-11  6:51       ` Steve Kilbane
2001-05-10 14:30 rob pike
2001-05-11  8:33 ` Douglas A. Gwyn
2001-05-14  8:36 ` David Rubin
2001-05-10  5:11 Scott Schwartz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010510104430.B13515@honk.eecs.harvard.edu \
    --to=wkj@eecs.harvard.edu \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).