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