]> git.saurik.com Git - apple/libc.git/blame - stdio/FreeBSD/vswscanf.c.patch
Libc-594.9.5.tar.gz
[apple/libc.git] / stdio / FreeBSD / vswscanf.c.patch
CommitLineData
3d9156a7
A
1--- vswscanf.c.orig 2004-11-25 11:38:36.000000000 -0800
2+++ vswscanf.c 2005-02-23 17:03:30.000000000 -0800
3@@ -43,6 +43,8 @@
4 #endif
5 __FBSDID("$FreeBSD: src/lib/libc/stdio/vswscanf.c,v 1.3 2004/04/07 09:55:05 tjr Exp $");
6
7+#include "xlocale_private.h"
8+
9 #include <limits.h>
10 #include <stdarg.h>
11 #include <stdio.h>
12@@ -71,15 +73,55 @@
13 char *mbstr;
14 size_t mlen;
15 int r;
16+ locale_t loc = __current_locale();
17+
18+ /*
19+ * XXX Convert the wide character string to multibyte, which
20+ * __vfwscanf() will convert back to wide characters.
21+ */
22+ if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX_L(loc) + 1)) == NULL)
23+ return (EOF);
24+ mbs = initial;
25+ if ((mlen = wcsrtombs_l(mbstr, &str, SIZE_T_MAX, &mbs, loc)) == (size_t)-1) {
26+ free(mbstr);
27+ return (EOF);
28+ }
29+ f._file = -1;
30+ f._flags = __SRD;
31+ f._bf._base = f._p = (unsigned char *)mbstr;
32+ f._bf._size = f._r = mlen;
33+ f._read = eofread;
34+ f._ub._base = NULL;
35+ f._lb._base = NULL;
36+ f._extra = &ext;
37+ INITEXTRA(&f);
38+ r = __vfwscanf(&f, loc, fmt, ap);
39+ free(mbstr);
40+
41+ return (r);
42+}
43+
44+int
45+vswscanf_l(const wchar_t * __restrict str, locale_t loc,
46+ const wchar_t * __restrict fmt, va_list ap)
47+{
48+ static const mbstate_t initial;
49+ mbstate_t mbs;
50+ FILE f;
51+ struct __sFILEX ext;
52+ char *mbstr;
53+ size_t mlen;
54+ int r;
55
56+ NORMALIZE_LOCALE(loc);
57 /*
58 * XXX Convert the wide character string to multibyte, which
59 * __vfwscanf() will convert back to wide characters.
60 */
61- if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX + 1)) == NULL)
62+ if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX_L(loc) + 1)) == NULL)
63 return (EOF);
64 mbs = initial;
65- if ((mlen = wcsrtombs(mbstr, &str, SIZE_T_MAX, &mbs)) == (size_t)-1) {
66+ if ((mlen = wcsrtombs_l(mbstr, &str, SIZE_T_MAX, &mbs, loc)) == (size_t)-1) {
67 free(mbstr);
68 return (EOF);
69 }
70@@ -92,7 +134,7 @@
71 f._lb._base = NULL;
72 f._extra = &ext;
73 INITEXTRA(&f);
74- r = __vfwscanf(&f, fmt, ap);
75+ r = __vfwscanf(&f, loc, fmt, ap);
76 free(mbstr);
77
78 return (r);