10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51846Scraigm * Common Development and Distribution License (the "License").
61846Scraigm * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
211846Scraigm
220Sstevel@tonic-gate /*
23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
301846Scraigm #pragma ident "%Z%%M% %I% %E% SMI"
311846Scraigm
320Sstevel@tonic-gate #ifndef _C89_INTMAX32
33*6812Sraf #pragma weak _vscanf = vscanf
34*6812Sraf #pragma weak _vfscanf = vfscanf
35*6812Sraf #pragma weak _vsscanf = vsscanf
360Sstevel@tonic-gate #endif
370Sstevel@tonic-gate
38*6812Sraf #include "lint.h"
390Sstevel@tonic-gate #include "file64.h"
400Sstevel@tonic-gate #include "mtlib.h"
410Sstevel@tonic-gate #include <stdio.h>
420Sstevel@tonic-gate #include <stdarg.h>
430Sstevel@tonic-gate #include <string.h>
440Sstevel@tonic-gate #include <thread.h>
450Sstevel@tonic-gate #include <synch.h>
460Sstevel@tonic-gate #include "libc.h"
470Sstevel@tonic-gate #include "stdiom.h"
480Sstevel@tonic-gate #include "mse.h"
490Sstevel@tonic-gate #include <stdio_ext.h>
500Sstevel@tonic-gate
510Sstevel@tonic-gate
520Sstevel@tonic-gate /*
530Sstevel@tonic-gate * 32-bit shadow functions _vscanf_c89(), _vfscanf_c89(), _vsscanf_c89()
540Sstevel@tonic-gate * are included here.
550Sstevel@tonic-gate * When using the c89 compiler to build 32-bit applications, the size
560Sstevel@tonic-gate * of intmax_t is 32-bits, otherwise the size of intmax_t is 64-bits.
570Sstevel@tonic-gate * The shadow function uses 32-bit size of intmax_t for %j conversion.
580Sstevel@tonic-gate * The #pragma redefine_extname in <stdio.h> selects the proper routine
590Sstevel@tonic-gate * at compile time for the user application.
600Sstevel@tonic-gate * NOTE: the shadow function only exists in the 32-bit library.
610Sstevel@tonic-gate */
620Sstevel@tonic-gate
630Sstevel@tonic-gate int
640Sstevel@tonic-gate #ifdef _C89_INTMAX32 /* _C89_INTMAX32 version in 32-bit libc only */
_vscanf_c89(const char * fmt,va_list ap)650Sstevel@tonic-gate _vscanf_c89(const char *fmt, va_list ap)
660Sstevel@tonic-gate #else
670Sstevel@tonic-gate vscanf(const char *fmt, va_list ap)
680Sstevel@tonic-gate #endif
690Sstevel@tonic-gate {
700Sstevel@tonic-gate rmutex_t *lk;
710Sstevel@tonic-gate int ret;
720Sstevel@tonic-gate
730Sstevel@tonic-gate FLOCKFILE(lk, stdin);
740Sstevel@tonic-gate
750Sstevel@tonic-gate _SET_ORIENTATION_BYTE(stdin);
760Sstevel@tonic-gate
770Sstevel@tonic-gate #ifdef _C89_INTMAX32
780Sstevel@tonic-gate ret = __doscan_u(stdin, fmt, ap, _F_INTMAX32);
790Sstevel@tonic-gate #else
800Sstevel@tonic-gate ret = __doscan_u(stdin, fmt, ap, 0);
810Sstevel@tonic-gate #endif
820Sstevel@tonic-gate
830Sstevel@tonic-gate FUNLOCKFILE(lk);
840Sstevel@tonic-gate return (ret);
850Sstevel@tonic-gate }
860Sstevel@tonic-gate
870Sstevel@tonic-gate int
880Sstevel@tonic-gate #ifdef _C89_INTMAX32 /* _C89_INTMAX32 version in 32-bit libc only */
_vfscanf_c89(FILE * iop,const char * fmt,va_list ap)890Sstevel@tonic-gate _vfscanf_c89(FILE *iop, const char *fmt, va_list ap)
900Sstevel@tonic-gate #else
910Sstevel@tonic-gate vfscanf(FILE *iop, const char *fmt, va_list ap)
920Sstevel@tonic-gate #endif
930Sstevel@tonic-gate {
940Sstevel@tonic-gate rmutex_t *lk;
950Sstevel@tonic-gate int ret;
960Sstevel@tonic-gate
970Sstevel@tonic-gate FLOCKFILE(lk, iop);
980Sstevel@tonic-gate
990Sstevel@tonic-gate _SET_ORIENTATION_BYTE(iop);
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate #ifdef _C89_INTMAX32
1020Sstevel@tonic-gate ret = __doscan_u(iop, fmt, ap, _F_INTMAX32);
1030Sstevel@tonic-gate #else
1040Sstevel@tonic-gate ret = __doscan_u(iop, fmt, ap, 0);
1050Sstevel@tonic-gate #endif
1060Sstevel@tonic-gate FUNLOCKFILE(lk);
1070Sstevel@tonic-gate return (ret);
1080Sstevel@tonic-gate }
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate int
1110Sstevel@tonic-gate #ifdef _C89_INTMAX32 /* _C89_INTMAX32 version in 32-bit libc only */
_vsscanf_c89(const char * str,const char * fmt,va_list ap)1120Sstevel@tonic-gate _vsscanf_c89(const char *str, const char *fmt, va_list ap)
1130Sstevel@tonic-gate #else
1140Sstevel@tonic-gate vsscanf(const char *str, const char *fmt, va_list ap)
1150Sstevel@tonic-gate #endif
1160Sstevel@tonic-gate {
1170Sstevel@tonic-gate FILE strbuf;
1180Sstevel@tonic-gate
1190Sstevel@tonic-gate /*
1200Sstevel@tonic-gate * The dummy FILE * created for sscanf has the _IOWRT
1210Sstevel@tonic-gate * flag set to distinguish it from scanf and fscanf
1220Sstevel@tonic-gate * invocations.
1230Sstevel@tonic-gate */
1240Sstevel@tonic-gate strbuf._flag = _IOREAD | _IOWRT;
1250Sstevel@tonic-gate strbuf._ptr = strbuf._base = (unsigned char *)str;
1260Sstevel@tonic-gate strbuf._cnt = strlen(str);
1271846Scraigm SET_FILE(&strbuf, _NFILE);
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate /*
1300Sstevel@tonic-gate * Mark the stream so that routines called by __doscan_u()
1310Sstevel@tonic-gate * do not do any locking. In particular this avoids a NULL
1320Sstevel@tonic-gate * lock pointer being used by getc() causing a core dump.
1330Sstevel@tonic-gate * See bugid - 1210179 program SEGV's in sscanf if linked with
1340Sstevel@tonic-gate * the libthread.
1350Sstevel@tonic-gate * This also makes sscanf() quicker since it does not need
1360Sstevel@tonic-gate * to do any locking.
1370Sstevel@tonic-gate */
1380Sstevel@tonic-gate if (__fsetlocking(&strbuf, FSETLOCKING_BYCALLER) == -1) {
1390Sstevel@tonic-gate return (-1); /* this should never happen */
1400Sstevel@tonic-gate }
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate /* as this stream is local to this function, no locking is be done */
1430Sstevel@tonic-gate #ifdef _C89_INTMAX32
1440Sstevel@tonic-gate return (__doscan_u(&strbuf, fmt, ap, _F_INTMAX32));
1450Sstevel@tonic-gate #else
1460Sstevel@tonic-gate return (__doscan_u(&strbuf, fmt, ap, 0));
1470Sstevel@tonic-gate #endif
1480Sstevel@tonic-gate }
149