2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include "lint.h"
2N/A#include "file64.h"
2N/A#include <mtlib.h>
2N/A#include <stdio.h>
2N/A#include <stdarg.h>
2N/A#include <string.h>
2N/A#include <thread.h>
2N/A#include <synch.h>
2N/A#include <wchar.h>
2N/A#include <errno.h>
2N/A#include <stdlib.h>
2N/A#include <alloca.h>
2N/A#include "mse.h"
2N/A#include "stdiom.h"
2N/A#include "libc.h"
2N/A
2N/Aint
2N/A#ifdef _C89_INTMAX32 /* _C89_INTMAX32 version in 32-bit libc only */
2N/A_vwscanf_c89(const wchar_t *fmt, va_list ap)
2N/A#else
2N/Avwscanf(const wchar_t *fmt, va_list ap)
2N/A#endif
2N/A{
2N/A rmutex_t *lk;
2N/A int ret;
2N/A
2N/A FLOCKFILE(lk, stdin);
2N/A
2N/A if (_set_orientation_wide(stdin, NULL, NULL, 0) == -1) {
2N/A errno = EBADF;
2N/A FUNLOCKFILE(lk);
2N/A return (EOF);
2N/A }
2N/A
2N/A#ifdef _C89_INTMAX32
2N/A ret = __wdoscan_u(stdin, fmt, ap, _F_INTMAX32);
2N/A#else
2N/A ret = __wdoscan_u(stdin, fmt, ap, 0);
2N/A#endif
2N/A FUNLOCKFILE(lk);
2N/A return (ret);
2N/A}
2N/A
2N/Aint
2N/A#ifdef _C89_INTMAX32 /* _C89_INTMAX32 version in 32-bit libc only */
2N/A_vfwscanf_c89(FILE *iop, const wchar_t *fmt, va_list ap)
2N/A#else
2N/Avfwscanf(FILE *iop, const wchar_t *fmt, va_list ap)
2N/A#endif
2N/A{
2N/A rmutex_t *lk;
2N/A int ret;
2N/A
2N/A FLOCKFILE(lk, iop);
2N/A
2N/A if (_set_orientation_wide(iop, NULL, NULL, 0) == -1) {
2N/A errno = EBADF;
2N/A FUNLOCKFILE(lk);
2N/A return (EOF);
2N/A }
2N/A
2N/A
2N/A#ifdef _C89_INTMAX32
2N/A ret = __wdoscan_u(iop, fmt, ap, _F_INTMAX32);
2N/A#else
2N/A ret = __wdoscan_u(iop, fmt, ap, 0);
2N/A#endif
2N/A FUNLOCKFILE(lk);
2N/A return (ret);
2N/A}
2N/A
2N/Aint
2N/A#ifdef _C89_INTMAX32 /* _C89_INTMAX32 version in 32-bit libc only */
2N/A_vswscanf_c89(const wchar_t *wstr, const wchar_t *fmt, va_list ap)
2N/A#else
2N/Avswscanf(const wchar_t *wstr, const wchar_t *fmt, va_list ap)
2N/A#endif
2N/A{
2N/A FILE strbuf;
2N/A size_t wlen, clen;
2N/A char *tmp_buf;
2N/A int ret;
2N/A
2N/A /*
2N/A * The dummy FILE * created for swscanf has the _IOWRT
2N/A * flag set to distinguish it from wscanf and fwscanf
2N/A * invocations.
2N/A */
2N/A
2N/A clen = wcstombs(NULL, wstr, 0);
2N/A if (clen == (size_t)-1) {
2N/A errno = EILSEQ;
2N/A return (EOF);
2N/A }
2N/A tmp_buf = alloca(sizeof (char) * (clen + 1));
2N/A if (tmp_buf == NULL)
2N/A return (EOF);
2N/A wlen = wcstombs(tmp_buf, wstr, clen + 1);
2N/A if (wlen == (size_t)-1) {
2N/A errno = EILSEQ;
2N/A return (EOF);
2N/A }
2N/A
2N/A strbuf._flag = _IOREAD | _IOWRT;
2N/A strbuf._ptr = strbuf._base = (unsigned char *)tmp_buf;
2N/A strbuf._cnt = strlen(tmp_buf);
2N/A SET_FILE(&strbuf, _NFILE);
2N/A
2N/A /* Probably the following is not required. */
2N/A /* _setorientation(&strbuf, _WC_MODE); */
2N/A
2N/A#ifdef _C89_INTMAX32
2N/A ret = __wdoscan_u(&strbuf, fmt, ap, _F_INTMAX32);
2N/A#else
2N/A ret = __wdoscan_u(&strbuf, fmt, ap, 0);
2N/A#endif
2N/A return (ret);
2N/A}