]> git.saurik.com Git - apple/libc.git/blob - stdio/FreeBSD/vasprintf.c.patch
Libc-498.1.5.tar.gz
[apple/libc.git] / stdio / FreeBSD / vasprintf.c.patch
1 --- vasprintf.c.orig 2003-05-20 15:22:44.000000000 -0700
2 +++ vasprintf.c 2005-02-23 18:55:18.000000000 -0800
3 @@ -30,6 +30,8 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/stdio/vasprintf.c,v 1.18 2002/09/26 13:11:24 tjr Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <errno.h>
12 @@ -56,7 +58,42 @@
13 f._bf._size = f._w = 127; /* Leave room for the NUL */
14 f._extra = &ext;
15 INITEXTRA(&f);
16 - ret = __vfprintf(&f, fmt, ap);
17 + ret = __vfprintf(&f, __current_locale(), fmt, ap);
18 + if (ret < 0) {
19 + free(f._bf._base);
20 + *str = NULL;
21 + errno = ENOMEM;
22 + return (-1);
23 + }
24 + *f._p = '\0';
25 + *str = (char *)f._bf._base;
26 + return (ret);
27 +}
28 +
29 +int
30 +vasprintf_l(str, loc, fmt, ap)
31 + char **str;
32 + locale_t loc;
33 + const char *fmt;
34 + __va_list ap;
35 +{
36 + int ret;
37 + FILE f;
38 + struct __sFILEX ext;
39 +
40 + NORMALIZE_LOCALE(loc);
41 + f._file = -1;
42 + f._flags = __SWR | __SSTR | __SALC;
43 + f._bf._base = f._p = (unsigned char *)malloc(128);
44 + if (f._bf._base == NULL) {
45 + *str = NULL;
46 + errno = ENOMEM;
47 + return (-1);
48 + }
49 + f._bf._size = f._w = 127; /* Leave room for the NUL */
50 + f._extra = &ext;
51 + INITEXTRA(&f);
52 + ret = __vfprintf(&f, loc, fmt, ap);
53 if (ret < 0) {
54 free(f._bf._base);
55 *str = NULL;