vswscanf.c (bad3b6889aecd4b42701fd9b1e63f3cefa1595a4) vswscanf.c (1b0181df2f46ef73a41ea8c9b7026718f8eec3a1)
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Donn Seeley at UUNET Technologies, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 48 unchanged lines hidden (view full) ---

57}
58
59int
60vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt,
61 va_list ap)
62{
63 static const mbstate_t initial;
64 mbstate_t mbs;
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Donn Seeley at UUNET Technologies, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 48 unchanged lines hidden (view full) ---

57}
58
59int
60vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt,
61 va_list ap)
62{
63 static const mbstate_t initial;
64 mbstate_t mbs;
65 FILE f;
65 FILE f = FAKE_FILE;
66 char *mbstr;
67 size_t mlen;
68 int r;
69 const wchar_t *strp;
70
71 /*
72 * XXX Convert the wide character string to multibyte, which
73 * __vfwscanf() will convert back to wide characters.
74 */
75 if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX + 1)) == NULL)
76 return (EOF);
77 mbs = initial;
78 strp = str;
79 if ((mlen = wcsrtombs(mbstr, &strp, SIZE_T_MAX, &mbs)) == (size_t)-1) {
80 free(mbstr);
81 return (EOF);
82 }
66 char *mbstr;
67 size_t mlen;
68 int r;
69 const wchar_t *strp;
70
71 /*
72 * XXX Convert the wide character string to multibyte, which
73 * __vfwscanf() will convert back to wide characters.
74 */
75 if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX + 1)) == NULL)
76 return (EOF);
77 mbs = initial;
78 strp = str;
79 if ((mlen = wcsrtombs(mbstr, &strp, SIZE_T_MAX, &mbs)) == (size_t)-1) {
80 free(mbstr);
81 return (EOF);
82 }
83 f._file = -1;
84 f._flags = __SRD;
85 f._bf._base = f._p = (unsigned char *)mbstr;
86 f._bf._size = f._r = mlen;
87 f._read = eofread;
83 f._flags = __SRD;
84 f._bf._base = f._p = (unsigned char *)mbstr;
85 f._bf._size = f._r = mlen;
86 f._read = eofread;
88 f._ub._base = NULL;
89 f._lb._base = NULL;
90 f._orientation = 0;
91 memset(&f._mbstate, 0, sizeof(mbstate_t));
92 r = __vfwscanf(&f, fmt, ap);
93 free(mbstr);
94
95 return (r);
96}
87 r = __vfwscanf(&f, fmt, ap);
88 free(mbstr);
89
90 return (r);
91}