snprintf.c revision 82498
182498Sroberto#include <config.h> 282498Sroberto 382498Sroberto#include <sys/types.h> 482498Sroberto 582498Sroberto#ifdef __STDC__ 682498Sroberto#include <stdarg.h> 782498Sroberto#else 882498Sroberto#include <varargs.h> 982498Sroberto#endif 1082498Sroberto#include <stdio.h> 1182498Sroberto 1282498Sroberto#ifdef __STDC__ 1382498Srobertoint snprintf(char *str, size_t n, const char *fmt, ...) 1482498Sroberto#else 1582498Srobertoint snprintf(str, n, fmt, va_alist) 1682498Sroberto char *str; 1782498Sroberto size_t n; 1882498Sroberto const char *fmt; 1982498Sroberto va_dcl 2082498Sroberto#endif 2182498Sroberto{ 2282498Sroberto va_list ap; 2382498Sroberto int rval; 2482498Sroberto#ifdef VSPRINTF_CHARSTAR 2582498Sroberto char *rp; 2682498Sroberto#endif 2782498Sroberto#ifdef __STDC__ 2882498Sroberto va_start(ap, fmt); 2982498Sroberto#else 3082498Sroberto va_start(ap); 3182498Sroberto#endif 3282498Sroberto#ifdef VSPRINTF_CHARSTAR 3382498Sroberto rp = vsprintf(str, fmt, ap); 3482498Sroberto va_end(ap); 3582498Sroberto return (strlen(rp)); 3682498Sroberto#else 3782498Sroberto rval = vsprintf(str, fmt, ap); 3882498Sroberto va_end(ap); 3982498Sroberto return (rval); 4082498Sroberto#endif 4182498Sroberto} 4282498Sroberto 4382498Srobertoint 4482498Srobertovsnprintf(str, n, fmt, ap) 4582498Sroberto char *str; 4682498Sroberto size_t n; 4782498Sroberto const char *fmt; 4882498Sroberto va_list ap; 4982498Sroberto{ 5082498Sroberto#ifdef VSPRINTF_CHARSTAR 5182498Sroberto return (strlen(vsprintf(str, fmt, ap))); 5282498Sroberto#else 5382498Sroberto return (vsprintf(str, fmt, ap)); 5482498Sroberto#endif 5582498Sroberto} 56