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) 1988 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
33 #pragma weak _vscanf = vscanf
34 #pragma weak _vfscanf = vfscanf
35 #pragma weak _vsscanf = vsscanf
49 #include <stdio_ext.h>
53 * 32-bit shadow functions _vscanf_c89(), _vfscanf_c89(), _vsscanf_c89()
55 * When using the c89 compiler to build 32-bit applications, the size
56 * of intmax_t is 32-bits, otherwise the size of intmax_t is 64-bits.
57 * The shadow function uses 32-bit size of intmax_t for %j conversion.
58 * The #pragma redefine_extname in <stdio.h> selects the proper routine
59 * at compile time for the user application.
60 * NOTE: the shadow function only exists in the 32-bit library.
64 #ifdef _C89_INTMAX32 /* _C89_INTMAX32 version in 32-bit libc only */
65 _vscanf_c89(const char *fmt
, va_list ap
)
67 vscanf(const char *fmt
, va_list ap
)
75 _SET_ORIENTATION_BYTE(stdin
);
78 ret
= __doscan_u(stdin
, fmt
, ap
, _F_INTMAX32
);
80 ret
= __doscan_u(stdin
, fmt
, ap
, 0);
88 #ifdef _C89_INTMAX32 /* _C89_INTMAX32 version in 32-bit libc only */
89 _vfscanf_c89(FILE *iop
, const char *fmt
, va_list ap
)
91 vfscanf(FILE *iop
, const char *fmt
, va_list ap
)
99 _SET_ORIENTATION_BYTE(iop
);
102 ret
= __doscan_u(iop
, fmt
, ap
, _F_INTMAX32
);
104 ret
= __doscan_u(iop
, fmt
, ap
, 0);
111 #ifdef _C89_INTMAX32 /* _C89_INTMAX32 version in 32-bit libc only */
112 _vsscanf_c89(const char *str
, const char *fmt
, va_list ap
)
114 vsscanf(const char *str
, const char *fmt
, va_list ap
)
120 * The dummy FILE * created for sscanf has the _IOWRT
121 * flag set to distinguish it from scanf and fscanf
124 strbuf
._flag
= _IOREAD
| _IOWRT
;
125 strbuf
._ptr
= strbuf
._base
= (unsigned char *)str
;
126 strbuf
._cnt
= strlen(str
);
127 SET_FILE(&strbuf
, _NFILE
);
130 * Mark the stream so that routines called by __doscan_u()
131 * do not do any locking. In particular this avoids a NULL
132 * lock pointer being used by getc() causing a core dump.
133 * See bugid - 1210179 program SEGV's in sscanf if linked with
135 * This also makes sscanf() quicker since it does not need
138 if (__fsetlocking(&strbuf
, FSETLOCKING_BYCALLER
) == -1) {
139 return (-1); /* this should never happen */
142 /* as this stream is local to this function, no locking is be done */
144 return (__doscan_u(&strbuf
, fmt
, ap
, _F_INTMAX32
));
146 return (__doscan_u(&strbuf
, fmt
, ap
, 0));