[Bug 1865] extend snprintf to work on NULL

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Wed Nov 24 02:27:34 PST 2004


Please do not reply to this email: if you want to comment on the bug, go to          
the URL shown below and enter yourcomments there.   
 
https://bugs.freedesktop.org/show_bug.cgi?id=1865        
   




------- Additional Comments From ago at freedesktop.org  2004-11-24 02:27 -------
glibc has an asprintf(char **str, const char *format, ...) for this

I'm about to use this implementation for XWin

#ifndef HAS_VASPRINTF
extern int vasprintf(char **strp, const char *format, va_list va)
{
    int ret;
    int size;
    va_list va2;

    va_copy(va2, va);
    size = vsnprintf(NULL, 0, format, va2);
    va_end(va2);

    *strp = malloc(size + 1);
    if (*strp == NULL)
        return -1;

    ret = vsnprintf(*strp, size + 1, format, va);
    (*strp)[size] = 0;
    return ret;
}
#endif

#ifndef HAS_ASPRINTF
extern int asprintf(char **strp, const char *format, ...)
{
    int ret;
    va_list va;
    va_start(va, format);
    ret = vasprintf(strp, format, va);
    va_end(va);
    return ret;
}
#endif        
   
   
--         
Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email       
   
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


More information about the xorg-bugzilla-noise mailing list