Re: snprintf heads-up
| From: | Jon Ribbens | Date: | Fri, 08 Sep 2000 14:55:57 +0000 |
| Subject: | Re: snprintf heads-up | ||
| References: | 1 2 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-32681@lists.php.net to get a copy of this message | ||
Zeev Suraski <zeev@zend.com> wrote:
> > This may indeed be the most common case, but from the point of view of
> > the people writing C libraries, they need to cater for as many people
> > as possible. One behaviour satisfies only some people, the other satisfies
> > everyone.
>
> This seems to be contradicting itself.
Why?
Case (a): snprintf returns bytes written
* People extending buffer are screwed, they must write their own snprintf
or do something horrible like repeatedly extend the buffer until snprintf
succeeds.
* People not extending buffer are happy.
Case (b): snprintf returns bytes that *would* be written
* People extending buffer are happy.
* People not extending buffer are slightly less happy, but they can still
achieve what they want quite easily.
> > You don't need strlen(), simply do max(snprintf(...), buffer_size)
>
> You can do that; Probably not a good idea with most MAX() macros, though.
Yes, this is why I put it in lower-case ;-).
Cheers
Jon