Re: *printf and zero size - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: *printf and zero size
Date
Msg-id 200512052135.jB5LZVs22806@candle.pha.pa.us
Whole thread Raw
In response to Re: *printf and zero size  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: *printf and zero size
Re: *printf and zero size
List pgsql-hackers
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > Tom, did you implement this functionality in *printf?
> >     The size may be given as zero to find out how many characters are
> >     needed; in this case, the str argument is ignored. Sprintf() and
> >     vsprintf() effectively assume an infinite size.
> 
> Where do you read that?  The SUS says the opposite:
> 
>     If the value of n is zero on a call to snprintf(), an unspecified
>     value less than 1 is returned. 
> 
> and that's what our code implements.

I got it from the BSD/OS manual page, and in the NetBSD manual page I
see:
If size is zero, nothing is written and str may be a NULL pointer.

and:
Upon successful completion snprintf() and vsnprintf() return the numberof characters that would have been written to a
sufficientlysized str,excluding the terminating NUL character.
 

but it seems this is some BSD'ism that we don't need to support if the
standard doesn't say so.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: *printf and zero size
Next
From: Tom Lane
Date:
Subject: Re: *printf and zero size