bumped version
[gnutls.git] / src / libopts / compat / snprintf.c
blobfc91d63a9cf68bf868742dad824aedf8f717b9c0
2 #ifndef HAVE_VPRINTF
3 #include "choke-me: no vprintf and no snprintf"
4 #endif
6 #if defined(HAVE_STDARG_H)
7 # include <stdarg.h>
8 # ifndef VA_START
9 # define VA_START(a, f) va_start(a, f)
10 # define VA_END(a) va_end(a)
11 # endif /* VA_START */
12 # define SNV_USING_STDARG_H
14 #elif defined(HAVE_VARARGS_H)
15 # include <varargs.h>
16 # ifndef VA_START
17 # define VA_START(a, f) va_start(a)
18 # define VA_END(a) va_end(a)
19 # endif /* VA_START */
20 # undef SNV_USING_STDARG_H
22 #else
23 # include "must-have-stdarg-or-varargs"
24 #endif
26 static int
27 snprintf(char *str, size_t n, char const *fmt, ...)
29 va_list ap;
30 int rval;
32 #ifdef VSPRINTF_CHARSTAR
33 char *rp;
34 VA_START(ap, fmt);
35 rp = vsprintf(str, fmt, ap);
36 VA_END(ap);
37 rval = strlen(rp);
39 #else
40 VA_START(ap, fmt);
41 rval = vsprintf(str, fmt, ap);
42 VA_END(ap);
43 #endif
45 if (rval > n) {
46 fprintf(stderr, "snprintf buffer overrun %d > %d\n", rval, (int)n);
47 abort();
49 return rval;
52 static int
53 vsnprintf( char *str, size_t n, char const *fmt, va_list ap )
55 #ifdef VSPRINTF_CHARSTAR
56 return (strlen(vsprintf(str, fmt, ap)));
57 #else
58 return (vsprintf(str, fmt, ap));
59 #endif