src/fmt.c
/** \brief Wrapped snprintf.
 *
 * Formats the string, and updates dst and capacity.
 *
 * \return As snprintf : < 0 on error, or the total string length
 */
\brief Wrapped snprintf.
Formats the string, and updates dst and capacity.

\return As snprintf : < 0 on error, or the total string length
\ brief Wrapped snprintf . Formats the string and updates dst and capacity . \ return As snprintf : < 0 on error or the total string length
ssize_t str_fmt(char ** dst, size_t * cap, char const * fmt, ...)
{
    va_list args;
    va_start(args, fmt);
    int ret = vsnprintf(dst ? *dst : NULL, cap ? *cap : 0, fmt, args);
    va_end(args);
    if((ret >= 0) && cap && ((size_t)ret < *cap) && (ret <= SSIZE_MAX))
    {
        *dst += ret;
        *cap -= ret;
        assert(**dst == '\0');
    }
    else
    {
        if(ret < -1)
        {
            ret = -1;
        }
        str_rst_dst(dst, cap);
    }
    return ret;
}
ssize_t str_fmt ( char * * dst , size_t * cap , char const * fmt , ... ) { va_list args ; va_start ( args , fmt ) ; int ret = vsnprintf ( dst ? * dst : NULL , cap ? * cap : 0 , fmt , args ) ; va_end ( args ) ; if ( ( ret >= 0 ) && cap && ( ( size_t ) ret < * cap ) && ( ret <= SSIZE_MAX ) ) { * dst += ret ; * cap -= ret ; assert ( * * dst == ' \0 ' ) ; } else { if ( ret < -1 ) { ret = -1 ; } str_rst_dst ( dst , cap ) ; } return ret ; }
\brief Wrapped snprintf.
\ brief Wrapped snprintf .
// snprintf // Update dst and cap // success // formatting failure or result too large