Module Name:    src
Committed By:   joerg
Date:           Fri Apr 19 15:22:25 UTC 2013

Modified Files:
        src/include: stdio.h wchar.h
        src/lib/libc/include: namespace.h
        src/lib/libc/stdio: Makefile.inc dprintf.c fprintf.c fwprintf.c local.h
            printf.c swprintf.c vasprintf.c vdprintf.c vfprintf.c vfwprintf.c
            vprintf.c vsnprintf.c vsprintf.c vswprintf.c vwprintf.c wprintf.c
Removed Files:
        src/lib/libc/stdio: asprintf.c snprintf.c sprintf.c

Log Message:
Add explicit locale versions for the printf family. Replace asprintf,
snprintf and sprintf with simple wrappers around the corresponding
va_list functions to reduce code duplication.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/include/stdio.h
cvs rdiff -u -r1.34 -r1.35 src/include/wchar.h
cvs rdiff -u -r1.161 -r1.162 src/lib/libc/include/namespace.h
cvs rdiff -u -r1.41 -r1.42 src/lib/libc/stdio/Makefile.inc
cvs rdiff -u -r1.19 -r0 src/lib/libc/stdio/asprintf.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/stdio/dprintf.c
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/stdio/fprintf.c \
    src/lib/libc/stdio/printf.c src/lib/libc/stdio/vprintf.c
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/stdio/fwprintf.c \
    src/lib/libc/stdio/swprintf.c src/lib/libc/stdio/vdprintf.c \
    src/lib/libc/stdio/vwprintf.c src/lib/libc/stdio/wprintf.c
cvs rdiff -u -r1.34 -r1.35 src/lib/libc/stdio/local.h
cvs rdiff -u -r1.24 -r0 src/lib/libc/stdio/snprintf.c
cvs rdiff -u -r1.16 -r0 src/lib/libc/stdio/sprintf.c
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/stdio/vasprintf.c
cvs rdiff -u -r1.59 -r1.60 src/lib/libc/stdio/vfprintf.c
cvs rdiff -u -r1.30 -r1.31 src/lib/libc/stdio/vfwprintf.c
cvs rdiff -u -r1.25 -r1.26 src/lib/libc/stdio/vsnprintf.c
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/stdio/vsprintf.c
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/stdio/vswprintf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/include/stdio.h
diff -u src/include/stdio.h:1.83 src/include/stdio.h:1.84
--- src/include/stdio.h:1.83	Wed Apr 17 09:07:32 2013
+++ src/include/stdio.h	Fri Apr 19 15:22:24 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: stdio.h,v 1.83 2013/04/17 09:07:32 joerg Exp $	*/
+/*	$NetBSD: stdio.h,v 1.84 2013/04/19 15:22:24 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -527,6 +527,40 @@ int	 dprintf(int, const char * __restric
 FILE *fmemopen(void * __restrict, size_t, const char * __restrict);
 #endif
 
+#if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE)
+#  ifndef __LOCALE_T_DECLARED
+typedef struct _locale		*locale_t;
+#  define __LOCALE_T_DECLARED
+#  endif
+int	 fprintf_l(FILE * __restrict, locale_t, const char * __restrict, ...)
+		__printflike(3, 4);
+int	 vfprintf_l(FILE * __restrict, locale_t, const char * __restrict,
+		__va_list) __printflike(3, 0);
+int	 printf_l(locale_t, const char * __restrict, ...)
+		__printflike(2, 3);
+int	 vprintf_l(locale_t, const char * __restrict, __va_list)
+		__printflike(2, 0);
+int	 asprintf_l(char ** __restrict, locale_t, const char * __restrict, ...)
+		__printflike(3, 4);
+int	 vasprintf_l(char ** __restrict, locale_t, const char * __restrict,
+    __va_list)
+		__printflike(3, 0);
+int	 vdprintf_l(int, locale_t, const char * __restrict, __va_list)
+		__printflike(3, 0);
+int	 dprintf_l(int, locale_t, const char * __restrict, ...)
+		__printflike(3, 4);
+int	 snprintf_l(char * __restrict, size_t, locale_t,
+		    const char * __restrict, ...) __printflike(4, 5);
+int	 vsnprintf_l(char * __restrict, size_t, locale_t,
+		     const char * __restrict, __va_list) __printflike(4, 0);
+#ifndef __AUDIT__
+int	 sprintf_l(char * __restrict, locale_t, const char * __restrict, ...)
+		   __printflike(3, 4);
+int	 vsprintf_l(char * __restrict, locale_t, const char * __restrict,
+		    __va_list) __printflike(3, 0);
+#endif
+#endif
+
 #if _FORTIFY_SOURCE > 0
 #include <ssp/stdio.h>
 #endif

Index: src/include/wchar.h
diff -u src/include/wchar.h:1.34 src/include/wchar.h:1.35
--- src/include/wchar.h:1.34	Thu Apr 18 23:24:26 2013
+++ src/include/wchar.h	Fri Apr 19 15:22:24 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: wchar.h,v 1.34 2013/04/18 23:24:26 joerg Exp $	*/
+/*	$NetBSD: wchar.h,v 1.35 2013/04/19 15:22:24 joerg Exp $	*/
 
 /*-
  * Copyright (c)1999 Citrus Project,
@@ -247,6 +247,16 @@ size_t	wcrtomb_l(char * __restrict, wcha
 size_t	wcsrtombs_l(char * __restrict, const wchar_t ** __restrict, size_t,
 	    mbstate_t * __restrict, locale_t);
 int	wctob_l(wint_t, locale_t);
+
+int fwprintf_l(FILE * __restrict, locale_t, const wchar_t * __restrict, ...);
+int swprintf_l(wchar_t * __restrict, size_t n, locale_t,
+    const wchar_t * __restrict, ...);
+int vfwprintf_l(FILE * __restrict, locale_t,
+    const wchar_t * __restrict, __va_list);
+int vswprintf_l(wchar_t * __restrict, size_t, locale_t,
+    const wchar_t * __restrict, __va_list);
+int vwprintf_l(locale_t, const wchar_t * __restrict, __va_list);
+int wprintf_l(locale_t, const wchar_t * __restrict, ...);
 #endif /* _NETBSD_SOURCE */
 
 #endif /* !_WCHAR_H_ */

