Loading...
stdio/FreeBSD/vfwprintf.c.patch Libc-763.13 Libc-391.5.22
--- Libc/Libc-763.13/stdio/FreeBSD/vfwprintf.c.patch
+++ Libc/Libc-391.5.22/stdio/FreeBSD/vfwprintf.c.patch
@@ -1,15 +1,15 @@
---- vfwprintf.c.orig	2010-07-15 10:03:36.000000000 -0700
-+++ vfwprintf.c	2010-07-15 10:49:02.000000000 -0700
-@@ -38,6 +38,8 @@ static char sccsid[] = "@(#)vfprintf.c	8
+--- vfwprintf.c.orig	2004-11-25 11:38:36.000000000 -0800
++++ vfwprintf.c	2005-11-08 22:46:07.000000000 -0800
+@@ -42,6 +42,8 @@
  #include <sys/cdefs.h>
- __FBSDID("$FreeBSD: src/lib/libc/stdio/vfwprintf.c,v 1.42 2009/11/25 04:27:55 wollman Exp $");
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/vfwprintf.c,v 1.23 2004/08/26 06:25:28 des Exp $");
  
 +#include "xlocale_private.h"
 +
  /*
   * Actual wprintf innards.
   *
-@@ -59,6 +61,7 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/v
+@@ -63,12 +65,20 @@
  #include <string.h>
  #include <wchar.h>
  #include <wctype.h>
@@ -17,117 +17,66 @@
  #include "un-namespace.h"
  
  #include "libc_private.h"
-@@ -66,10 +69,11 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/v
+ #include "local.h"
  #include "fvwrite.h"
- #include "printflocal.h"
- 
--static int	__sprint(FILE *, struct __suio *);
--static int	__sbprintf(FILE *, const wchar_t *, va_list) __noinline;
+ 
++#ifdef VECTORS
++typedef __attribute__ ((vector_size(16))) unsigned char VECTORTYPE;
++#ifdef __SSE2__
++#define V64TYPE
++#endif /* __SSE2__ */
++#endif /* VECTORS */
++
+ union arg {
+ 	int	intarg;
+ 	u_int	uintarg;
+@@ -96,6 +106,21 @@
+ #endif
+ 	wint_t	wintarg;
+ 	wchar_t	*pwchararg;
++#ifdef VECTORS
++	VECTORTYPE		vectorarg;
++	unsigned char		vuchararg[16];
++	signed char		vchararg[16];
++	unsigned short		vushortarg[8];
++	signed short		vshortarg[8];
++	unsigned int		vuintarg[4];
++	signed int		vintarg[4];
++	float			vfloatarg[4];
++#ifdef V64TYPE
++	double			vdoublearg[2];
++	unsigned long long	vulonglongarg[2];
++	long long		vlonglongarg[2];
++#endif /* V64TYPE */
++#endif /* VECTORS */
+ };
+ 
+ /*
+@@ -106,16 +131,20 @@
+ 	T_LONG, T_U_LONG, TP_LONG, T_LLONG, T_U_LLONG, TP_LLONG,
+ 	T_PTRDIFFT, TP_PTRDIFFT, T_SIZET, TP_SIZET,
+ 	T_INTMAXT, T_UINTMAXT, TP_INTMAXT, TP_VOID, TP_CHAR, TP_SCHAR,
++#ifdef VECTORS
++	T_DOUBLE, T_LONG_DOUBLE, T_WINT, TP_WCHAR, T_VECTOR
++#else /* ! VECTORS */
+ 	T_DOUBLE, T_LONG_DOUBLE, T_WINT, TP_WCHAR
++#endif /* VECTORS */
+ };
+ 
+-static int	__sbprintf(FILE *, const wchar_t *, va_list);
 -static wint_t	__xfputwc(wchar_t, FILE *);
--static wchar_t	*__mbsconv(char *, int);
-+static int	__sprint(FILE *, locale_t, struct __suio *);
 +static int	__sbprintf(FILE *, locale_t, const wchar_t *, va_list);
 +static wint_t	__xfputwc(wchar_t, FILE *, locale_t);
+ static wchar_t	*__ujtoa(uintmax_t, wchar_t *, int, int, const char *, int,
+ 		    char, const char *);
+ static wchar_t	*__ultoa(u_long, wchar_t *, int, int, const char *, int,
+ 		    char, const char *);
+-static wchar_t	*__mbsconv(char *, int);
 +static wchar_t	*__mbsconv(char *, int, locale_t);
