]> git.saurik.com Git - apple/libc.git/blame - stdio/FreeBSD/vsnprintf.c.patch
Libc-594.9.5.tar.gz
[apple/libc.git] / stdio / FreeBSD / vsnprintf.c.patch
CommitLineData
3d9156a7
A
1--- vsnprintf.c.orig 2003-07-24 12:42:14.000000000 -0700
2+++ vsnprintf.c 2005-02-23 16:54:44.000000000 -0800
3@@ -40,6 +40,8 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/stdio/vsnprintf.c,v 1.22 2003/07/02 07:08:44 jkh Exp $");
6
7+#include "xlocale_private.h"
8+
9 #include <limits.h>
10 #include <stdio.h>
11 #include "local.h"
12@@ -72,7 +74,42 @@
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+ return (ret);
21+}
22+
23+int
24+vsnprintf_l(char * __restrict str, size_t n, locale_t loc,
25+ const char * __restrict fmt, __va_list ap)
26+{
27+ size_t on;
28+ int ret;
29+ char dummy[2];
30+ FILE f;
31+ struct __sFILEX ext;
32+
33+ NORMALIZE_LOCALE(loc);
34+ on = n;
35+ if (n != 0)
36+ n--;
37+ if (n > INT_MAX)
38+ n = INT_MAX;
39+ /* Stdio internals do not deal correctly with zero length buffer */
40+ if (n == 0) {
41+ if (on > 0)
42+ *str = '\0';
43+ str = dummy;
44+ n = 1;
45+ }
46+ f._file = -1;
47+ f._flags = __SWR | __SSTR;
48+ f._bf._base = f._p = (unsigned char *)str;
49+ f._bf._size = f._w = n;
50+ f._extra = &ext;
51+ INITEXTRA(&f);
52+ ret = __vfprintf(&f, loc, fmt, ap);
53 if (on > 0)
54 *f._p = '\0';
55 return (ret);