Re: snprintf heads-up

From: Date: Fri, 08 Sep 2000 14:49:00 +0000
Subject: Re: snprintf heads-up
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-32680@lists.php.net to get a copy of this message
On Fri, 8 Sep 2000, Jon Ribbens wrote: > Zeev Suraski <zeev@zend.com> wrote: > > > This behaviour is not particularly useful, because it means that if your > > > buffer turns out to be too small, and you want to extend it, you have no > > > way of knowing by how much you need to increase it. > > > > If you want to extend it, that's true. However, in my opinion, in most > > cases you use snprintf() to give a maximum limit to an existing buffer, > > and you wouldn't increase its length even if it overflows. > > 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. > > In this (general, IMHO) case, the most interesting piece of information > > would be the number of characters actually written, so that you don't have > > to go through strlen() again. > > 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. Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/

« previous php.dev (#32680) next »