1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
28 Sfdisc_t sfdisc
; /* sfio discipline */
29 Sfio_t
* f
; /* original wide stream */
30 char fmt
[1]; /* mb fmt */
34 * wide exception handler
39 wideexcept(Sfio_t
* f
, int op
, void* val
, Sfdisc_t
* dp
)
46 sfdisc(f
, SF_POPDISC
);
59 * sfio wide discipline read
61 * go pure multibyte for best performance
65 wideread(Sfio_t
* f
, Void_t
* buf
, size_t size
, Sfdisc_t
* dp
)
67 register Wide_t
* w
= (Wide_t
*)dp
;
71 if (sfread(w
->f
, wuf
, sizeof(wuf
[0])) != sizeof(wuf
[0]))
74 return wcstombs(buf
, wuf
, size
);
78 r
= sfread(w
->f
, wuf
, sizeof(wuf
[0]));
79 if (r
!= sizeof(wuf
[0]))
82 r
= wcstombs(buf
, wuf
, size
);
88 vfwscanf(Sfio_t
* f
, const wchar_t* fmt
, va_list args
)
96 STDIO_INT(f
, "vfwscanf", int, (Sfio_t
*, const wchar_t*, va_list), (f
, fmt
, args
))
99 n
= wcstombs(NiL
, fmt
, 0);
100 if (w
= newof(0, Wide_t
, 1, n
))
102 if (t
= sfnew(NiL
, buf
, sizeof(buf
), OPEN_MAX
+1, SF_READ
))
104 w
->sfdisc
.exceptf
= wideexcept
;
105 w
->sfdisc
.readf
= wideread
;
107 if (sfdisc(t
, &w
->sfdisc
) == &w
->sfdisc
)
109 wcstombs(w
->fmt
, fmt
, n
+ 1);
110 v
= sfvscanf(t
, w
->fmt
, args
);