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