Index: src/lib/libc/include/namespace.h
diff -u src/lib/libc/include/namespace.h:1.161 src/lib/libc/include/namespace.h:1.162
--- src/lib/libc/include/namespace.h:1.161	Thu Apr 18 23:24:26 2013
+++ src/lib/libc/include/namespace.h	Fri Apr 19 15:22:24 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: namespace.h,v 1.161 2013/04/18 23:24:26 joerg Exp $	*/
+/*	$NetBSD: namespace.h,v 1.162 2013/04/19 15:22:24 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
@@ -168,6 +168,7 @@
 #define arc4random_uniform	_arc4random_uniform
 #define asctime_r		_asctime_r
 #define asprintf		_asprintf
+#define asprintf_l		_asprintf_l
 #define atoll			_atoll
 #define authnone_create		_authnone_create
 #define authunix_create		_authunix_create
@@ -240,6 +241,7 @@
 #define difftime		_difftime
 #define dirname			_dirname
 #define dn_expand		_dn_expand
+#define dprintf_l		_dprintf_l
 #define drand48			_drand48
 #define endfsent		_endfsent
 #define endgrent		_endgrent
@@ -276,6 +278,7 @@
 #define funlockfile		_funlockfile
 #define fnmatch			_fnmatch
 #define fparseln		_fparseln
+#define fprintf_l		_fprintf_l
 #define fpgetmask		_fpgetmask
 #define fpgetprec		_fpgetprec
 #define fpgetround		_fpgetround
@@ -295,6 +298,7 @@
 #define fts_open		_fts_open
 #define fts_read		_fts_read
 #define fts_set			_fts_set
+#define fwprintf_l		_fwprintf_l
 #define gai_strerror		_gai_strerror
 #define get_myaddress		_get_myaddress
 #define getaddrinfo		_getaddrinfo
@@ -497,6 +501,7 @@
 #define posix2time		_posix2time
 #define posix2time_z		_posix2time_z
 #define pread			_pread
+#define printf_l		_printf_l
 #define pselect			_pselect
 #define psignal			_psignal
 #define pthread_atfork		_pthread_atfork
@@ -593,7 +598,9 @@
 #ifndef snprintf
 #define snprintf		_snprintf
 #endif
+#define snprintf_l		_snprintf_l
 #define snprintf_ss		_snprintf_ss
+#define sprintf_l		_sprintf_l
 #define sradixsort		_sradixsort
 #define srand48			_srand48
 #define srandom			_srandom
@@ -644,6 +651,7 @@
 #define svcudp_create		_svcudp_create
 #define svcudp_enablecache	_svcudp_enablecache
 #define sysarch			_sys_sysarch
+#define swprintf_l		_swprintf_l
 #define sysctl			_sysctl
 #define sysctlbyname		_sysctlbyname
 #define sysctlgetmibinfo	_sysctlgetmibinfo
@@ -687,12 +695,22 @@
 #define uuid_create_nil		_uuid_create_nil
 #define uuid_is_nil		_uuid_is_nil
 #define valloc			_valloc
-#define vdprintf		_vdprintf
+#define vasprintf		_vasprintf
+#define vasprintf_l		_vasprintf_l
 #define	vdprintf		_vdprintf
 #ifndef vsnprintf
 #define vsnprintf		_vsnprintf
 #endif
+#define vdprintf_l		_vdprintf_l
+#define vdprintf_l		_vdprintf_l
+#define vfprintf_l		_vfprintf_l
+#define vfwprintf_l		_vfwprintf_l
+#define vprintf_l		_vprintf_l
+#define vsnprintf_l		_vsnprintf_l
 #define vsnprintf_ss		_vsnprintf_ss
+#define vsprintf_l		_vsprintf_l
+#define vswprintf_l		_vswprintf_l
+#define vwprintf_l		_vwprintf_l
 #define vsyslog			_vsyslog
 #define vsyslog_r		_vsyslog_r
 #define vsyslog_ss		_vsyslog_ss
@@ -716,6 +734,7 @@
 #define wcstold_l		_wcstold_l
 #define wcwidth			_wcwidth
 #define wcwidth_l		_wcwidth_l
+#define wprintf_l		_wprintf_l
 #define xdr_accepted_reply	_xdr_accepted_reply
 #define xdr_array		_xdr_array
 #define xdr_authunix_parms	_xdr_authunix_parms

Index: src/lib/libc/stdio/Makefile.inc
diff -u src/lib/libc/stdio/Makefile.inc:1.41 src/lib/libc/stdio/Makefile.inc:1.42
--- src/lib/libc/stdio/Makefile.inc:1.41	Tue Mar 27 15:05:42 2012
+++ src/lib/libc/stdio/Makefile.inc	Fri Apr 19 15:22:25 2013
@@ -1,12 +1,12 @@
 #	from: @(#)Makefile.inc	5.7 (Berkeley) 6/27/91
-#	$NetBSD: Makefile.inc,v 1.41 2012/03/27 15:05:42 christos Exp $
+#	$NetBSD: Makefile.inc,v 1.42 2013/04/19 15:22:25 joerg Exp $
 
 # stdio sources
 .PATH: ${.CURDIR}/stdio
 
 CPPFLAGS+=-DWIDE_DOUBLE
 
-SRCS+=	asprintf.c clrerr.c dprintf.c fclose.c fdopen.c feof.c ferror.c \
+SRCS+=	clrerr.c dprintf.c fclose.c fdopen.c feof.c ferror.c \
 	fflush.c fgetc.c fgetln.c fgetpos.c fgets.c fgetstr.c fgetwc.c \
 	fgetwln.c fgetws.c fileno.c findfp.c flags.c flockfile.c fopen.c \
 	fparseln.c fprintf.c fpurge.c fputc.c fputs.c fputwc.c fputws.c \
@@ -15,7 +15,7 @@ SRCS+=	asprintf.c clrerr.c dprintf.c fcl
 	getc.c getchar.c getdelim.c getline.c gettemp.c getw.c getwc.c \
 	getwchar.c makebuf.c mkdtemp.c mkstemp.c perror.c printf.c putc.c \
 	putchar.c puts.c putw.c putwc.c putwchar.c refill.c remove.c rewind.c \
-	rget.c scanf.c setbuf.c setbuffer.c setvbuf.c snprintf.c snprintf_ss.c \
+	rget.c scanf.c setbuf.c setbuffer.c setvbuf.c snprintf_ss.c \
 	sscanf.c stdio.c swprintf.c swscanf.c tmpfile.c ungetc.c ungetwc.c \
 	vasprintf.c vdprintf.c vfprintf.c vfscanf.c vfwprintf.c vfwscanf.c \
 	vprintf.c vscanf.c vsnprintf.c vsnprintf_ss.c vsscanf.c vswprintf.c \
@@ -23,7 +23,7 @@ SRCS+=	asprintf.c clrerr.c dprintf.c fcl
 SRCS+=	fmemopen.c
 
 .if !defined(AUDIT)
-SRCS+=	gets.c sprintf.c vsprintf.c tempnam.c tmpnam.c mktemp.c
+SRCS+=	gets.c vsprintf.c tempnam.c tmpnam.c mktemp.c
 .endif
 
 # namespace purity wrappers

Index: src/lib/libc/stdio/dprintf.c
diff -u src/lib/libc/stdio/dprintf.c:1.1 src/lib/libc/stdio/dprintf.c:1.2
--- src/lib/libc/stdio/dprintf.c:1.1	Mon Sep  6 14:52:55 2010
+++ src/lib/libc/stdio/dprintf.c	Fri Apr 19 15:22:25 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: dprintf.c,v 1.1 2010/09/06 14:52:55 christos Exp $	*/
+/*	$NetBSD: dprintf.c,v 1.2 2013/04/19 15:22:25 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: dprintf.c,v 1.1 2010/09/06 14:52:55 christos Exp $");
+__RCSID("$NetBSD: dprintf.c,v 1.2 2013/04/19 15:22:25 joerg Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -46,6 +46,8 @@ __RCSID("$NetBSD: dprintf.c,v 1.1 2010/0
 #include "reentrant.h"
 #include "local.h"
 
+__weak_alias(dprintf_l, _dprintf_l)
+
 int
 dprintf(int fd, const char * __restrict fmt, ...)
 {
@@ -57,3 +59,15 @@ dprintf(int fd, const char * __restrict 
 	va_end(ap);
 	return ret;
 }
+
+int
+dprintf_l(int fd, locale_t loc, const char * __restrict fmt, ...)
+{
+	va_list ap;
+	int ret;
+
+	va_start(ap, fmt);
+	ret = vdprintf_l(fd, loc, fmt, ap);
+	va_end(ap);
+	return ret;
+}

Index: src/lib/libc/stdio/fprintf.c
diff -u src/lib/libc/stdio/fprintf.c:1.12 src/lib/libc/stdio/fprintf.c:1.13
--- src/lib/libc/stdio/fprintf.c:1.12	Thu Mar 15 18:22:30 2012
+++ src/lib/libc/stdio/fprintf.c	Fri Apr 19 15:22:25 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: fprintf.c,v 1.12 2012/03/15 18:22:30 christos Exp $	*/
+/*	$NetBSD: fprintf.c,v 1.13 2013/04/19 15:22:25 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,10 +37,11 @@
 #if 0
 static char sccsid[] = "@(#)fprintf.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: fprintf.c,v 1.12 2012/03/15 18:22:30 christos Exp $");
+__RCSID("$NetBSD: fprintf.c,v 1.13 2013/04/19 15:22:25 joerg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
+#include "namespace.h"
 #include <assert.h>
 #include <errno.h>
 #include <stdarg.h>
@@ -60,3 +61,17 @@ fprintf(FILE *fp, const char *fmt, ...)
 	va_end(ap);
 	return ret;
 }
+
+__weak_alias(fprintf_l, _fprintf_l)
+
+int
+fprintf_l(FILE *fp, locale_t loc, const char *fmt, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, fmt);
+	ret = vfprintf_l(fp, loc, fmt, ap);
+	va_end(ap);
+	return ret;
+}
Index: src/lib/libc/stdio/printf.c
diff -u src/lib/libc/stdio/printf.c:1.12 src/lib/libc/stdio/printf.c:1.13
--- src/lib/libc/stdio/printf.c:1.12	Thu Mar 15 18:22:30 2012
+++ src/lib/libc/stdio/printf.c	Fri Apr 19 15:22:25 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: printf.c,v 1.12 2012/03/15 18:22:30 christos Exp $	*/
+/*	$NetBSD: printf.c,v 1.13 2013/04/19 15:22:25 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,15 +37,18 @@
 #if 0
 static char sccsid[] = "@(#)printf.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: printf.c,v 1.12 2012/03/15 18:22:30 christos Exp $");
+__RCSID("$NetBSD: printf.c,v 1.13 2013/04/19 15:22:25 joerg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
+#include "namespace.h"
 #include <assert.h>
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
 
+__weak_alias(printf_l, _printf_l)
+
 int
 printf(char const *fmt, ...)
 {
@@ -57,3 +60,15 @@ printf(char const *fmt, ...)
 	va_end(ap);
 	return ret;
 }
+
+int
+printf_l(locale_t loc, char const *fmt, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, fmt);
+	ret = vfprintf_l(stdout, loc, fmt, ap);
+	va_end(ap);
+	return ret;
+}
Index: src/lib/libc/stdio/vprintf.c
diff -u src/lib/libc/stdio/vprintf.c:1.12 src/lib/libc/stdio/vprintf.c:1.13
--- src/lib/libc/stdio/vprintf.c:1.12	Thu Mar 15 18:22:31 2012
+++ src/lib/libc/stdio/vprintf.c	Fri Apr 19 15:22:25 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vprintf.c,v 1.12 2012/03/15 18:22:31 christos Exp $	*/
+/*	$NetBSD: vprintf.c,v 1.13 2013/04/19 15:22:25 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,15 +37,18 @@
 #if 0
 static char sccsid[] = "@(#)vprintf.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: vprintf.c,v 1.12 2012/03/15 18:22:31 christos Exp $");
+__RCSID("$NetBSD: vprintf.c,v 1.13 2013/04/19 15:22:25 joerg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
+#include "namespace.h"
 #include <assert.h>
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
 
+__weak_alias(vprintf_l, _vprintf_l)
+
 int
 vprintf(const char *fmt, va_list ap)
 {
@@ -54,3 +57,10 @@ vprintf(const char *fmt, va_list ap)
 
 	return vfprintf(stdout, fmt, ap);
 }
+
+int
+vprintf_l(locale_t loc, const char *fmt, va_list ap)
+{
+
+	return vfprintf_l(stdout, loc, fmt, ap);
+}

Index: src/lib/libc/stdio/fwprintf.c
diff -u src/lib/libc/stdio/fwprintf.c:1.2 src/lib/libc/stdio/fwprintf.c:1.3
--- src/lib/libc/stdio/fwprintf.c:1.2	Thu Mar 15 18:22:30 2012
+++ src/lib/libc/stdio/fwprintf.c	Fri Apr 19 15:22:25 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: fwprintf.c,v 1.2 2012/03/15 18:22:30 christos Exp $	*/
+/*	$NetBSD: fwprintf.c,v 1.3 2013/04/19 15:22:25 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2002 Tim J. Robbins
@@ -31,14 +31,17 @@
 #if 0
 __FBSDID("$FreeBSD: src/lib/libc/stdio/fwprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $");
 #else
-__RCSID("$NetBSD: fwprintf.c,v 1.2 2012/03/15 18:22:30 christos Exp $");
+__RCSID("$NetBSD: fwprintf.c,v 1.3 2013/04/19 15:22:25 joerg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
+#include "namespace.h"
 #include <stdarg.h>
 #include <stdio.h>
 #include <wchar.h>
 
+__weak_alias(fwprintf_l, _fwprintf_l)
+
 int
 fwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt, ...)
 {
@@ -51,3 +54,16 @@ fwprintf(FILE * __restrict fp, const wch
 
 	return ret;
 }
+
+int
+fwprintf_l(FILE * __restrict fp, locale_t loc, const wchar_t * __restrict fmt, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, fmt);
+	ret = vfwprintf_l(fp, loc, fmt, ap);
+	va_end(ap);
+
+	return ret;
+}
Index: src/lib/libc/stdio/swprintf.c
diff -u src/lib/libc/stdio/swprintf.c:1.2 src/lib/libc/stdio/swprintf.c:1.3
--- src/lib/libc/stdio/swprintf.c:1.2	Thu Mar 15 18:22:30 2012
+++ src/lib/libc/stdio/swprintf.c	Fri Apr 19 15:22:25 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: swprintf.c,v 1.2 2012/03/15 18:22:30 christos Exp $	*/
+/*	$NetBSD: swprintf.c,v 1.3 2013/04/19 15:22:25 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2002 Tim J. Robbins
@@ -31,14 +31,17 @@
 #if 0
 __FBSDID("$FreeBSD: src/lib/libc/stdio/swprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $");
 #else
-__RCSID("$NetBSD: swprintf.c,v 1.2 2012/03/15 18:22:30 christos Exp $");
+__RCSID("$NetBSD: swprintf.c,v 1.3 2013/04/19 15:22:25 joerg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
+#include "namespace.h"
 #include <stdarg.h>
 #include <stdio.h>
 #include <wchar.h>
 
+__weak_alias(swprintf_l, _swprintf_l)
+
 int
 swprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, ...)
 {
@@ -51,3 +54,17 @@ swprintf(wchar_t * __restrict s, size_t 
 
 	return ret;
 }
+
+int
+swprintf_l(wchar_t * __restrict s, size_t n, locale_t loc,
+    const wchar_t * __restrict fmt, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, fmt);
+	ret = vswprintf_l(s, n, loc, fmt, ap);
+	va_end(ap);
+
+	return ret;
+}
Index: src/lib/libc/stdio/vdprintf.c
diff -u src/lib/libc/stdio/vdprintf.c:1.2 src/lib/libc/stdio/vdprintf.c:1.3
--- src/lib/libc/stdio/vdprintf.c:1.2	Sun Jul 17 20:54:34 2011
+++ src/lib/libc/stdio/vdprintf.c	Fri Apr 19 15:22:25 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vdprintf.c,v 1.2 2011/07/17 20:54:34 joerg Exp $	*/
+/*	$NetBSD: vdprintf.c,v 1.3 2013/04/19 15:22:25 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: vdprintf.c,v 1.2 2011/07/17 20:54:34 joerg Exp $");
+__RCSID("$NetBSD: vdprintf.c,v 1.3 2013/04/19 15:22:25 joerg Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -43,19 +43,22 @@ __RCSID("$NetBSD: vdprintf.c,v 1.2 2011/
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <locale.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <limits.h>
 
 #include "reentrant.h"
+#include "setlocale_local.h"
 #include "local.h"
 
 #ifdef __weak_alias
 __weak_alias(vdprintf,_vdprintf)
+__weak_alias(vdprintf_l,_vdprintf_l)
 #endif
 
 int
-vdprintf(int fd, const char * __restrict fmt, va_list ap)
+vdprintf_l(int fd, locale_t loc, const char * __restrict fmt, va_list ap)
 {
 	FILE f;
 	struct __sfileext fext;
@@ -109,8 +112,14 @@ vdprintf(int fd, const char * __restrict
 	f._seek = NULL;
 	f._close = NULL;
 
-	if ((ret = vfprintf(&f, fmt, ap)) < 0)
+	if ((ret = vfprintf_l(&f, loc, fmt, ap)) < 0)
 		return ret;
 
 	return fflush(&f) ? EOF : ret;
 }
+
+int
+vdprintf(int fd, const char * __restrict fmt, va_list ap)
+{
+	return vdprintf_l(fd, *_current_locale(), fmt, ap);
+}
Index: src/lib/libc/stdio/vwprintf.c
diff -u src/lib/libc/stdio/vwprintf.c:1.2 src/lib/libc/stdio/vwprintf.c:1.3
--- src/lib/libc/stdio/vwprintf.c:1.2	Thu Mar 15 18:22:31 2012
+++ src/lib/libc/stdio/vwprintf.c	Fri Apr 19 15:22:25 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vwprintf.c,v 1.2 2012/03/15 18:22:31 christos Exp $	*/
+/*	$NetBSD: vwprintf.c,v 1.3 2013/04/19 15:22:25 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2002 Tim J. Robbins
@@ -31,14 +31,23 @@
 #if 0
 __FBSDID("$FreeBSD: src/lib/libc/stdio/vwprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $");
 #else
-__RCSID("$NetBSD: vwprintf.c,v 1.2 2012/03/15 18:22:31 christos Exp $");
+__RCSID("$NetBSD: vwprintf.c,v 1.3 2013/04/19 15:22:25 joerg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
+#include "namespace.h"
 #include <stdarg.h>
 #include <stdio.h>
 #include <wchar.h>
 
+__weak_alias(vwprintf_l, _vwprintf_l)
+
+int
+vwprintf_l(locale_t loc, const wchar_t * __restrict fmt, va_list ap)
+{
+	return vfwprintf_l(stdout, loc, fmt, ap);
+}
+
 int
 vwprintf(const wchar_t * __restrict fmt, va_list ap)
 {
Index: src/lib/libc/stdio/wprintf.c
diff -u src/lib/libc/stdio/wprintf.c:1.2 src/lib/libc/stdio/wprintf.c:1.3
--- src/lib/libc/stdio/wprintf.c:1.2	Thu Mar 15 18:22:31 2012
+++ src/lib/libc/stdio/wprintf.c	Fri Apr 19 15:22:25 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: wprintf.c,v 1.2 2012/03/15 18:22:31 christos Exp $	*/
+/*	$NetBSD: wprintf.c,v 1.3 2013/04/19 15:22:25 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2002 Tim J. Robbins
@@ -31,14 +31,17 @@
 #if 0
 __FBSDID("$FreeBSD: src/lib/libc/stdio/wprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $");
 #else
-__RCSID("$NetBSD: wprintf.c,v 1.2 2012/03/15 18:22:31 christos Exp $");
+__RCSID("$NetBSD: wprintf.c,v 1.3 2013/04/19 15:22:25 joerg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
+#include "namespace.h"
 #include <stdarg.h>
 #include <stdio.h>
 #include <wchar.h>
 
+__weak_alias(wprintf_l, _wprintf_l)
+
 int
 wprintf(const wchar_t * __restrict fmt, ...)
 {
@@ -51,3 +54,16 @@ wprintf(const wchar_t * __restrict fmt, 
 
 	return ret;
 }
+
+int
+wprintf_l(locale_t loc, const wchar_t * __restrict fmt, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, fmt);
+	ret = vfwprintf_l(stdout, loc, fmt, ap);
+	va_end(ap);
+
+	return ret;
+}

Index: src/lib/libc/stdio/local.h
diff -u src/lib/libc/stdio/local.h:1.34 src/lib/libc/stdio/local.h:1.35
--- src/lib/libc/stdio/local.h:1.34	Tue Mar 27 15:05:42 2012
+++ src/lib/libc/stdio/local.h	Fri Apr 19 15:22:25 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: local.h,v 1.34 2012/03/27 15:05:42 christos Exp $	*/
+/*	$NetBSD: local.h,v 1.35 2013/04/19 15:22:25 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -67,8 +67,8 @@ extern int	__svfscanf(FILE * __restrict,
     va_list) __scanflike(2, 0);
 extern int	__svfscanf_unlocked(FILE * __restrict, const char * __restrict,
     va_list) __scanflike(2, 0);
-extern int	__vfprintf_unlocked(FILE * __restrict, const char * __restrict,
-    va_list) __printflike(2, 0);
+extern int	__vfprintf_unlocked_l(FILE * __restrict, locale_t,
+    const char * __restrict, va_list) __printflike(3, 0);
 
 
 extern int	__sdidinit;
@@ -81,7 +81,7 @@ extern wint_t	__fputwc_unlock(wchar_t, F
 extern ssize_t	__getdelim(char **__restrict, size_t *__restrict, int,
     FILE *__restrict);
 extern char	*__fgetstr(FILE * __restrict, size_t * __restrict, int);
-extern int 	 __vfwprintf_unlocked(FILE *, const wchar_t *, va_list);
+extern int 	 __vfwprintf_unlocked_l(FILE *, locale_t, const wchar_t *, va_list);
 extern int	 __vfwscanf_unlocked(FILE * __restrict,
     const wchar_t * __restrict, va_list);
 

Index: src/lib/libc/stdio/vasprintf.c
diff -u src/lib/libc/stdio/vasprintf.c:1.14 src/lib/libc/stdio/vasprintf.c:1.15
--- src/lib/libc/stdio/vasprintf.c:1.14	Thu Mar 15 18:22:30 2012
+++ src/lib/libc/stdio/vasprintf.c	Fri Apr 19 15:22:25 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vasprintf.c,v 1.14 2012/03/15 18:22:30 christos Exp $	*/
+/*	$NetBSD: vasprintf.c,v 1.15 2013/04/19 15:22:25 joerg Exp $	*/
 
 /*
  * Copyright (c) 1997 Todd C. Miller <[email protected]>
@@ -29,18 +29,28 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: vasprintf.c,v 1.14 2012/03/15 18:22:30 christos Exp $");
+__RCSID("$NetBSD: vasprintf.c,v 1.15 2013/04/19 15:22:25 joerg Exp $");
 #endif /* LIBC_SCCS and not lint */
 
