vfwprintf.c (124887) | vfwprintf.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 --- 27 unchanged lines hidden (view full) --- 36 37#include <sys/cdefs.h> 38#if 0 39#if defined(LIBC_SCCS) && !defined(lint) 40static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93"; 41#endif /* LIBC_SCCS and not lint */ 42__FBSDID("FreeBSD: src/lib/libc/stdio/vfprintf.c,v 1.62 2004/01/18 10:32:49 das Exp"); 43#endif | 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 --- 27 unchanged lines hidden (view full) --- 36 37#include <sys/cdefs.h> 38#if 0 39#if defined(LIBC_SCCS) && !defined(lint) 40static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93"; 41#endif /* LIBC_SCCS and not lint */ 42__FBSDID("FreeBSD: src/lib/libc/stdio/vfprintf.c,v 1.62 2004/01/18 10:32:49 das Exp"); 43#endif |
44__FBSDID("$FreeBSD: head/lib/libc/stdio/vfwprintf.c 124887 2004-01-23 22:48:16Z das $"); | 44__FBSDID("$FreeBSD: head/lib/libc/stdio/vfwprintf.c 128002 2004-04-07 09:55:05Z tjr $"); |
45 46/* 47 * Actual wprintf innards. 48 * 49 * Avoid making gratuitous changes to this source file; it should be kept 50 * as close as possible to vfprintf.c for ease of maintenance. 51 */ 52 --- 106 unchanged lines hidden (view full) --- 159 160/* 161 * Like __fputwc, but handles fake string (__SSTR) files properly. 162 * File must already be locked. 163 */ 164static wint_t 165__xfputwc(wchar_t wc, FILE *fp) 166{ | 45 46/* 47 * Actual wprintf innards. 48 * 49 * Avoid making gratuitous changes to this source file; it should be kept 50 * as close as possible to vfprintf.c for ease of maintenance. 51 */ 52 --- 106 unchanged lines hidden (view full) --- 159 160/* 161 * Like __fputwc, but handles fake string (__SSTR) files properly. 162 * File must already be locked. 163 */ 164static wint_t 165__xfputwc(wchar_t wc, FILE *fp) 166{ |
167 static const mbstate_t initial; 168 mbstate_t mbs; |
|
167 char buf[MB_LEN_MAX]; 168 struct __suio uio; 169 struct __siov iov; 170 size_t len; 171 172 if ((fp->_flags & __SSTR) == 0) 173 return (__fputwc(wc, fp)); 174 | 169 char buf[MB_LEN_MAX]; 170 struct __suio uio; 171 struct __siov iov; 172 size_t len; 173 174 if ((fp->_flags & __SSTR) == 0) 175 return (__fputwc(wc, fp)); 176 |
175 if ((len = wcrtomb(buf, wc, NULL)) == (size_t)-1) { | 177 mbs = initial; 178 if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) { |
176 fp->_flags |= __SERR; 177 return (WEOF); 178 } 179 uio.uio_iov = &iov; 180 uio.uio_resid = len; 181 uio.uio_iovcnt = 1; 182 iov.iov_base = buf; 183 iov.iov_len = len; --- 165 unchanged lines hidden (view full) --- 349 * Convert a multibyte character string argument for the %s format to a wide 350 * string representation. ``prec'' specifies the maximum number of bytes 351 * to output. If ``prec'' is greater than or equal to zero, we can't assume 352 * that the multibyte char. string ends in a null character. 353 */ 354static wchar_t * 355__mbsconv(char *mbsarg, int prec) 356{ | 179 fp->_flags |= __SERR; 180 return (WEOF); 181 } 182 uio.uio_iov = &iov; 183 uio.uio_resid = len; 184 uio.uio_iovcnt = 1; 185 iov.iov_base = buf; 186 iov.iov_len = len; --- 165 unchanged lines hidden (view full) --- 352 * Convert a multibyte character string argument for the %s format to a wide 353 * string representation. ``prec'' specifies the maximum number of bytes 354 * to output. If ``prec'' is greater than or equal to zero, we can't assume 355 * that the multibyte char. string ends in a null character. 356 */ 357static wchar_t * 358__mbsconv(char *mbsarg, int prec) 359{ |
360 static const mbstate_t initial; 361 mbstate_t mbs; |
|
357 wchar_t *convbuf, *wcp; 358 const char *p; 359 size_t insize, nchars, nconv; 360 361 if (mbsarg == NULL) 362 return (NULL); 363 364 /* 365 * Supplied argument is a multibyte string; convert it to wide 366 * characters first. 367 */ 368 if (prec >= 0) { 369 /* 370 * String is not guaranteed to be NUL-terminated. Find the 371 * number of characters to print. 372 */ 373 p = mbsarg; 374 insize = nchars = 0; | 362 wchar_t *convbuf, *wcp; 363 const char *p; 364 size_t insize, nchars, nconv; 365 366 if (mbsarg == NULL) 367 return (NULL); 368 369 /* 370 * Supplied argument is a multibyte string; convert it to wide 371 * characters first. 372 */ 373 if (prec >= 0) { 374 /* 375 * String is not guaranteed to be NUL-terminated. Find the 376 * number of characters to print. 377 */ 378 p = mbsarg; 379 insize = nchars = 0; |
380 mbs = initial; |
|
375 while (nchars != (size_t)prec) { | 381 while (nchars != (size_t)prec) { |
376 nconv = mbrlen(p, MB_CUR_MAX, NULL); | 382 nconv = mbrlen(p, MB_CUR_MAX, &mbs); |
377 if (nconv == 0 || nconv == (size_t)-1 || 378 nconv == (size_t)-2) 379 break; 380 p += nconv; 381 nchars++; 382 insize += nconv; 383 } 384 if (nconv == (size_t)-1 || nconv == (size_t)-2) --- 6 unchanged lines hidden (view full) --- 391 * converting at most `size' bytes of the input multibyte string to 392 * wide characters for printing. 393 */ 394 convbuf = malloc((insize + 1) * sizeof(*convbuf)); 395 if (convbuf == NULL) 396 return (NULL); 397 wcp = convbuf; 398 p = mbsarg; | 383 if (nconv == 0 || nconv == (size_t)-1 || 384 nconv == (size_t)-2) 385 break; 386 p += nconv; 387 nchars++; 388 insize += nconv; 389 } 390 if (nconv == (size_t)-1 || nconv == (size_t)-2) --- 6 unchanged lines hidden (view full) --- 397 * converting at most `size' bytes of the input multibyte string to 398 * wide characters for printing. 399 */ 400 convbuf = malloc((insize + 1) * sizeof(*convbuf)); 401 if (convbuf == NULL) 402 return (NULL); 403 wcp = convbuf; 404 p = mbsarg; |
405 mbs = initial; |
|
399 while (insize != 0) { | 406 while (insize != 0) { |
400 nconv = mbrtowc(wcp, p, insize, NULL); | 407 nconv = mbrtowc(wcp, p, insize, &mbs); |
401 if (nconv == 0 || nconv == (size_t)-1 || nconv == (size_t)-2) 402 break; 403 wcp++; 404 p += nconv; 405 insize -= nconv; 406 } 407 if (nconv == (size_t)-1 || nconv == (size_t)-2) { 408 free(convbuf); --- 1230 unchanged lines hidden --- | 408 if (nconv == 0 || nconv == (size_t)-1 || nconv == (size_t)-2) 409 break; 410 wcp++; 411 p += nconv; 412 insize -= nconv; 413 } 414 if (nconv == (size_t)-1 || nconv == (size_t)-2) { 415 free(convbuf); --- 1230 unchanged lines hidden --- |