]> git.saurik.com Git - apple/libc.git/blob - stdio/FreeBSD/snprintf.c.patch
Libc-763.13.tar.gz
[apple/libc.git] / stdio / FreeBSD / snprintf.c.patch
1 --- snprintf.c.orig 2009-11-30 16:15:30.000000000 -0800
2 +++ snprintf.c 2009-12-02 16:48:44.000000000 -0800
3 @@ -36,6 +36,8 @@ static char sccsid[] = "@(#)snprintf.c 8
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/stdio/snprintf.c,v 1.22 2008/04/17 22:17:54 jhb Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include <limits.h>
10 #include <stdio.h>
11 #include <stdarg.h>
12 @@ -45,26 +47,24 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/s
13 int
14 snprintf(char * __restrict str, size_t n, char const * __restrict fmt, ...)
15 {
16 - size_t on;
17 int ret;
18 va_list ap;
19 - FILE f;
20
21 - on = n;
22 - if (n != 0)
23 - n--;
24 - if (n > INT_MAX)
25 - n = INT_MAX;
26 va_start(ap, fmt);
27 - f._file = -1;
28 - f._flags = __SWR | __SSTR;
29 - f._bf._base = f._p = (unsigned char *)str;
30 - f._bf._size = f._w = n;
31 - f._orientation = 0;
32 - memset(&f._mbstate, 0, sizeof(mbstate_t));
33 - ret = __vfprintf(&f, fmt, ap);
34 - if (on > 0)
35 - *f._p = '\0';
36 + ret = vsnprintf_l(str, n, __current_locale(), fmt, ap);
37 + va_end(ap);
38 + return (ret);
39 +}
40 +
41 +int
42 +snprintf_l(char * __restrict str, size_t n, locale_t loc,
43 + char const * __restrict fmt, ...)
44 +{
45 + int ret;
46 + va_list ap;
47 +
48 + va_start(ap, fmt);
49 + ret = vsnprintf_l(str, n, loc, fmt, ap);
50 va_end(ap);
51 return (ret);
52 }