snprintf.c revision 82498
1#include <config.h> 2 3#include <sys/types.h> 4 5#ifdef __STDC__ 6#include <stdarg.h> 7#else 8#include <varargs.h> 9#endif 10#include <stdio.h> 11 12#ifdef __STDC__ 13int snprintf(char *str, size_t n, const char *fmt, ...) 14#else 15int snprintf(str, n, fmt, va_alist) 16 char *str; 17 size_t n; 18 const char *fmt; 19 va_dcl 20#endif 21{ 22 va_list ap; 23 int rval; 24#ifdef VSPRINTF_CHARSTAR 25 char *rp; 26#endif 27#ifdef __STDC__ 28 va_start(ap, fmt); 29#else 30 va_start(ap); 31#endif 32#ifdef VSPRINTF_CHARSTAR 33 rp = vsprintf(str, fmt, ap); 34 va_end(ap); 35 return (strlen(rp)); 36#else 37 rval = vsprintf(str, fmt, ap); 38 va_end(ap); 39 return (rval); 40#endif 41} 42 43int 44vsnprintf(str, n, fmt, ap) 45 char *str; 46 size_t n; 47 const char *fmt; 48 va_list ap; 49{ 50#ifdef VSPRINTF_CHARSTAR 51 return (strlen(vsprintf(str, fmt, ap))); 52#else 53 return (vsprintf(str, fmt, ap)); 54#endif 55} 56