]> git.saurik.com Git - apple/libc.git/blobdiff - stdio/FreeBSD/asprintf.c.patch
Libc-391.tar.gz
[apple/libc.git] / stdio / FreeBSD / asprintf.c.patch
diff --git a/stdio/FreeBSD/asprintf.c.patch b/stdio/FreeBSD/asprintf.c.patch
new file mode 100644 (file)
index 0000000..1f21732
--- /dev/null
@@ -0,0 +1,54 @@
+--- asprintf.c.orig    2003-05-20 15:22:40.000000000 -0700
++++ asprintf.c 2005-02-23 16:17:23.000000000 -0800
+@@ -30,6 +30,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/asprintf.c,v 1.13 2002/09/26 13:09:48 tjr Exp $");
++#include "xlocale_private.h"
++
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <errno.h>
+@@ -57,7 +59,41 @@
+       f._extra = &ext;
+       INITEXTRA(&f);
+       va_start(ap, fmt);
+-      ret = __vfprintf(&f, fmt, ap);          /* Use unlocked __vfprintf */
++      ret = __vfprintf(&f, __current_locale(), fmt, ap);      /* Use unlocked __vfprintf */
++      va_end(ap);
++      if (ret < 0) {
++              free(f._bf._base);
++              *str = NULL;
++              errno = ENOMEM;
++              return (-1);
++      }
++      *f._p = '\0';
++      *str = (char *)f._bf._base;
++      return (ret);
++}
++
++int
++asprintf_l(char **str, locale_t loc, char const *fmt, ...)
++{
++      int ret;
++      va_list ap;
++      FILE f;
++      struct __sFILEX ext;
++
++      NORMALIZE_LOCALE(loc);
++      f._file = -1;
++      f._flags = __SWR | __SSTR | __SALC;
++      f._bf._base = f._p = (unsigned char *)malloc(128);
++      if (f._bf._base == NULL) {
++              *str = NULL;
++              errno = ENOMEM;
++              return (-1);
++      }
++      f._bf._size = f._w = 127;               /* Leave room for the NUL */
++      f._extra = &ext;
++      INITEXTRA(&f);
++      va_start(ap, fmt);
++      ret = __vfprintf(&f, loc, fmt, ap);     /* Use unlocked __vfprintf */
+       va_end(ap);
+       if (ret < 0) {
+               free(f._bf._base);