vsnprintf.c (178287) | vsnprintf.c (205021) |
---|---|
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 178287 2008-04-17 22:17:54Z jhb $"); | 37__FBSDID("$FreeBSD: head/lib/libc/stdio/vsnprintf.c 205021 2010-03-11 17:03:32Z 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]; | 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; | 50 FILE f = FAKE_FILE; |
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 } | 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; | 64 f._flags = __SWR | __SSTR; 65 f._bf._base = f._p = (unsigned char *)str; 66 f._bf._size = f._w = n; |
68 f._orientation = 0; 69 memset(&f._mbstate, 0, sizeof(mbstate_t)); | |
70 ret = __vfprintf(&f, fmt, ap); 71 if (on > 0) 72 *f._p = '\0'; 73 return (ret); 74} | 67 ret = __vfprintf(&f, fmt, ap); 68 if (on > 0) 69 *f._p = '\0'; 70 return (ret); 71} |