vfprintf.c (124667) | vfprintf.c (128002) |
---|---|
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 --- 24 unchanged lines hidden (view full) --- 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37#if defined(LIBC_SCCS) && !defined(lint) 38static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93"; 39#endif /* LIBC_SCCS and not lint */ 40#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 --- 24 unchanged lines hidden (view full) --- 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37#if defined(LIBC_SCCS) && !defined(lint) 38static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93"; 39#endif /* LIBC_SCCS and not lint */ 40#include <sys/cdefs.h> |
41__FBSDID("$FreeBSD: head/lib/libc/stdio/vfprintf.c 124667 2004-01-18 10:32:49Z das $"); | 41__FBSDID("$FreeBSD: head/lib/libc/stdio/vfprintf.c 128002 2004-04-07 09:55:05Z tjr $"); |
42 43/* 44 * Actual printf innards. 45 * 46 * This code is large and complicated... 47 */ 48 49#include "namespace.h" --- 287 unchanged lines hidden (view full) --- 337 * Convert a wide character string argument for the %ls format to a multibyte 338 * string representation. ``prec'' specifies the maximum number of bytes 339 * to output. If ``prec'' is greater than or equal to zero, we can't assume 340 * that the wide char. string ends in a null character. 341 */ 342static char * 343__wcsconv(wchar_t *wcsarg, int prec) 344{ | 42 43/* 44 * Actual printf innards. 45 * 46 * This code is large and complicated... 47 */ 48 49#include "namespace.h" --- 287 unchanged lines hidden (view full) --- 337 * Convert a wide character string argument for the %ls format to a multibyte 338 * string representation. ``prec'' specifies the maximum number of bytes 339 * to output. If ``prec'' is greater than or equal to zero, we can't assume 340 * that the wide char. string ends in a null character. 341 */ 342static char * 343__wcsconv(wchar_t *wcsarg, int prec) 344{ |
345 static const mbstate_t initial; 346 mbstate_t mbs; |
|
345 char buf[MB_LEN_MAX]; 346 wchar_t *p; 347 char *convbuf, *mbp; 348 size_t clen, nbytes; 349 350 /* 351 * Determine the number of bytes to output and allocate space for 352 * the output. 353 */ 354 if (prec >= 0) { 355 nbytes = 0; 356 p = wcsarg; | 347 char buf[MB_LEN_MAX]; 348 wchar_t *p; 349 char *convbuf, *mbp; 350 size_t clen, nbytes; 351 352 /* 353 * Determine the number of bytes to output and allocate space for 354 * the output. 355 */ 356 if (prec >= 0) { 357 nbytes = 0; 358 p = wcsarg; |
359 mbs = initial; |
|
357 for (;;) { | 360 for (;;) { |
358 clen = wcrtomb(buf, *p++, NULL); | 361 clen = wcrtomb(buf, *p++, &mbs); |
359 if (clen == 0 || clen == (size_t)-1 || 360 nbytes + clen > prec) 361 break; 362 nbytes += clen; 363 } 364 } else { 365 p = wcsarg; | 362 if (clen == 0 || clen == (size_t)-1 || 363 nbytes + clen > prec) 364 break; 365 nbytes += clen; 366 } 367 } else { 368 p = wcsarg; |
366 nbytes = wcsrtombs(NULL, (const wchar_t **)&p, 0, NULL); | 369 mbs = initial; 370 nbytes = wcsrtombs(NULL, (const wchar_t **)&p, 0, &mbs); |
367 if (nbytes == (size_t)-1) 368 return (NULL); 369 } 370 if ((convbuf = malloc(nbytes + 1)) == NULL) 371 return (NULL); 372 373 /* 374 * Fill the output buffer with the multibyte representations of as 375 * many wide characters as will fit. 376 */ 377 mbp = convbuf; 378 p = wcsarg; | 371 if (nbytes == (size_t)-1) 372 return (NULL); 373 } 374 if ((convbuf = malloc(nbytes + 1)) == NULL) 375 return (NULL); 376 377 /* 378 * Fill the output buffer with the multibyte representations of as 379 * many wide characters as will fit. 380 */ 381 mbp = convbuf; 382 p = wcsarg; |
383 mbs = initial; |
|
379 while (mbp - convbuf < nbytes) { | 384 while (mbp - convbuf < nbytes) { |
380 clen = wcrtomb(mbp, *p++, NULL); | 385 clen = wcrtomb(mbp, *p++, &mbs); |
381 if (clen == 0 || clen == (size_t)-1) 382 break; 383 mbp += clen; 384 } 385 if (clen == (size_t)-1) { 386 free(convbuf); 387 return (NULL); 388 } --- 399 unchanged lines hidden (view full) --- 788 case 'z': 789 flags |= SIZET; 790 goto rflag; 791 case 'C': 792 flags |= LONGINT; 793 /*FALLTHROUGH*/ 794 case 'c': 795 if (flags & LONGINT) { | 386 if (clen == 0 || clen == (size_t)-1) 387 break; 388 mbp += clen; 389 } 390 if (clen == (size_t)-1) { 391 free(convbuf); 392 return (NULL); 393 } --- 399 unchanged lines hidden (view full) --- 793 case 'z': 794 flags |= SIZET; 795 goto rflag; 796 case 'C': 797 flags |= LONGINT; 798 /*FALLTHROUGH*/ 799 case 'c': 800 if (flags & LONGINT) { |
801 static const mbstate_t initial; 802 mbstate_t mbs; |
|
796 size_t mbseqlen; 797 | 803 size_t mbseqlen; 804 |
805 mbs = initial; |
|
798 mbseqlen = wcrtomb(cp = buf, | 806 mbseqlen = wcrtomb(cp = buf, |
799 (wchar_t)GETARG(wint_t), NULL); | 807 (wchar_t)GETARG(wint_t), &mbs); |
800 if (mbseqlen == (size_t)-1) { 801 fp->_flags |= __SERR; 802 goto error; 803 } 804 size = (int)mbseqlen; 805 } else { 806 *(cp = buf) = GETARG(int); 807 size = 1; --- 834 unchanged lines hidden --- | 808 if (mbseqlen == (size_t)-1) { 809 fp->_flags |= __SERR; 810 goto error; 811 } 812 size = (int)mbseqlen; 813 } else { 814 *(cp = buf) = GETARG(int); 815 size = 1; --- 834 unchanged lines hidden --- |