]> git.saurik.com Git - apple/libc.git/blob - stdio/FreeBSD/snprintf.c.patch
Libc-391.2.3.tar.gz
[apple/libc.git] / stdio / FreeBSD / snprintf.c.patch
1 --- snprintf.c.orig 2003-05-20 15:22:43.000000000 -0700
2 +++ snprintf.c 2005-02-23 16:39:33.000000000 -0800
3 @@ -40,6 +40,8 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/stdio/snprintf.c,v 1.20 2002/09/06 11:23:55 tjr Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include <limits.h>
10 #include <stdio.h>
11 #include <stdarg.h>
12 @@ -67,7 +69,37 @@
13 f._bf._size = f._w = n;
14 f._extra = &ext;
15 INITEXTRA(&f);
16 - ret = __vfprintf(&f, fmt, ap);
17 + ret = __vfprintf(&f, __current_locale(), fmt, ap);
18 + if (on > 0)
19 + *f._p = '\0';
20 + va_end(ap);
21 + return (ret);
22 +}
23 +
24 +int
25 +snprintf_l(char * __restrict str, size_t n, locale_t loc,
26 + char const * __restrict fmt, ...)
27 +{
28 + size_t on;
29 + int ret;
30 + va_list ap;
31 + FILE f;
32 + struct __sFILEX ext;
33 +
34 + NORMALIZE_LOCALE(loc);
35 + on = n;
36 + if (n != 0)
37 + n--;
38 + if (n > INT_MAX)
39 + n = INT_MAX;
40 + va_start(ap, fmt);
41 + f._file = -1;
42 + f._flags = __SWR | __SSTR;
43 + f._bf._base = f._p = (unsigned char *)str;
44 + f._bf._size = f._w = n;
45 + f._extra = &ext;
46 + INITEXTRA(&f);
47 + ret = __vfprintf(&f, loc, fmt, ap);
48 if (on > 0)
49 *f._p = '\0';
50 va_end(ap);