-+__private_extern__ const char *__fix_nogrouping(const char *);
- 
- #define	CHAR	wchar_t
- #include "printfcommon.h"
-@@ -85,29 +89,29 @@ struct grouping_state {
- static const mbstate_t initial_mbs;
- 
- static inline wchar_t
--get_decpt(void)
-+get_decpt(locale_t loc)
- {
- 	mbstate_t mbs;
- 	wchar_t decpt;
- 	int nconv;
- 
- 	mbs = initial_mbs;
--	nconv = mbrtowc(&decpt, localeconv()->decimal_point, MB_CUR_MAX, &mbs);
-+	nconv = mbrtowc_l(&decpt, localeconv_l(loc)->decimal_point, MB_CUR_MAX_L(loc), &mbs, loc);
- 	if (nconv == (size_t)-1 || nconv == (size_t)-2)
- 		decpt = '.';    /* failsafe */
- 	return (decpt);
- }
- 
- static inline wchar_t
--get_thousep(void)
-+get_thousep(locale_t loc)
- {
- 	mbstate_t mbs;
- 	wchar_t thousep;
- 	int nconv;
- 
- 	mbs = initial_mbs;
--	nconv = mbrtowc(&thousep, localeconv()->thousands_sep,
--	    MB_CUR_MAX, &mbs);
-+	nconv = mbrtowc_l(&thousep, localeconv_l(loc)->thousands_sep,
-+	    MB_CUR_MAX_L(loc), &mbs, loc);
- 	if (nconv == (size_t)-1 || nconv == (size_t)-2)
- 		thousep = '\0';    /* failsafe */
- 	return (thousep);
-@@ -119,11 +123,11 @@ get_thousep(void)
-  * of wide characters that will be printed.
-  */
- static int
--grouping_init(struct grouping_state *gs, int ndigits)
-+grouping_init(struct grouping_state *gs, int ndigits, locale_t loc)
- {
- 
--	gs->grouping = localeconv()->grouping;
--	gs->thousands_sep = get_thousep();
-+	gs->grouping = __fix_nogrouping(localeconv_l(loc)->grouping);
-+	gs->thousands_sep = get_thousep(loc);
- 
- 	gs->nseps = gs->nrepeats = 0;
- 	gs->lead = ndigits;
-@@ -145,11 +149,11 @@ grouping_init(struct grouping_state *gs,
-  */
- static int
- grouping_print(struct grouping_state *gs, struct io_state *iop,
--	       const CHAR *cp, const CHAR *ep)
-+	       const CHAR *cp, const CHAR *ep, locale_t loc)
- {
- 	const CHAR *cp0 = cp;
- 
--	if (io_printandpad(iop, cp, ep, gs->lead, zeroes))
-+	if (io_printandpad(iop, cp, ep, gs->lead, zeroes, loc))
- 		return (-1);
- 	cp += gs->lead;
- 	while (gs->nseps > 0 || gs->nrepeats > 0) {
-@@ -159,9 +163,9 @@ grouping_print(struct grouping_state *gs
- 			gs->grouping--;
- 			gs->nseps--;
- 		}
--		if (io_print(iop, &gs->thousands_sep, 1))
-+		if (io_print(iop, &gs->thousands_sep, 1, loc))
- 			return (-1);
--		if (io_printandpad(iop, cp, ep, *gs->grouping, zeroes))
-+		if (io_printandpad(iop, cp, ep, *gs->grouping, zeroes, loc))
- 			return (-1);
- 		cp += *gs->grouping;
- 	}
-@@ -180,7 +184,7 @@ grouping_print(struct grouping_state *gs
-  * string eclipses the benefits of buffering.
-  */
- static int
--__sprint(FILE *fp, struct __suio *uio)
-+__sprint(FILE *fp, locale_t loc, struct __suio *uio)
- {
- 	struct __siov *iov;
- 	wchar_t *p;
-@@ -191,7 +195,7 @@ __sprint(FILE *fp, struct __suio *uio)
- 		p = (wchar_t *)iov->iov_base;
- 		len = iov->iov_len;
- 		for (i = 0; i < len; i++) {
--			if (__xfputwc(p[i], fp) == WEOF)
-+			if (__xfputwc(p[i], fp, loc) == WEOF)
- 				return (-1);
- 		}
- 	}
-@@ -205,11 +209,14 @@ __sprint(FILE *fp, struct __suio *uio)
+ static void	__find_arguments(const wchar_t *, va_list, union arg **);
+ static void	__grow_type_table(int, enum typeid **, int *);
+ 
+@@ -125,7 +154,7 @@
   * worries about ungetc buffers and so forth.
   */
  static int
@@ -136,14 +85,7 @@
  {
  	int ret;
  	FILE fake;
- 	unsigned char buf[BUFSIZ];
-+	struct __sFILEX ext;
-+	fake._extra = &ext;
-+	INITEXTRA(&fake);
- 
- 	/* XXX This is probably not needed. */
- 	if (prepwrite(fp) != 0)
-@@ -229,7 +236,7 @@ __sbprintf(FILE *fp, const wchar_t *fmt,
+@@ -144,7 +173,7 @@
  	fake._lbfsize = 0;	/* not actually used, but Just In Case */
  
  	/* do the work, then copy any error status */
@@ -152,96 +94,93 @@
  	if (ret >= 0 && __fflush(&fake))
  		ret = WEOF;
  	if (fake._flags & __SERR)
-@@ -242,7 +249,7 @@ __sbprintf(FILE *fp, const wchar_t *fmt,
+@@ -157,7 +186,7 @@
   * File must already be locked.
   */
  static wint_t
 -__xfputwc(wchar_t wc, FILE *fp)
 +__xfputwc(wchar_t wc, FILE *fp, locale_t loc)
  {
+ 	static const mbstate_t initial;
  	mbstate_t mbs;
- 	char buf[MB_LEN_MAX];
-@@ -251,10 +258,10 @@ __xfputwc(wchar_t wc, FILE *fp)
+@@ -167,10 +196,10 @@
  	size_t len;
  
  	if ((fp->_flags & __SSTR) == 0)
 -		return (__fputwc(wc, fp));
 +		return (__fputwc(wc, fp, loc));
  
- 	mbs = initial_mbs;
+ 	mbs = initial;
 -	if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) {
 +	if ((len = wcrtomb_l(buf, wc, &mbs, loc)) == (size_t)-1) {
  		fp->_flags |= __SERR;
  		return (WEOF);
  	}
-@@ -273,12 +280,13 @@ __xfputwc(wchar_t wc, FILE *fp)
+@@ -350,13 +379,14 @@
   * that the multibyte char. string ends in a null character.
   */
  static wchar_t *
 -__mbsconv(char *mbsarg, int prec)
 +__mbsconv(char *mbsarg, int prec, locale_t loc)
  {
+ 	static const mbstate_t initial;
  	mbstate_t mbs;
  	wchar_t *convbuf, *wcp;
  	const char *p;
--	size_t insize, nchars, nconv;
-+	size_t insize, nchars, nconv = 0;
+ 	size_t insize, nchars, nconv;
 +	int mb_cur_max = MB_CUR_MAX_L(loc);
  
  	if (mbsarg == NULL)
  		return (NULL);
-@@ -296,7 +304,7 @@ __mbsconv(char *mbsarg, int prec)
- 		insize = nchars = nconv = 0;
- 		mbs = initial_mbs;
+@@ -374,7 +404,7 @@
+ 		insize = nchars = 0;
+ 		mbs = initial;
  		while (nchars != (size_t)prec) {
 -			nconv = mbrlen(p, MB_CUR_MAX, &mbs);
 +			nconv = mbrlen_l(p, mb_cur_max, &mbs, loc);
  			if (nconv == 0 || nconv == (size_t)-1 ||
  			    nconv == (size_t)-2)
  				break;
-@@ -323,7 +331,7 @@ __mbsconv(char *mbsarg, int prec)
+@@ -399,7 +429,7 @@
  	p = mbsarg;
- 	mbs = initial_mbs;
+ 	mbs = initial;
  	while (insize != 0) {
 -		nconv = mbrtowc(wcp, p, insize, &mbs);
 +		nconv = mbrtowc_l(wcp, p, insize, &mbs, loc);
  		if (nconv == 0 || nconv == (size_t)-1 || nconv == (size_t)-2)
  			break;
  		wcp++;
-@@ -343,22 +351,28 @@ __mbsconv(char *mbsarg, int prec)
-  * MT-safe version
-  */
- int
--vfwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt0, va_list ap)
--
-+vfwprintf_l(FILE * __restrict fp, locale_t loc, const wchar_t * __restrict fmt0, va_list ap)
- {
+@@ -425,7 +455,21 @@
  	int ret;
  
+ 	FLOCKFILE(fp);
+-	ret = __vfwprintf(fp, fmt0, ap);
++	ret = __vfwprintf(fp, __current_locale(), fmt0, ap);
++	FUNLOCKFILE(fp);
++	return (ret);
++}
++
++int
++vfwprintf_l(FILE * __restrict fp, locale_t loc, const wchar_t * __restrict fmt0,
++    va_list ap)
++
++{
++	int ret;
++
 +	NORMALIZE_LOCALE(loc);
- 	FLOCKFILE(fp);
- 	/* optimise fprintf(stderr) (and other unbuffered Unix files) */
- 	if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
- 	    fp->_file >= 0)
--		ret = __sbprintf(fp, fmt0, ap);
-+		ret = __sbprintf(fp, loc, fmt0, ap);
- 	else
--		ret = __vfwprintf(fp, fmt0, ap);
-+		ret = __vfwprintf(fp, loc, fmt0, ap);
++	FLOCKFILE(fp);
++	ret = __vfwprintf(fp, loc, fmt0, ap);
  	FUNLOCKFILE(fp);
  	return (ret);
  }
- 
-+int
-+vfwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt0, va_list ap)
-+{
-+	return vfwprintf_l(fp, __current_locale(), fmt0, ap);
-+}
-+
- /*
-  * The size of the buffer we use as scratch space for integer
-  * conversions, among other things.  We need enough space to
-@@ -373,8 +387,8 @@ vfwprintf(FILE * __restrict fp, const wc
+@@ -474,12 +518,15 @@
+ #define	PTRDIFFT	0x800		/* ptrdiff_t */
+ #define	INTMAXT		0x1000		/* intmax_t */
+ #define	CHARINT		0x2000		/* print char using int format */
++#ifdef VECTORS
++#define	VECTOR		0x4000		/* Altivec or SSE vector */
++#endif /* VECTORS */
+ 
  /*
   * Non-MT-safe version
   */
@@ -252,9 +191,9 @@
  {
  	wchar_t *fmt;		/* format string */
  	wchar_t ch;		/* character from fmt */
-@@ -415,6 +429,11 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
- 	wchar_t expstr[MAXEXPDIG+2];	/* buffer for exponent string: e+ZZZ */
- 	char *dtoaresult;	/* buffer allocated by dtoa */
+@@ -524,6 +571,11 @@
+ 	int nseps;		/* number of group separators with ' */
+ 	int nrepeats;		/* number of repeats of the last group */
  #endif
 +#ifdef VECTORS
 +	union arg vval;		/* Vector argument. */
@@ -264,62 +203,43 @@
  	u_long	ulval;		/* integer arguments %[diouxX] */
  	uintmax_t ujval;	/* %j, %ll, %q, %t, %z integers */
  	int base;		/* base for [diouxX] conversion */
-@@ -437,19 +456,19 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
- 
- 	/* BEWARE, these `goto error' on error. */
+@@ -560,7 +612,7 @@
+ 	 */
  #define	PRINT(ptr, len)	do {			\
--	if (io_print(&io, (ptr), (len)))	\
-+	if (io_print(&io, (ptr), (len), loc))	\
- 		goto error; \
+ 	for (n3 = 0; n3 < (len); n3++)		\
+-		__xfputwc((ptr)[n3], fp);	\
++		__xfputwc((ptr)[n3], fp, loc);	\
  } while (0)
- #define	PAD(howmany, with) { \
--	if (io_pad(&io, (howmany), (with))) \
-+	if (io_pad(&io, (howmany), (with), loc)) \
- 		goto error; \
- }
- #define	PRINTANDPAD(p, ep, len, with) {	\
--	if (io_printandpad(&io, (p), (ep), (len), (with))) \
-+	if (io_printandpad(&io, (p), (ep), (len), (with), loc)) \
- 		goto error; \
- }
- #define	FLUSH() { \
--	if (io_flush(&io)) \
-+	if (io_flush(&io, loc)) \
- 		goto error; \
- }
- 
-@@ -485,7 +504,7 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
- #define	UJARG() \
- 	(flags&INTMAXT ? GETARG(uintmax_t) : \
- 	    flags&SIZET ? (uintmax_t)GETARG(size_t) : \
--	    flags&PTRDIFFT ? (uintmax_t)GETARG(ptrdiff_t) : \
-+	    flags&PTRDIFFT ? (uintmax_t)(unsigned long)GETARG(ptrdiff_t) : \
- 	    (uintmax_t)GETARG(unsigned long long))
- 
- 	/*
-@@ -518,8 +537,11 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
- 
- 
+ #define	PAD(howmany, with)	do {		\
+ 	if ((n = (howmany)) > 0) {		\
+@@ -640,21 +692,22 @@
+ 		val = GETARG (int); \
+ 	}
+ 
+-
+ 	thousands_sep = '\0';
+ 	grouping = NULL;
+ #ifndef NO_FLOATING_POINT
+-	decimal_point = localeconv()->decimal_point;
++	decimal_point = localeconv_l(loc)->decimal_point;
+ #endif
+ 	convbuf = NULL;
  	/* sorry, fwprintf(read_only_file, L"") returns WEOF, not 0 */
 -	if (prepwrite(fp) != 0)
 +	if (prepwrite(fp) != 0) {
 +		errno = EBADF;
  		return (EOF);
 +	}
-+	ORIENT(fp, 1);
- 
- 	convbuf = NULL;
+ 
+ 	/* optimise fprintf(stderr) (and other unbuffered Unix files) */
+ 	if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
+ 	    fp->_file >= 0)
+-		return (__sbprintf(fp, fmt0, ap));
++		return (__sbprintf(fp, loc, fmt0, ap));
+ 
  	fmt = (wchar_t *)fmt0;
-@@ -529,7 +551,7 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
- 	io_init(&io, fp);
- 	ret = 0;
- #ifndef NO_FLOATING_POINT
--	decimal_point = get_decpt();
-+	decimal_point = get_decpt(loc);
- #endif
- 
- 	/*
-@@ -548,6 +570,9 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
+ 	argtable = NULL;
+@@ -678,6 +731,9 @@
  		}
  		if (ch == '\0')
  			goto done;
@@ -329,8 +249,8 @@
  		fmt++;		/* skip over '%' */
  
  		flags = 0;
-@@ -557,6 +582,9 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
- 		gs.grouping = NULL;
+@@ -686,6 +742,9 @@
+ 		prec = -1;
  		sign = '\0';
  		ox[1] = '\0';
 +#ifdef VECTORS
@@ -339,7 +259,7 @@
  
  rflag:		ch = *fmt++;
  reswitch:	switch (ch) {
-@@ -572,6 +600,11 @@ reswitch:	switch (ch) {
+@@ -701,6 +760,11 @@
  		case '#':
  			flags |= ALT;
  			goto rflag;
@@ -351,7 +271,18 @@
  		case '*':
  			/*-
  			 * ``A negative field width argument is taken as a
-@@ -668,10 +701,14 @@ reswitch:	switch (ch) {
+@@ -721,8 +785,8 @@
+ 			goto rflag;
+ 		case '\'':
+ 			flags |= GROUPING;
+-			thousands_sep = *(localeconv()->thousands_sep);
+-			grouping = localeconv()->grouping;
++			thousands_sep = *(localeconv_l(loc)->thousands_sep);
++			grouping = localeconv_l(loc)->grouping;
+ 			goto rflag;
+ 		case '.':
+ 			if ((ch = *fmt++) == '*') {
+@@ -796,10 +860,14 @@
  			flags |= LONGINT;
  			/*FALLTHROUGH*/
  		case 'c':
@@ -367,7 +298,7 @@
  			size = 1;
  			sign = '\0';
  			break;
-@@ -680,6 +717,10 @@ reswitch:	switch (ch) {
+@@ -808,6 +876,10 @@
  			/*FALLTHROUGH*/
  		case 'd':
  		case 'i':
@@ -378,7 +309,7 @@
  			if (flags & INTMAX_SIZE) {
  				ujval = SJARG();
  				if ((intmax_t)ujval < 0) {
-@@ -698,6 +739,12 @@ reswitch:	switch (ch) {
+@@ -826,6 +898,12 @@
  #ifndef NO_FLOATING_POINT
  		case 'a':
  		case 'A':
@@ -391,7 +322,7 @@
  			if (ch == 'a') {
  				ox[1] = 'x';
  				xdigs = xdigs_lower;
-@@ -709,6 +756,12 @@ reswitch:	switch (ch) {
+@@ -837,6 +915,12 @@
  			}
  			if (prec >= 0)
  				prec++;
@@ -404,7 +335,7 @@
  			if (flags & LONGDBL) {
  				fparg.ldbl = GETARG(long double);
  				dtoaresult =
-@@ -720,6 +773,7 @@ reswitch:	switch (ch) {
+@@ -848,6 +932,7 @@
  				    __hdtoa(fparg.dbl, xdigs, prec,
  				        &expt, &signflag, &dtoaend);
  			}
@@ -412,7 +343,7 @@
  			if (prec < 0)
  				prec = dtoaend - dtoaresult;
  			if (expt == INT_MAX)
-@@ -727,11 +781,17 @@ reswitch:	switch (ch) {
+@@ -855,11 +940,17 @@
  			if (convbuf != NULL)
  				free(convbuf);
  			ndig = dtoaend - dtoaresult;
@@ -431,7 +362,7 @@
  			expchar = ch;
  			if (prec < 0)	/* account for digit before decpt */
  				prec = DEFPREC + 1;
-@@ -740,10 +800,22 @@ reswitch:	switch (ch) {
+@@ -868,10 +959,22 @@
  			goto fp_begin;
  		case 'f':
  		case 'F':
@@ -454,7 +385,7 @@
  			expchar = ch - ('g' - 'e');
  			if (prec == 0)
  				prec = 1;
-@@ -752,6 +824,14 @@ fp_begin:
+@@ -880,6 +983,14 @@
  				prec = DEFPREC;
  			if (convbuf != NULL)
  				free(convbuf);
@@ -469,7 +400,7 @@
  			if (flags & LONGDBL) {
  				fparg.ldbl = GETARG(long double);
  				dtoaresult =
-@@ -765,8 +845,9 @@ fp_begin:
+@@ -893,8 +1004,9 @@
  				if (expt == 9999)
  					expt = INT_MAX;
  			}
@@ -480,53 +411,7 @@
  			freedtoa(dtoaresult);
  fp_common:
  			if (signflag)
-@@ -816,37 +897,46 @@ fp_common:
- 				if (prec || flags & ALT)
- 					size += prec + 1;
- 				if ((flags & GROUPING) && expt > 0)
--					size += grouping_init(&gs, expt);
-+					size += grouping_init(&gs, expt, loc);
- 			}
- 			break;
- #endif /* !NO_FLOATING_POINT */
- 		case 'n':
-+		{
- 			/*
- 			 * Assignment-like behavior is specified if the
- 			 * value overflows or is otherwise unrepresentable.
- 			 * C99 says to use `signed char' for %hhn conversions.
- 			 */
--			if (flags & LLONGINT)
--				*GETARG(long long *) = ret;
-+			void *ptr = GETARG(void *);
-+			if (ptr == NULL)
-+				continue;
-+			else if (flags & LLONGINT)
-+				*(long long *)ptr = ret;
- 			else if (flags & SIZET)
--				*GETARG(ssize_t *) = (ssize_t)ret;
-+				*(ssize_t *)ptr = (ssize_t)ret;
- 			else if (flags & PTRDIFFT)
--				*GETARG(ptrdiff_t *) = ret;
-+				*(ptrdiff_t *)ptr = ret;
- 			else if (flags & INTMAXT)
--				*GETARG(intmax_t *) = ret;
-+				*(intmax_t *)ptr = ret;
- 			else if (flags & LONGINT)
--				*GETARG(long *) = ret;
-+				*(long *)ptr = ret;
- 			else if (flags & SHORTINT)
--				*GETARG(short *) = ret;
-+				*(short *)ptr = ret;
- 			else if (flags & CHARINT)
--				*GETARG(signed char *) = ret;
-+				*(signed char *)ptr = ret;
- 			else
--				*GETARG(int *) = ret;
-+				*(int *)ptr = ret;
- 			continue;	/* no output */
-+		}
- 		case 'O':
+@@ -989,6 +1101,10 @@
  			flags |= LONGINT;
  			/*FALLTHROUGH*/
  		case 'o':
@@ -537,7 +422,7 @@
  			if (flags & INTMAX_SIZE)
  				ujval = UJARG();
  			else
-@@ -861,6 +951,10 @@ fp_common:
+@@ -1003,6 +1119,10 @@
  			 * defined manner.''
  			 *	-- ANSI X3J11
  			 */
@@ -548,7 +433,7 @@
  			ujval = (uintmax_t)(uintptr_t)GETARG(void *);
  			base = 16;
  			xdigs = xdigs_lower;
-@@ -882,7 +976,7 @@ fp_common:
+@@ -1024,7 +1144,7 @@
  				if ((mbp = GETARG(char *)) == NULL)
  					cp = L"(null)";
  				else {
@@ -557,20 +442,7 @@
  					if (convbuf == NULL) {
  						fp->_flags |= __SERR;
  						goto error;
-@@ -890,13 +984,23 @@ fp_common:
- 					cp = convbuf;
- 				}
- 			}
-+#if 0 // wcsnlen needs API review first
- 			size = (prec >= 0) ? wcsnlen(cp, prec) : wcslen(cp);
-+#else
-+			size = wcslen(cp);
-+			if(prec >= 0 && prec < size)
-+				size = prec;
-+#endif
- 			sign = '\0';
- 			break;
- 		case 'U':
+@@ -1055,6 +1175,10 @@
  			flags |= LONGINT;
  			/*FALLTHROUGH*/
  		case 'u':
@@ -581,7 +453,7 @@
  			if (flags & INTMAX_SIZE)
  				ujval = UJARG();
  			else
-@@ -909,6 +1013,10 @@ fp_common:
+@@ -1067,6 +1191,10 @@
  		case 'x':
  			xdigs = xdigs_lower;
  hex:
@@ -592,23 +464,9 @@
  			if (flags & INTMAX_SIZE)
  				ujval = UJARG();
  			else
-@@ -926,6 +1034,7 @@ nosign:			sign = '\0';
- 			 * ``... diouXx conversions ... if a precision is
- 			 * specified, the 0 flag will be ignored.''
- 			 *	-- ANSI X3J11
-+			 * except for %#.0o and zero value
- 			 */
- number:			if ((dprec = prec) >= 0)
- 				flags &= ~ZEROPAD;
-@@ -953,10 +1062,15 @@ number:			if ((dprec = prec) >= 0)
- 			}
- 			size = buf + BUF - cp;
+@@ -1111,6 +1239,11 @@
  			if (size > BUF)	/* should never happen */
--				abort();
-+				LIBC_ABORT("size (%d) > BUF (%d)", size, BUF);
- 			if ((flags & GROUPING) && size != 0)
--				size += grouping_init(&gs, size);
-+				size += grouping_init(&gs, size, loc);
+ 				abort();
  			break;
 +#ifdef VECTORS
 +		case 'v':
@@ -618,7 +476,7 @@
  		default:	/* "%?" prints ?, unless ? is NUL */
  			if (ch == '\0')
  				goto done;
-@@ -968,6 +1082,288 @@ number:			if ((dprec = prec) >= 0)
+@@ -1122,6 +1255,288 @@
  			break;
  		}
  
@@ -784,25 +642,25 @@
 +		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vuchararg[ind]); \
 +		break;							\
 +	case V_PCHAR:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(uintptr_t)vval.vuchararg[ind]); \
++		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(long)vval.vuchararg[ind]); \
 +		break;							\
 +	case V_SHORT:							\
 +		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vushortarg[ind]); \
 +		break;							\
 +	case V_PSHORT:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(uintptr_t)vval.vushortarg[ind]); \
++		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(long)vval.vushortarg[ind]); \
 +		break;							\
 +	case V_INT:							\
 +		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vuintarg[ind]); \
 +		break;							\
 +	case V_PINT:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(uintptr_t)vval.vuintarg[ind]); \
++		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(long)vval.vuintarg[ind]); \
 +		break;							\
 +	case V_LONGLONG:						\
 +		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vulonglongarg[ind]); \
 +		break;							\
 +	case V_PLONGLONG:						\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(uintptr_t)vval.vulonglongarg[ind]); \
++		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(long)vval.vulonglongarg[ind]); \
 +		break;							\
 +	case V_FLOAT:							\
 +		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vfloatarg[ind]); \
