4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1986 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
43 * wsscanf -- this function will read wchar_t characters from
44 * wchar_t string according to the conversion format.
45 * Note that the performance degrades if the intermediate
46 * result of conversion exceeds 1024 bytes due to the
47 * use of malloc() on each call.
48 * We should implement wchar_t version of doscan()
49 * for better performance.
54 wsscanf(wchar_t *string
, const char *format
, ...)
58 char stackbuf
[MAXINSTR
];
59 char *tempstring
= stackbuf
;
63 i
= wcstombs(tempstring
, string
, MAXINSTR
);
67 if (i
== MAXINSTR
) { /* The buffer was too small. Malloc it. */
68 tempstring
= malloc(malloced
= MB_CUR_MAX
*wcslen(string
)+1);
71 i
= wcstombs(tempstring
, string
, malloced
); /* Try again. */
72 if (i
== (size_t)-1) {
79 j
= vsscanf(tempstring
, format
, ap
);
81 if (malloced
) free(tempstring
);