]> git.saurik.com Git - apple/libc.git/blob - stdio/FreeBSD/fputws.c.patch
Libc-763.12.tar.gz
[apple/libc.git] / stdio / FreeBSD / fputws.c.patch
1 --- fputws.c.orig 2010-03-18 18:11:42.000000000 -0700
2 +++ fputws.c 2010-03-18 18:17:53.000000000 -0700
3 @@ -27,6 +27,8 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/stdio/fputws.c,v 1.8 2009/01/15 18:53:52 rdivacky Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include "namespace.h"
10 #include <errno.h>
11 #include <limits.h>
12 @@ -39,14 +41,18 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/f
13 #include "mblocal.h"
14
15 int
16 -fputws(const wchar_t * __restrict ws, FILE * __restrict fp)
17 +fputws_l(const wchar_t * __restrict ws, FILE * __restrict fp, locale_t loc)
18 {
19 size_t nbytes;
20 char buf[BUFSIZ];
21 struct __suio uio;
22 struct __siov iov;
23 - const wchar_t *wsp;
24 + const wchar_t *wsp = ws;
25 + size_t (*__wcsnrtombs)(char * __restrict, const wchar_t ** __restrict,
26 + size_t, size_t, mbstate_t * __restrict, locale_t);
27
28 + NORMALIZE_LOCALE(loc);
29 + __wcsnrtombs = loc->__lc_ctype->__wcsnrtombs;
30 FLOCKFILE(fp);
31 ORIENT(fp, 1);
32 if (prepwrite(fp) != 0)
33 @@ -55,15 +61,14 @@ fputws(const wchar_t * __restrict ws, FI
34 uio.uio_iovcnt = 1;
35 iov.iov_base = buf;
36 do {
37 - wsp = ws;
38 nbytes = __wcsnrtombs(buf, &wsp, SIZE_T_MAX, sizeof(buf),
39 - &fp->_mbstate);
40 + &fp->_mbstate, loc);
41 if (nbytes == (size_t)-1)
42 goto error;
43 iov.iov_len = uio.uio_resid = nbytes;
44 if (__sfvwrite(fp, &uio) != 0)
45 goto error;
46 - } while (ws != NULL);
47 + } while (wsp != NULL);
48 FUNLOCKFILE(fp);
49 return (0);
50
51 @@ -71,3 +76,9 @@ error:
52 FUNLOCKFILE(fp);
53 return (-1);
54 }
55 +
56 +int
57 +fputws(const wchar_t * __restrict ws, FILE * __restrict fp)
58 +{
59 + return fputws_l(ws, fp, __current_locale());
60 +}