Deleted Added
full compact
vsnprintf.c (165903) vsnprintf.c (178287)
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#if defined(LIBC_SCCS) && !defined(lint)
34static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93";
35#endif /* LIBC_SCCS and not lint */
36#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#if defined(LIBC_SCCS) && !defined(lint)
34static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93";
35#endif /* LIBC_SCCS and not lint */
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/lib/libc/stdio/vsnprintf.c 165903 2007-01-09 00:28:16Z imp $");
37__FBSDID("$FreeBSD: head/lib/libc/stdio/vsnprintf.c 178287 2008-04-17 22:17:54Z jhb $");
38
39#include <limits.h>
40#include <stdio.h>
41#include "local.h"
42
43int
44vsnprintf(char * __restrict str, size_t n, const char * __restrict fmt,
45 __va_list ap)
46{
47 size_t on;
48 int ret;
49 char dummy[2];
50 FILE f;
38
39#include <limits.h>
40#include <stdio.h>
41#include "local.h"
42
43int
44vsnprintf(char * __restrict str, size_t n, const char * __restrict fmt,
45 __va_list ap)
46{
47 size_t on;
48 int ret;
49 char dummy[2];
50 FILE f;
51 struct __sFILEX ext;
52
53 on = n;
54 if (n != 0)
55 n--;
56 if (n > INT_MAX)
57 n = INT_MAX;
58 /* Stdio internals do not deal correctly with zero length buffer */
59 if (n == 0) {
60 if (on > 0)
61 *str = '\0';
62 str = dummy;
63 n = 1;
64 }
65 f._file = -1;
66 f._flags = __SWR | __SSTR;
67 f._bf._base = f._p = (unsigned char *)str;
68 f._bf._size = f._w = n;
51
52 on = n;
53 if (n != 0)
54 n--;
55 if (n > INT_MAX)
56 n = INT_MAX;
57 /* Stdio internals do not deal correctly with zero length buffer */
58 if (n == 0) {
59 if (on > 0)
60 *str = '\0';
61 str = dummy;
62 n = 1;
63 }
64 f._file = -1;
65 f._flags = __SWR | __SSTR;
66 f._bf._base = f._p = (unsigned char *)str;
67 f._bf._size = f._w = n;
69 f._extra = &ext;
70 INITEXTRA(&f);
68 f._orientation = 0;
69 memset(&f._mbstate, 0, sizeof(mbstate_t));
71 ret = __vfprintf(&f, fmt, ap);
72 if (on > 0)
73 *f._p = '\0';
74 return (ret);
75}
70 ret = __vfprintf(&f, fmt, ap);
71 if (on > 0)
72 *f._p = '\0';
73 return (ret);
74}