Re: *printf and zero size

Поиск
Список
Период
Сортировка
От Kurt Roeckx
Тема Re: *printf and zero size
Дата
Msg-id 20051205214514.GA18244@roeckx.be
обсуждение исходный текст
Ответ на Re: *printf and zero size  (Bruce Momjian <pgman@candle.pha.pa.us>)
Список pgsql-hackers
On Mon, Dec 05, 2005 at 04:35:31PM -0500, Bruce Momjian wrote:
> 
> but it seems this is some BSD'ism that we don't need to support if the
> standard doesn't say so.

I think the Linux manpage is more informative about this:
      The functions snprintf and vsnprintf do not write more  than      size  bytes (including the trailing '\0').  If
theoutput was truncated      due to this limit then the return value is  the  number  of  characters      (not
includingthe trailing '\0') which would have been written to the      final string if enough space had been available.
Thus,a  return  value      of  size  or  more means that the output was truncated. (See also below      under NOTES.)
Ifan output error is encountered, a negative  value  is      returned.
 

[...]

NOTES      The  glibc  implementation  of the functions snprintf() and vsnprintf()      conforms to the C99 standard,
i.e.,behaves as described  above,  since      glibc version 2.1. Until glibc 2.0.6 they would return -1 when the out-
  put was truncated.
 

[...]
      Concerning  the return value of snprintf(), the SUSv2 and the C99 stan-      dard contradict each other: when
snprintf()is called with size=0  then      SUSv2  stipulates  an  unspecified  return value less than 1, while C99
allowsstr to be NULL in this case, and  gives  the  return  value  (as      always)  as  the  number  of characters
thatwould have been written in      case the output string has been large enough.
 


Kurt



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: *printf and zero size
Следующее
От: Tom Lane
Дата:
Сообщение: Re: About varlena2