Merge from vendor branch GDB:
[dragonfly.git] / contrib / nvi / clib / snprintf.c
1 #include "config.h"
2
3 #include <sys/types.h>
4
5 #include <stdio.h>
6
7 #ifdef __STDC__
8 #include <stdarg.h>
9 #else
10 #include <varargs.h>
11 #endif
12
13 /*
14  * PUBLIC: #ifndef HAVE_SNPRINTF
15  * PUBLIC: int snprintf __P((char *, size_t, const char *, ...));
16  * PUBLIC: #endif
17  */
18 int
19 #ifdef __STDC__
20 snprintf(char *str, size_t n, const char *fmt, ...)
21 #else
22 snprintf(str, n, fmt, va_alist)
23         char *str;
24         size_t n;
25         const char *fmt;
26         va_dcl
27 #endif
28 {
29         va_list ap;
30         int rval;
31 #ifdef __STDC__
32         va_start(ap, fmt);
33 #else
34         va_start(ap);
35 #endif
36 #ifdef SPRINTF_RET_CHARPNT
37         (void)vsprintf(str, fmt, ap);
38         va_end(ap);
39         return (strlen(str));
40 #else
41         rval = vsprintf(str, fmt, ap);
42         va_end(ap);
43         return (rval);
44 #endif
45 }