[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [leafnode-list] [ANNOUNCE:] leafnode-1.9.12



Bruno Rohee wrote:

> Second thought on the problem : why not having in miscutils.c
> 
> #ifndef HAVE_SNPRINTF
> int snprintf(char *str, size_t n, const char *fmt, ...)
> {
>     int rval;
>     va_list ap;
> 
>     va_start(ap, fmt);
>     rval = sprintf(str, fmt, ap);
>     va_end(ap);
> 
>     return rval;
> }
> #endif
> 
> So platform having snprintf() will use theirs and those who haven't will
> use sprintf().

Sure, that was what I was thinking of. It is actually already the same
with strdup().

I put the following into miscutil.c; please have a short look and check
whether it is correct:

#ifndef HAVE_SNPRINTF
int snprintf(char *str, size_t n, const char *fmt, ...) {
    int rval;
    va_list ap;

    va_start(ap, fmt);
    rval = vsprintf(str, fmt, ap);
    if ( strlen(str) > n ) {
        syslog( LOG_NOTICE, "snprintf buffer overflow" );
        str[n] = '\0';
    }
    va_end(ap);

    return rval;
}
#endif

--Cornelius.

-- 
/* Cornelius Krasel, U Wuerzburg, Dept. of Pharmacology, Versbacher Str. 9 */
/* D-97078 Wuerzburg, Germany   email: phak004@xxxxxxxxxxxxxxxxxxxxxx  SP4 */
/* "Science is the game we play with God to find out what His rules are."  */

-- 
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx -- mailing list for leafnode
To unsubscribe, send mail with "unsubscribe" in the subject to the list