snprintf.c revision 132451
182498Sroberto#include <config.h> 282498Sroberto 3106163Sroberto#if !HAVE_SNPRINTF 482498Sroberto#include <sys/types.h> 582498Sroberto 682498Sroberto#ifdef __STDC__ 782498Sroberto#include <stdarg.h> 882498Sroberto#else 982498Sroberto#include <varargs.h> 1082498Sroberto#endif 1182498Sroberto#include <stdio.h> 1282498Sroberto 13132451Sroberto#include "l_stdlib.h" 14132451Sroberto 1582498Sroberto#ifdef __STDC__ 1682498Srobertoint snprintf(char *str, size_t n, const char *fmt, ...) 1782498Sroberto#else 1882498Srobertoint snprintf(str, n, fmt, va_alist) 1982498Sroberto char *str; 2082498Sroberto size_t n; 2182498Sroberto const char *fmt; 2282498Sroberto va_dcl 2382498Sroberto#endif 2482498Sroberto{ 2582498Sroberto va_list ap; 2682498Sroberto int rval; 2782498Sroberto#ifdef VSPRINTF_CHARSTAR 2882498Sroberto char *rp; 2982498Sroberto#endif 3082498Sroberto#ifdef __STDC__ 3182498Sroberto va_start(ap, fmt); 3282498Sroberto#else 3382498Sroberto va_start(ap); 3482498Sroberto#endif 3582498Sroberto#ifdef VSPRINTF_CHARSTAR 3682498Sroberto rp = vsprintf(str, fmt, ap); 3782498Sroberto va_end(ap); 3882498Sroberto return (strlen(rp)); 3982498Sroberto#else 4082498Sroberto rval = vsprintf(str, fmt, ap); 4182498Sroberto va_end(ap); 4282498Sroberto return (rval); 4382498Sroberto#endif 4482498Sroberto} 4582498Sroberto 4682498Srobertoint 47132451Srobertovsnprintf( 48132451Sroberto char *str, 49132451Sroberto size_t n, 50132451Sroberto const char *fmt, 51132451Sroberto va_list ap 52132451Sroberto ) 5382498Sroberto{ 5482498Sroberto#ifdef VSPRINTF_CHARSTAR 5582498Sroberto return (strlen(vsprintf(str, fmt, ap))); 5682498Sroberto#else 5782498Sroberto return (vsprintf(str, fmt, ap)); 5882498Sroberto#endif 5982498Sroberto} 60106163Sroberto#else 61106163Srobertoint snprintf_bs; 62106163Sroberto#endif 63