+#include "namespace.h"
+
 #include <assert.h>
 #include <errno.h>
+#include <locale.h>
 #include <stdio.h>
 #include <stdlib.h>
+
 #include "reentrant.h"
+#include "setlocale_local.h"
 #include "local.h"
 
+__weak_alias(asprintf, _asprintf)
+__weak_alias(asprintf_l, _asprintf_l)
+__weak_alias(vasprintf, _vasprintf)
+__weak_alias(vasprintf_l, _vasprintf_l)
+
 int
-vasprintf(char **str, const char *fmt, va_list ap)
+vasprintf_l(char **str, locale_t loc, const char *fmt, va_list ap)
 {
 	int ret;
 	FILE f;
@@ -57,7 +67,7 @@ vasprintf(char **str, const char *fmt, v
 	if (f._bf._base == NULL)
 		goto err;
 	f._bf._size = f._w = 127;		/* Leave room for the NUL */
-	ret = __vfprintf_unlocked(&f, fmt, ap);
+	ret = __vfprintf_unlocked_l(&f, loc, fmt, ap);
 	if (ret == -1)
 		goto err;
 	*f._p = '\0';
@@ -74,3 +84,33 @@ err:
 	errno = ENOMEM;
 	return -1;
 }
+
+int
+vasprintf(char **str, const char *fmt, va_list ap)
+{
+	return vasprintf_l(str, *_current_locale(), fmt, ap);
+}
+
+int
+asprintf_l(char **str, locale_t loc, char const *fmt, ...)
+{
+	va_list ap;
+	int ret;
+
+	va_start(ap, fmt);
+	ret = vasprintf_l(str, loc, fmt, ap);
+	va_end(ap);
+	return ret;
+}
+
+int
+asprintf(char **str, char const *fmt, ...)
+{
+	va_list ap;
+	int ret;
+
+	va_start(ap, fmt);
+	ret = vasprintf(str, fmt, ap);
+	va_end(ap);
+	return ret;
+}

Index: src/lib/libc/stdio/vfprintf.c
diff -u src/lib/libc/stdio/vfprintf.c:1.59 src/lib/libc/stdio/vfprintf.c:1.60
--- src/lib/libc/stdio/vfprintf.c:1.59	Thu Oct 15 06:19:35 2009
+++ src/lib/libc/stdio/vfprintf.c	Fri Apr 19 15:22:25 2013
@@ -1,2 +1,5 @@
 #define NARROW
 #include "vfwprintf.c"
+
+
+__weak_alias(vfprintf_l, _vfprintf_l)

Index: src/lib/libc/stdio/vfwprintf.c
diff -u src/lib/libc/stdio/vfwprintf.c:1.30 src/lib/libc/stdio/vfwprintf.c:1.31
--- src/lib/libc/stdio/vfwprintf.c:1.30	Tue Mar 27 15:05:42 2012
+++ src/lib/libc/stdio/vfwprintf.c	Fri Apr 19 15:22:25 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfwprintf.c,v 1.30 2012/03/27 15:05:42 christos Exp $	*/
+/*	$NetBSD: vfwprintf.c,v 1.31 2013/04/19 15:22:25 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -38,7 +38,7 @@
 static char sccsid[] = "@(#)vfprintf.c	8.1 (Berkeley) 6/4/93";
 __FBSDID("$FreeBSD: src/lib/libc/stdio/vfwprintf.c,v 1.27 2007/01/09 00:28:08 imp Exp $");
 #else
-__RCSID("$NetBSD: vfwprintf.c,v 1.30 2012/03/27 15:05:42 christos Exp $");
+__RCSID("$NetBSD: vfwprintf.c,v 1.31 2013/04/19 15:22:25 joerg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -64,6 +64,7 @@ __RCSID("$NetBSD: vfwprintf.c,v 1.30 201
 #include <wctype.h>
 
 #include "reentrant.h"
+#include "setlocale_local.h"
 #include "local.h"
 #include "extern.h"
 #include "fvwrite.h"
@@ -73,7 +74,7 @@ __RCSID("$NetBSD: vfwprintf.c,v 1.30 201
 #define CHAR_T		wchar_t
 #define STRLEN(a)	wcslen(a)
 #define MEMCHR(a, b, c)	wmemchr(a, b, c)
-#define SCONV(a, b)	__mbsconv(a, b)
+#define SCONV(a, b, loc)	__mbsconv(a, b, loc)
 #define STRCONST(a)	L ## a
 #define WDECL(a, b)	a ## w ## b
 #define END_OF_FILE	WEOF
@@ -83,7 +84,7 @@ __RCSID("$NetBSD: vfwprintf.c,v 1.30 201
 #define CHAR_T		char
 #define STRLEN(a)	strlen(a)
 #define MEMCHR(a, b, c)	memchr(a, b, c)
-#define SCONV(a, b)	__wcsconv(a, b)
+#define SCONV(a, b, loc)	__wcsconv(a, b, loc)
 #define STRCONST(a)	a
 #define WDECL(a, b)	a ## b
 #define END_OF_FILE	EOF
@@ -131,16 +132,20 @@ enum typeid {
 	T_DOUBLE, T_LONG_DOUBLE, T_WINT, TP_WCHAR
 };
 
-static int	__sbprintf(FILE *, const CHAR_T *, va_list);
+#ifdef NARROW
+__printflike(3, 0)
+#endif
+static int	__sbprintf(FILE *, locale_t, const CHAR_T *, va_list);
+
 static CHAR_T	*__ujtoa(uintmax_t, CHAR_T *, int, int, const char *, int,
 		    char, const char *);
 static CHAR_T	*__ultoa(u_long, CHAR_T *, int, int, const char *, int,
 		    char, const char *);
 #ifndef NARROW
-static CHAR_T	*__mbsconv(char *, int);
-static wint_t	__xfputwc(CHAR_T, FILE *);
+static CHAR_T	*__mbsconv(char *, int, locale_t);
+static wint_t	__xfputwc(CHAR_T, FILE *, locale_t);
 #else
-static char	*__wcsconv(wchar_t *, int);
+static char	*__wcsconv(wchar_t *, int, locale_t);
 static int	__sprint(FILE *, struct __suio *);
 #endif
 static int	__find_arguments(const CHAR_T *, va_list, union arg **);
@@ -152,7 +157,7 @@ static int	__grow_type_table(size_t, enu
  * worries about ungetc buffers and so forth.
  */
 static int
-__sbprintf(FILE *fp, const CHAR_T *fmt, va_list ap)
+__sbprintf(FILE *fp, locale_t loc, const CHAR_T *fmt, va_list ap)
 {
 	int ret;
 	FILE fake;
@@ -178,7 +183,7 @@ __sbprintf(FILE *fp, const CHAR_T *fmt, 
 	fake._lbfsize = 0;	/* not actually used, but Just In Case */
 
 	/* do the work, then copy any error status */
-	ret = WDECL(__vf,printf_unlocked)(&fake, fmt, ap);
+	ret = WDECL(__vf,printf_unlocked_l)(&fake, loc, fmt, ap);
 	if (ret >= 0 && fflush(&fake))
 		ret = END_OF_FILE;
 	if (fake._flags & __SERR)
@@ -192,7 +197,7 @@ __sbprintf(FILE *fp, const CHAR_T *fmt, 
  * 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;
@@ -205,7 +210,7 @@ __xfputwc(wchar_t wc, FILE *fp)
 		return __fputwc_unlock(wc, fp);
 
 	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 END_OF_FILE;
 	}
@@ -412,7 +417,7 @@ __ujtoa(uintmax_t val, CHAR_T *endp, int
  * 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;
@@ -436,7 +441,7 @@ __mbsconv(char *mbsarg, int prec)
 		insize = nchars = nconv = 0;
 		mbs = initial;
 		while (nchars != (size_t)prec) {
-			nconv = mbrlen(p, MB_CUR_MAX, &mbs);
+			nconv = mbrlen_l(p, MB_CUR_MAX_L(loc), &mbs, loc);
 			if (nconv == 0 || nconv == (size_t)-1 ||
 			    nconv == (size_t)-2)
 				break;
@@ -462,7 +467,7 @@ __mbsconv(char *mbsarg, int prec)
 	mbs = initial;
 	nconv = 0;
 	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++;
@@ -485,7 +490,7 @@ __mbsconv(char *mbsarg, int prec)
  * string ends is null-terminated.
  */
 static char *
-__wcsconv(wchar_t *wcsarg, int prec)
+__wcsconv(wchar_t *wcsarg, int prec, locale_t loc)
 {
 	static const mbstate_t initial;
 	mbstate_t mbs;
@@ -498,7 +503,7 @@ __wcsconv(wchar_t *wcsarg, int prec)
 	if (prec < 0) {
 		p = wcsarg;
 		mbs = initial;
-		nbytes = wcsrtombs(NULL, (void *)&p, 0, &mbs);
+		nbytes = wcsrtombs_l(NULL, (void *)&p, 0, &mbs, loc);
 		if (nbytes == (size_t)-1)
 			return NULL;
 	} else {
@@ -514,7 +519,7 @@ __wcsconv(wchar_t *wcsarg, int prec)
 			p = wcsarg;
 			mbs = initial;
 			for (;;) {
-				clen = wcrtomb(buf, *p++, &mbs);
+				clen = wcrtomb_l(buf, *p++, &mbs, loc);
 				if (clen == 0 || clen == (size_t)-1 ||
 				    nbytes + clen > (size_t)prec)
 					break;
@@ -528,8 +533,8 @@ __wcsconv(wchar_t *wcsarg, int prec)
 	/* Fill the output buffer. */
 	p = wcsarg;
 	mbs = initial;
-	if ((nbytes = wcsrtombs(convbuf, (void *)&p,
-	    nbytes, &mbs)) == (size_t)-1) {
+	if ((nbytes = wcsrtombs_l(convbuf, (void *)&p,
+	    nbytes, &mbs, loc)) == (size_t)-1) {
 		free(convbuf);
 		return NULL;
 	}
@@ -547,7 +552,19 @@ WDECL(vf,printf)(FILE * __restrict fp, c
 	int ret;
 
 	FLOCKFILE(fp);
-	ret = WDECL(__vf,printf_unlocked)(fp, fmt0, ap);
+	ret = WDECL(__vf,printf_unlocked_l)(fp, *_current_locale(), fmt0, ap);
+	FUNLOCKFILE(fp);
+	return ret;
+}
+
+int
+WDECL(vf,printf_l)(FILE * __restrict fp, locale_t loc, const CHAR_T * __restrict fmt0,
+    va_list ap)
+{
+	int ret;
+
+	FLOCKFILE(fp);
+	ret = WDECL(__vf,printf_unlocked_l)(fp, loc, fmt0, ap);
 	FUNLOCKFILE(fp);
 	return ret;
 }
@@ -600,7 +617,7 @@ static char *cvt(double, int, int, char 
  * Non-MT-safe version
  */
 int
-WDECL(__vf,printf_unlocked)(FILE *fp, const CHAR_T *fmt0, va_list ap)
+WDECL(__vf,printf_unlocked_l)(FILE *fp, locale_t loc, const CHAR_T *fmt0, va_list ap)
 {
 	CHAR_T *fmt;		/* format string */
 	int ch;			/* character from fmt */
@@ -688,6 +705,9 @@ WDECL(__vf,printf_unlocked)(FILE *fp, co
 	static const char xdigs_lower[16] = "0123456789abcdef";
 	static const char xdigs_upper[16] = "0123456789ABCDEF";
 
+	if (loc == NULL)
+		loc = _C_locale;
+
 	/*
 	 * BEWARE, these `goto error' on error, PRINT uses `n2' and
 	 * PAD uses `n'.
@@ -695,7 +715,7 @@ WDECL(__vf,printf_unlocked)(FILE *fp, co
 #ifndef NARROW
 #define	PRINT(ptr, len)	do {			\
 	for (n3 = 0; n3 < (len); n3++)		\
-		__xfputwc((ptr)[n3], fp);	\
+		__xfputwc((ptr)[n3], fp, loc);	\
 } while (/*CONSTCOND*/0)
 #define FLUSH()
 #else
@@ -809,7 +829,7 @@ WDECL(__vf,printf_unlocked)(FILE *fp, co
 	thousands_sep = '\0';
 	grouping = NULL;
 #ifndef NO_FLOATING_POINT
-	decimal_point = localeconv()->decimal_point;
+	decimal_point = localeconv_l(loc)->decimal_point;
 	expsize = 0;		/* XXXGCC -Wuninitialized [sh3,m68000] */
 #endif
 	convbuf = NULL;
@@ -822,7 +842,7 @@ WDECL(__vf,printf_unlocked)(FILE *fp, co
 	/* optimise fprintf(stderr) (and other unbuffered Unix files) */
 	if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
 	    __sfileno(fp) != -1)
-		return __sbprintf(fp, fmt0, ap);
+		return __sbprintf(fp, loc, fmt0, ap);
 
 	fmt = (CHAR_T *)__UNCONST(fmt0);
 	argtable = NULL;
@@ -903,8 +923,8 @@ reswitch:	switch (ch) {
 			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;
 			/* If the locale doesn't define the above, use sane
 			 * defaults - otherwise silly things happen! */
 			if (thousands_sep == 0)
@@ -992,8 +1012,8 @@ reswitch:	switch (ch) {
 				size_t mbseqlen;
 
 				mbs = initial;
-				mbseqlen = wcrtomb(buf,
-				    (wchar_t)GETARG(wint_t), &mbs);
+				mbseqlen = wcrtomb_l(buf,
+				    (wchar_t)GETARG(wint_t), &mbs, loc);
 				if (mbseqlen == (size_t)-1) {
 					fp->_flags |= __SERR;
 					goto error;
@@ -1007,7 +1027,7 @@ reswitch:	switch (ch) {
 			if (flags & LONGINT)
 				*buf = (wchar_t)GETARG(wint_t);
 			else
-				*buf = (wchar_t)btowc(GETARG(int));
+				*buf = (wchar_t)btowc_l(GETARG(int), loc);
 			size = 1;
 #endif
 			result = buf;
@@ -1074,7 +1094,7 @@ reswitch:	switch (ch) {
 			if (convbuf != NULL)
 				free(convbuf);
 #ifndef NARROW
-			result = convbuf = __mbsconv(dtoaresult, -1);
+			result = convbuf = __mbsconv(dtoaresult, -1, loc);
 #else
 			/*XXX inefficient*/
 			result = convbuf = strdup(dtoaresult);
@@ -1123,7 +1143,7 @@ fp_begin:
 			if (convbuf != NULL)
 				free(convbuf);
 #ifndef NARROW
-			result = convbuf = __mbsconv(dtoaresult, -1);
+			result = convbuf = __mbsconv(dtoaresult, -1, loc);
 #else
 			/*XXX inefficient*/
 			result = convbuf = strdup(dtoaresult);
@@ -1195,7 +1215,7 @@ fp_common:
 			if (convbuf != NULL)
 				free(convbuf);
 #ifndef NARROW
-			result = convbuf = __mbsconv(dtoaresult, -1);
+			result = convbuf = __mbsconv(dtoaresult, -1, loc);
 #else
 			/*XXX inefficient*/
 			result = convbuf = strdup(dtoaresult);
@@ -1323,7 +1343,7 @@ fp_common:
 				if ((mc = GETARG(MCHAR_T *)) == NULL)
 					result = STRCONST("(null)");
 				else {
-					convbuf = SCONV(mc, prec);
+					convbuf = SCONV(mc, prec, loc);
 					if (convbuf == NULL) {
 						fp->_flags |= __SERR;
 						goto error;

Index: src/lib/libc/stdio/vsnprintf.c
diff -u src/lib/libc/stdio/vsnprintf.c:1.25 src/lib/libc/stdio/vsnprintf.c:1.26
--- src/lib/libc/stdio/vsnprintf.c:1.25	Thu Mar 15 18:22:31 2012
+++ src/lib/libc/stdio/vsnprintf.c	Fri Apr 19 15:22:25 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vsnprintf.c,v 1.25 2012/03/15 18:22:31 christos Exp $	*/
+/*	$NetBSD: vsnprintf.c,v 1.26 2013/04/19 15:22:25 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)vsnprintf.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: vsnprintf.c,v 1.25 2012/03/15 18:22:31 christos Exp $");
+__RCSID("$NetBSD: vsnprintf.c,v 1.26 2013/04/19 15:22:25 joerg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -45,21 +45,28 @@ __RCSID("$NetBSD: vsnprintf.c,v 1.25 201
 
 #include <assert.h>
 #include <errno.h>
+#include <locale.h>
 #include <stdio.h>
 #include "reentrant.h"
+#include "setlocale_local.h"
 #include "local.h"
 
 #if defined(_FORTIFY_SOURCE) && !defined(__lint__)
 #undef vsnprintf
 #define vsnprintf _vsnprintf
+#undef snprintf
+#define snprintf _snprintf
 #endif
 
 #ifdef __weak_alias
 __weak_alias(vsnprintf,_vsnprintf)
+__weak_alias(vsnprintf_l,_vsnprintf_l)
+__weak_alias(snprintf,_snprintf)
+__weak_alias(snprintf_l,_snprintf_l)
 #endif
 
 int
-vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
+vsnprintf_l(char *str, size_t n, locale_t loc, const char *fmt, va_list ap)
 {
 	int ret;
 	FILE f;
@@ -85,7 +92,37 @@ vsnprintf(char *str, size_t n, const cha
 		_DIAGASSERT(__type_fit(int, n - 1));
 		f._bf._size = f._w = (int)(n - 1);
 	}
-	ret = __vfprintf_unlocked(&f, fmt, ap);
+	ret = __vfprintf_unlocked_l(&f, loc, fmt, ap);
 	*f._p = 0;
 	return ret;
 }
+
+int
+vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
+{
+	return vsnprintf_l(str, n, *_current_locale(), fmt, ap);
+}
+
+int
+snprintf(char *str, size_t n, const char *fmt, ...)
+{
+	va_list ap;
+	int ret;
+
+	va_start(ap, fmt);
+	ret = vsnprintf(str, n, fmt, ap);
+	va_end(ap);
+	return ret;
+}
+
+int
+snprintf_l(char *str, size_t n, locale_t loc, const char *fmt, ...)
+{
+	va_list ap;
+	int ret;
+
+	va_start(ap, fmt);
+	ret = vsnprintf_l(str, n, loc, fmt, ap);
+	va_end(ap);
+	return ret;
+}

Index: src/lib/libc/stdio/vsprintf.c
diff -u src/lib/libc/stdio/vsprintf.c:1.17 src/lib/libc/stdio/vsprintf.c:1.18
--- src/lib/libc/stdio/vsprintf.c:1.17	Thu Mar 15 18:22:31 2012
+++ src/lib/libc/stdio/vsprintf.c	Fri Apr 19 15:22:25 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vsprintf.c,v 1.17 2012/03/15 18:22:31 christos Exp $	*/
+/*	$NetBSD: vsprintf.c,v 1.18 2013/04/19 15:22:25 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,23 +37,31 @@
 #if 0
 static char sccsid[] = "@(#)vsprintf.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: vsprintf.c,v 1.17 2012/03/15 18:22:31 christos Exp $");
+__RCSID("$NetBSD: vsprintf.c,v 1.18 2013/04/19 15:22:25 joerg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
+#include "namespace.h"
 #include <assert.h>
 #include <errno.h>
 #include <limits.h>
+#include <locale.h>
 #include <stdio.h>
+
 #include "reentrant.h"
+#include "setlocale_local.h"
 #include "local.h"
 
 #ifdef _FORTIFY_SOURCE
 #undef vsprintf
+#undef sprintf
 #endif
 
+__weak_alias(sprintf_l, _sprintf_l)
+__weak_alias(vsprintf_l, _vsprintf_l)
+
 int
-vsprintf(char *str, const char *fmt, va_list ap)
+vsprintf_l(char *str, locale_t loc, const char *fmt, va_list ap)
 {
 	int ret;
 	FILE f;
@@ -67,7 +75,39 @@ vsprintf(char *str, const char *fmt, va_
 	f._flags = __SWR | __SSTR;
 	f._bf._base = f._p = (unsigned char *)str;
 	f._bf._size = f._w = INT_MAX;
-	ret = __vfprintf_unlocked(&f, fmt, ap);
+	ret = __vfprintf_unlocked_l(&f, loc, fmt, ap);
 	*f._p = 0;
 	return ret;
 }
+
+int
+vsprintf(char *str, const char *fmt, va_list ap)
+{
+	return vsprintf_l(str, *_current_locale(), fmt, ap);
+}
+
+int
+sprintf_l(char *str, locale_t loc, char const *fmt, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, fmt);
+	ret = vsprintf_l(str, loc, fmt, ap);
+	va_end(ap);
+
+	return ret;
+}
+
+int
+sprintf(char *str, char const *fmt, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, fmt);
+	ret = vsprintf(str, fmt, ap);
+	va_end(ap);
+
+	return ret;
+}

Index: src/lib/libc/stdio/vswprintf.c
diff -u src/lib/libc/stdio/vswprintf.c:1.3 src/lib/libc/stdio/vswprintf.c:1.4
--- src/lib/libc/stdio/vswprintf.c:1.3	Thu Mar 15 18:22:31 2012
+++ src/lib/libc/stdio/vswprintf.c	Fri Apr 19 15:22:25 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vswprintf.c,v 1.3 2012/03/15 18:22:31 christos Exp $	*/
+/*	$NetBSD: vswprintf.c,v 1.4 2013/04/19 15:22:25 joerg Exp $	*/
 
 /*
  * Copyright (c) 1997 Todd C. Miller <[email protected]>
@@ -32,21 +32,27 @@
 #if 0
 __FBSDID("$FreeBSD: src/lib/libc/stdio/vswprintf.c,v 1.6 2005/02/21 19:41:44 fjoe Exp $");
 #else
-__RCSID("$NetBSD: vswprintf.c,v 1.3 2012/03/15 18:22:31 christos Exp $");
+__RCSID("$NetBSD: vswprintf.c,v 1.4 2013/04/19 15:22:25 joerg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
+#include "namespace.h"
 #include <errno.h>
+#include <locale.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <wchar.h>
 #include <stdarg.h>
+
 #include "reentrant.h"
+#include "setlocale_local.h"
 #include "local.h"
 
+__weak_alias(vswprintf_l, _vswprintf_l)
+
 int
-vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt,
-    va_list ap)
+vswprintf_l(wchar_t * __restrict s, size_t n, locale_t loc,
+    const wchar_t * __restrict fmt, va_list ap)
 {
 	static const mbstate_t initial;
 	mbstate_t mbs;
@@ -70,7 +76,7 @@ vswprintf(wchar_t * __restrict s, size_t
 		return -1;
 	}
 	f._bf._size = f._w = 127;		/* Leave room for the NUL */
-	ret = __vfwprintf_unlocked(&f, fmt, ap);
+	ret = __vfwprintf_unlocked_l(&f, loc, fmt, ap);
 	if (ret < 0) {
 		sverrno = errno;
 		free(f._bf._base);
@@ -84,7 +90,7 @@ vswprintf(wchar_t * __restrict s, size_t
 	 * fputwc() did in __vfwprintf().
 	 */
 	mbs = initial;
-	nwc = mbsrtowcs(s, (void *)&mbp, n, &mbs);
+	nwc = mbsrtowcs_l(s, (void *)&mbp, n, &mbs, loc);
 	free(f._bf._base);
 	if (nwc == (size_t)-1) {
 		errno = EILSEQ;
@@ -98,3 +104,10 @@ vswprintf(wchar_t * __restrict s, size_t
 
 	return ret;
 }
+
+int
+vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt,
+    va_list ap)
+{
+	return vswprintf_l(s, n, *_current_locale(), fmt, ap);
+}

Reply via email to