FreeBSD/contrib/openpam/lib/libpam/openpam_vasprintf.c
/* like vsprintf(3), but allocates memory for the result. */
like vsprintf(3), but allocates memory for the result.
like vsprintf ( 3 ) but allocates memory for the result .
int
openpam_vasprintf(char **str, const char *fmt, va_list ap)
{
        va_list apcopy;
        int len, ret;
        va_copy(apcopy, ap);
        len = vsnprintf(NULL, 0, fmt, ap);
        if ((*str = malloc(len + 1)) == NULL)
                return (-1);
        ret = vsnprintf(*str, len + 1, fmt, apcopy);
        va_end(apcopy);
        return (ret);
}
int openpam_vasprintf ( char * * str , const char * fmt , va_list ap ) { va_list apcopy ; int len , ret ; va_copy ( apcopy , ap ) ; len = vsnprintf ( NULL , 0 , fmt , ap ) ; if ( ( * str = malloc ( len + 1 ) ) == NULL ) return ( -1 ) ; ret = vsnprintf ( * str , len + 1 , fmt , apcopy ) ; va_end ( apcopy ) ; return ( ret ) ; }
like vsprintf(3), but allocates memory for the result.
like vsprintf ( 3 ) but allocates memory for the result .