fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / stdio / vsnprintf.c
blob0393ead2972d203d0a461229a6ce88fd5aeba514
1 /* doc in vfprintf.c */
3 /* This code created by modifying vsprintf.c so copyright inherited. */
5 /*
6 * Copyright (c) 1990 The Regents of the University of California.
7 * All rights reserved.
9 * Redistribution and use in source and binary forms are permitted
10 * provided that the above copyright notice and this paragraph are
11 * duplicated in all such forms and that any documentation,
12 * advertising materials, and other materials related to such
13 * distribution and use acknowledge that the software was developed
14 * by the University of California, Berkeley. The name of the
15 * University may not be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 #if defined(LIBC_SCCS) && !defined(lint)
23 static char sccsid[] = "%W% (Berkeley) %G%";
24 #endif /* LIBC_SCCS and not lint */
26 #include <_ansi.h>
27 #include <reent.h>
28 #include <stdio.h>
29 #include <limits.h>
30 #ifdef _HAVE_STDC
31 #include <stdarg.h>
32 #else
33 #include <varargs.h>
34 #endif
36 #ifndef _REENT_ONLY
38 int
39 _DEFUN (vsnprintf, (str, size, fmt, ap),
40 char *str _AND
41 size_t size _AND
42 _CONST char *fmt _AND
43 va_list ap)
45 int ret;
46 FILE f;
48 f._flags = __SWR | __SSTR;
49 f._bf._base = f._p = (unsigned char *) str;
50 f._bf._size = f._w = (size > 0 ? size - 1 : 0);
51 ret = _vfprintf_r (_REENT, &f, fmt, ap);
52 if (size > 0)
53 *f._p = 0;
54 return ret;
57 #endif /* !_REENT_ONLY */
59 int
60 _DEFUN (_vsnprintf_r, (ptr, str, size, fmt, ap),
61 struct _reent *ptr _AND
62 char *str _AND
63 size_t size _AND
64 _CONST char *fmt _AND
65 va_list ap)
67 int ret;
68 FILE f;
70 f._flags = __SWR | __SSTR;
71 f._bf._base = f._p = (unsigned char *) str;
72 f._bf._size = f._w = (size > 0 ? size - 1 : 0);
73 ret = _vfprintf_r (ptr, &f, fmt, ap);
74 if (size > 0)
75 *f._p = 0;
76 return ret;