@@ -822,19 +680,19 @@
 +		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vuchararg[ind]); \
 +		break;							\
 +	case V_PCHAR:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(uintptr_t)vval.vuchararg[ind]); \
++		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(long)vval.vuchararg[ind]); \
 +		break;							\
 +	case V_SHORT:							\
 +		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vushortarg[ind]); \
 +		break;							\
 +	case V_PSHORT:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(uintptr_t)vval.vushortarg[ind]); \
++		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(long)vval.vushortarg[ind]); \
 +		break;							\
 +	case V_INT:							\
 +		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vuintarg[ind]); \
 +		break;							\
 +	case V_PINT:							\
-+		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(uintptr_t)vval.vuintarg[ind]); \
++		vlen = asprintf_l(&vstr, loc, vfmt , ## args, (void *)(long)vval.vuintarg[ind]); \
 +		break;							\
 +	case V_FLOAT:							\
 +		vlen = asprintf_l(&vstr, loc, vfmt , ## args, vval.vfloatarg[ind]); \
@@ -907,21 +765,92 @@
  		/*
  		 * All reasonable formats wind up here.  At this point, `cp'
  		 * points to a string which (if not flags&LADJUST) should be
-@@ -1018,7 +1414,7 @@ number:			if ((dprec = prec) >= 0)
- 			/* leading zeroes from decimal precision */
- 			PAD(dprec - size, zeroes);
- 			if (gs.grouping) {
--				if (grouping_print(&gs, &io, cp, buf+BUF) < 0)
-+				if (grouping_print(&gs, &io, cp, buf+BUF, loc) < 0)
- 					goto error;
- 			} else {
- 				PRINT(cp, size);
-@@ -1036,7 +1432,7 @@ number:			if ((dprec = prec) >= 0)
- 				} else {
- 					if (gs.grouping) {
- 						n = grouping_print(&gs, &io,
--						    cp, convbuf + ndig);
-+						    cp, convbuf + ndig, loc);
- 						if (n < 0)
- 							goto error;
- 						cp += n;
+@@ -1401,6 +1816,11 @@
+ 			if (flags & LONGINT)
+ 				ADDTYPE(T_WINT);
+ 			else
++#ifdef VECTORS
++			if (flags & VECTOR)
++				ADDTYPE(T_VECTOR);
++			else
++#endif /* VECTORS */
+ 				ADDTYPE(T_INT);
+ 			break;
+ 		case 'D':
+@@ -1408,6 +1828,11 @@
+ 			/*FALLTHROUGH*/
+ 		case 'd':
+ 		case 'i':
++#ifdef VECTORS
++			if (flags & VECTOR)
++				ADDTYPE(T_VECTOR);
++			else
++#endif /* VECTORS */
+ 			ADDSARG();
+ 			break;
+ #ifndef NO_FLOATING_POINT
+@@ -1418,6 +1843,11 @@
+ 		case 'f':
+ 		case 'g':
+ 		case 'G':
++#ifdef VECTORS
++			if (flags & VECTOR)
++				ADDTYPE(T_VECTOR);
++			else
++#endif /* VECTORS */
+ 			if (flags & LONGDBL)
+ 				ADDTYPE(T_LONG_DOUBLE);
+ 			else
+@@ -1446,9 +1876,19 @@
+ 			flags |= LONGINT;
+ 			/*FALLTHROUGH*/
+ 		case 'o':
++#ifdef VECTORS
++			if (flags & VECTOR)
++				ADDTYPE(T_VECTOR);
++			else
++#endif /* VECTORS */
+ 			ADDUARG();
+ 			break;
+ 		case 'p':
++#ifdef VECTORS
++			if (flags & VECTOR)
++				ADDTYPE(T_VECTOR);
++			else
++#endif /* VECTORS */
+ 			ADDTYPE(TP_VOID);
+ 			break;
+ 		case 'S':
+@@ -1466,6 +1906,11 @@
+ 		case 'u':
+ 		case 'X':
+ 		case 'x':
++#ifdef VECTORS
++			if (flags & VECTOR)
++				ADDTYPE(T_VECTOR);
++			else
++#endif /* VECTORS */
+ 			ADDUARG();
+ 			break;
+ 		default:	/* "%?" prints ?, unless ? is NUL */
+@@ -1532,7 +1977,7 @@
+ 			(*argtable) [n].sizearg = va_arg (ap, size_t);
+ 			break;
+ 		    case TP_SIZET:
+-			(*argtable) [n].psizearg = va_arg (ap, ssize_t *);
++			(*argtable) [n].psizearg = va_arg (ap, size_t *);
+ 			break;
+ 		    case T_INTMAXT:
+ 			(*argtable) [n].intmaxarg = va_arg (ap, intmax_t);
+@@ -1551,6 +1996,11 @@
+ 			(*argtable) [n].longdoublearg = va_arg (ap, long double);
+ 			break;
+ #endif
++#ifdef VECTORS
++		    case T_VECTOR:
++			(*argtable) [n].vectorarg = va_arg (ap, VECTORTYPE);
++			break;
++#endif /* VECTORS */
+ 		    case TP_CHAR:
+ 			(*argtable) [n].pchararg = va_arg (ap, char *);
+ 			break;