[dovecot] Re: vsnprintf()

Timo Sirainen tss at iki.fi
Wed Oct 23 20:21:55 EEST 2002


On Wed, 2002-10-23 at 20:13, David Champion wrote:
> There's an alternative approach that depends on the newer vsnprintf()
> behavior. You can use
>  
> {
> 	char c, *buf;
> 	length = vsnprintf(&c, 1, fmt, vp);
> 	buf = malloc(length+1);
> 	vsnprintf(buf, length, fmt, vp);
> }
> 
> to dynamically size the buffer as large as it needs to be. For general
> formatting routines, I sometimes use this idiom (not totally valid C,
> and no error-checking):

Not too bad idea :) Dovecot currently uses a bit modified GLIB's
g_printf_string_upper_bound() and then allocates enough memory based on
it. Maybe using vsnprintf() could be optional (detected by configure if
it works), if it's better/faster than my upper_bound() function.




More information about the dovecot mailing list