vsnprintf.c (1e98f88776fc606df245a382685b1ac634a81389) | vsnprintf.c (1b0181df2f46ef73a41ea8c9b7026718f8eec3a1) |
---|---|
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 --- 33 unchanged lines hidden (view full) --- 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]; | 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 --- 33 unchanged lines hidden (view full) --- 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} |