Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add explicit locale versions for the printf family. Replace ...
details: https://anonhg.NetBSD.org/src/rev/8320c5e8be63
branches: trunk
changeset: 786194:8320c5e8be63
user: joerg <joerg%NetBSD.org@localhost>
date: Fri Apr 19 15:22:24 2013 +0000
description:
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.
diffstat:
include/stdio.h | 36 ++++++++++++++++-
include/wchar.h | 12 +++++-
lib/libc/include/namespace.h | 23 +++++++++-
lib/libc/stdio/Makefile.inc | 8 +-
lib/libc/stdio/asprintf.c | 85 ---------------------------------------
lib/libc/stdio/dprintf.c | 18 +++++++-
lib/libc/stdio/fprintf.c | 19 +++++++-
lib/libc/stdio/fwprintf.c | 20 ++++++++-
lib/libc/stdio/local.h | 8 +-
lib/libc/stdio/printf.c | 19 +++++++-
lib/libc/stdio/snprintf.c | 95 --------------------------------------------
lib/libc/stdio/sprintf.c | 78 ------------------------------------
lib/libc/stdio/swprintf.c | 21 ++++++++-
lib/libc/stdio/vasprintf.c | 48 ++++++++++++++++++++-
lib/libc/stdio/vdprintf.c | 17 ++++++-
lib/libc/stdio/vfprintf.c | 3 +
lib/libc/stdio/vfwprintf.c | 88 +++++++++++++++++++++++++---------------
lib/libc/stdio/vprintf.c | 14 +++++-
lib/libc/stdio/vsnprintf.c | 45 ++++++++++++++++++-
lib/libc/stdio/vsprintf.c | 48 ++++++++++++++++++++-
lib/libc/stdio/vswprintf.c | 25 ++++++++--
lib/libc/stdio/vwprintf.c | 13 +++++-
lib/libc/stdio/wprintf.c | 20 ++++++++-
23 files changed, 421 insertions(+), 342 deletions(-)
diffs (truncated from 1542 to 300 lines):
diff -r d9f032913937 -r 8320c5e8be63 include/stdio.h
--- a/include/stdio.h Fri Apr 19 14:35:31 2013 +0000
+++ b/include/stdio.h Fri Apr 19 15:22:24 2013 +0000
@@ -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 @@
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
diff -r d9f032913937 -r 8320c5e8be63 include/wchar.h
--- a/include/wchar.h Fri Apr 19 14:35:31 2013 +0000
+++ b/include/wchar.h Fri Apr 19 15:22:24 2013 +0000
@@ -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 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_ */
diff -r d9f032913937 -r 8320c5e8be63 lib/libc/include/namespace.h
--- a/lib/libc/include/namespace.h Fri Apr 19 14:35:31 2013 +0000
+++ b/lib/libc/include/namespace.h Fri Apr 19 15:22:24 2013 +0000
@@ -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
diff -r d9f032913937 -r 8320c5e8be63 lib/libc/stdio/Makefile.inc
--- a/lib/libc/stdio/Makefile.inc Fri Apr 19 14:35:31 2013 +0000
+++ b/lib/libc/stdio/Makefile.inc Fri Apr 19 15:22:24 2013 +0000
@@ -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 @@
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+= 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
diff -r d9f032913937 -r 8320c5e8be63 lib/libc/stdio/asprintf.c
--- a/lib/libc/stdio/asprintf.c Fri Apr 19 14:35:31 2013 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-/* $NetBSD: asprintf.c,v 1.19 2012/03/15 18:22:30 christos Exp $ */
-
-/*
- * Copyright (c) 1997 Todd C. Miller <Todd.Miller%courtesan.com@localhost>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: asprintf.c,v 1.19 2012/03/15 18:22:30 christos Exp $");
-#endif /* LIBC_SCCS and not lint */
-
-#include "namespace.h"
-#include <assert.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include "reentrant.h"
-#include "local.h"
-
-#ifdef __weak_alias
-__weak_alias(asprintf, _asprintf)
-#endif
-
-int
-asprintf(char **str, char const *fmt, ...)
-{
- int ret;
- va_list ap;
- FILE f;
- struct __sfileext fext;
- unsigned char *_base;
-
- _DIAGASSERT(str != NULL);
-
- _FILEEXT_SETUP(&f, &fext);
- f._file = -1;
- f._flags = __SWR | __SSTR | __SALC;
- f._bf._base = f._p = malloc((size_t)128);
- if (f._bf._base == NULL)
- goto err;
- f._bf._size = f._w = 127; /* Leave room for the NUL */
- va_start(ap, fmt);
- ret = __vfprintf_unlocked(&f, fmt, ap);
- va_end(ap);
- if (ret < 0)
- goto err;
- *f._p = '\0';
- _base = realloc(f._bf._base, (size_t)ret + 1);
- if (_base == NULL)
- goto err;
- *str = (char *)_base;
- return ret;
-
-err:
- if (f._bf._base)
- free(f._bf._base);
- *str = NULL;
- errno = ENOMEM;
- return -1;
-}
Home |
Main Index |
Thread Index |
Old Index