Synchronize on NetBSD-CVS (2013/12/1 12:00:00 UTC)

- Fix for possible unset uid/gid in toproto
 - Fix for default mtree style
 - Update libelf
 - Importing libexecinfo
 - Resynchronize GCC, mpc, gmp, mpfr
 - build.sh: Replace params with show-params.
     This has been done as the make target has been renamed in the same
     way, while a new target named params has been added. This new
     target generates a file containing all the parameters, instead of
     printing it on the console.
 - Update test48 with new etc/services (Fix by Ben Gras <ben@minix3.org)
     get getservbyport() out of the inner loop

Change-Id: Ie6ad5226fa2621ff9f0dee8782ea48f9443d2091
This commit is contained in:
2013-12-06 12:04:52 +01:00
parent ff10274392
commit 84d9c625bf
4655 changed files with 379317 additions and 151059 deletions

View File

@@ -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 fclose.c fdopen.c feof.c ferror.c \
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 fclose.c fdopen.c feof.c ferror.c \
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

View File

@@ -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>
* 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;
}

View File

@@ -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/09/06 14:52:55 christos Exp $");
#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 fmt, ...)
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;
}

View File

@@ -56,7 +56,7 @@ int __sdidinit;
#define NDYNAMIC 10 /* add ten more whenever necessary */
#if !defined(_LIBMINC) && !defined(__kernel__)
#if !defined(_LIBMINC) && !defined(__kernel__) && defined(__minix)
#define std(flags, file) { \
._p = NULL, \
@@ -132,7 +132,7 @@ FILE __sF[3] = {
std(__SWR|__SNBF, STDERR_FILENO) /* stderr */
};
#if !defined(__kernel__)
#if !defined(__kernel__) && defined(__minix)
struct glue __sglue = { &uglue, 3, __sF };
void f_prealloc(void);
@@ -221,7 +221,7 @@ found:
void
f_prealloc(void)
{
#if !defined(_LIBMINC)
#if !defined(_LIBMINC) && defined(__minix)
struct glue *g;
int n;
@@ -243,7 +243,7 @@ f_prealloc(void)
void
_cleanup(void)
{
#if !defined(_LIBMINC)
#if !defined(_LIBMINC) && defined(__minix)
/* (void) _fwalk(fclose); */
(void) fflush(NULL); /* `cheating' */
#endif /* !defined(_LIBMINC) */

View File

@@ -1,4 +1,4 @@
/* $NetBSD: flags.c,v 1.16 2012/03/15 18:22:30 christos Exp $ */
/* $NetBSD: flags.c,v 1.17 2012/11/15 03:50:36 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)flags.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: flags.c,v 1.16 2012/03/15 18:22:30 christos Exp $");
__RCSID("$NetBSD: flags.c,v 1.17 2012/11/15 03:50:36 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -90,6 +90,7 @@ __sflags(const char *mode, int *optr)
* [rwa]\+ or [rwa]b\+ means read and write
* f means open only plain files,
* e means set close on exec.
* x means exclusive open.
*/
for (; *mode; mode++)
switch (*mode) {
@@ -103,6 +104,9 @@ __sflags(const char *mode, int *optr)
case 'e':
o |= O_CLOEXEC;
break;
case 'x':
o |= O_EXCL;
break;
case 'b':
break;
default: /* We could produce a warning here */

View File

@@ -1,4 +1,4 @@
.\" $NetBSD: fopen.3,v 1.28 2012/07/02 20:02:43 wiz Exp $
.\" $NetBSD: fopen.3,v 1.29 2012/11/15 03:50:36 christos Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -33,7 +33,7 @@
.\"
.\" @(#)fopen.3 8.1 (Berkeley) 6/4/93
.\"
.Dd July 18, 2011
.Dd November 14, 2012
.Dt FOPEN 3
.Os
.Sh NAME
@@ -117,6 +117,12 @@ will fail.
This is a non
.St -ansiC
extension.
.It Sq x
The letter
.Sq x
in the mode turns on exclusive open mode to the file (
.Dv O_EXCL )
which means that the file will not be created if it already exists.
.El
.Pp
Any created files will have mode

View File

@@ -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;
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: fscanf.c,v 1.13 2012/03/15 18:22:30 christos Exp $ */
/* $NetBSD: fscanf.c,v 1.14 2013/04/19 23:32:17 joerg Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,10 +37,12 @@
#if 0
static char sccsid[] = "@(#)fscanf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: fscanf.c,v 1.13 2012/03/15 18:22:30 christos Exp $");
__RCSID("$NetBSD: fscanf.c,v 1.14 2013/04/19 23:32:17 joerg Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
@@ -49,6 +51,8 @@ __RCSID("$NetBSD: fscanf.c,v 1.13 2012/03/15 18:22:30 christos Exp $");
#include "reentrant.h"
#include "local.h"
__weak_alias(fscanf_l, _fscanf_l)
int
fscanf(FILE *fp, char const *fmt, ...)
{
@@ -60,3 +64,15 @@ fscanf(FILE *fp, char const *fmt, ...)
va_end(ap);
return ret;
}
int
fscanf_l(FILE *fp, locale_t loc, char const *fmt, ...)
{
int ret;
va_list ap;
va_start(ap, fmt);
ret = __svfscanf_l(fp, loc, fmt, ap);
va_end(ap);
return ret;
}

View File

@@ -150,8 +150,7 @@ fseeko(FILE *fp, off_t offset, int whence)
fp->_flags |= __SNPT;
goto dumb;
}
fp->_blksize = st.st_blksize;
fp->_blksize = st.st_blksize;
fp->_flags |= __SOPT;
}

View File

@@ -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 wchar_t * __restrict fmt, ...)
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;
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: fwscanf.c,v 1.2 2012/03/15 18:22:30 christos Exp $ */
/* $NetBSD: fwscanf.c,v 1.3 2013/04/19 23:32:17 joerg Exp $ */
/*-
* Copyright (c) 2002 Tim J. Robbins
@@ -31,14 +31,18 @@
#if 0
__FBSDID("$FreeBSD: src/lib/libc/stdio/fwscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $");
#else
__RCSID("$NetBSD: fwscanf.c,v 1.2 2012/03/15 18:22:30 christos Exp $");
__RCSID("$NetBSD: fwscanf.c,v 1.3 2013/04/19 23:32:17 joerg Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
__weak_alias(fwscanf_l, _fwscanf_l)
int
fwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, ...)
{
@@ -51,3 +55,17 @@ fwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, ...)
return r;
}
int
fwscanf_l(FILE * __restrict fp, locale_t loc, const wchar_t * __restrict fmt,
...)
{
va_list ap;
int r;
va_start(ap, fmt);
r = vfwscanf_l(fp, loc, fmt, ap);
va_end(ap);
return r;
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: gets.c,v 1.17 2012/03/15 18:22:30 christos Exp $ */
/* $NetBSD: gets.c,v 1.18 2013/10/04 20:49:16 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)gets.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: gets.c,v 1.17 2012/03/15 18:22:30 christos Exp $");
__RCSID("$NetBSD: gets.c,v 1.18 2013/10/04 20:49:16 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -53,7 +53,7 @@ __RCSID("$NetBSD: gets.c,v 1.17 2012/03/15 18:22:30 christos Exp $");
__warn_references(gets, "warning: this program uses gets(), which is unsafe.")
char *
gets(char *buf)
__gets(char *buf)
{
int c;
char *s;
@@ -77,3 +77,8 @@ gets(char *buf)
FUNLOCKFILE(stdin);
return buf;
}
char *
gets(char *buf) {
return __gets(buf);
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: gettemp.c,v 1.15 2012/03/15 18:22:30 christos Exp $ */
/* $NetBSD: gettemp.c,v 1.16 2013/04/22 20:57:36 christos Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -40,7 +40,7 @@
#if 0
static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: gettemp.c,v 1.15 2012/03/15 18:22:30 christos Exp $");
__RCSID("$NetBSD: gettemp.c,v 1.16 2013/04/22 20:57:36 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -119,14 +119,16 @@ GETTEMP(char *path, int *doopen, int domkdir)
if (trv <= path)
break;
if (*trv == '/') {
int e;
*trv = '\0';
if (stat(path, &sbuf))
return 0;
e = stat(path, &sbuf);
*trv = '/';
if (e == -1)
return doopen == NULL && !domkdir;
if (!S_ISDIR(sbuf.st_mode)) {
errno = ENOTDIR;
return 0;
return doopen == NULL && !domkdir;
}
*trv = '/';
break;
}
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: local.h,v 1.34 2012/03/27 15:05:42 christos Exp $ */
/* $NetBSD: local.h,v 1.37 2013/10/04 20:49:16 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -65,10 +65,12 @@ extern int __swsetup(FILE *);
extern int __sflags(const char *, int *);
extern int __svfscanf(FILE * __restrict, const char * __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 __svfscanf_l(FILE * __restrict, locale_t,
const char * __restrict, va_list) __scanflike(3, 0);
extern int __svfscanf_unlocked_l(FILE * __restrict, locale_t,
const char * __restrict, va_list) __scanflike(3, 0);
extern int __vfprintf_unlocked_l(FILE * __restrict, locale_t,
const char * __restrict, va_list) __printflike(3, 0);
extern int __sdidinit;
@@ -81,8 +83,8 @@ extern wint_t __fputwc_unlock(wchar_t, FILE *);
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 __vfwscanf_unlocked(FILE * __restrict,
extern int __vfwprintf_unlocked_l(FILE *, locale_t, const wchar_t *, va_list);
extern int __vfwscanf_unlocked_l(FILE * __restrict, locale_t,
const wchar_t * __restrict, va_list);
/*
@@ -115,6 +117,8 @@ extern int __vfwscanf_unlocked(FILE * __restrict,
extern void __flockfile_internal(FILE *, int);
extern void __funlockfile_internal(FILE *, int);
extern char *__gets(char *);
/*
* Detect if the current file position fits in a long int.
*/

View File

@@ -121,7 +121,8 @@ __swhatbuf(FILE *fp, size_t *bufsize, int *couldbetty)
* __sseek is mainly paranoia.) It is safe to set _blksize
* unconditionally; it will only be used if __SOPT is also set.
*/
*bufsize = fp->_blksize = st.st_blksize;
*bufsize = st.st_blksize;
fp->_blksize = st.st_blksize;
return (st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek ?
__SOPT : __SNPT;
}

View File

@@ -1,4 +1,4 @@
.\" $NetBSD: printf.3,v 1.58 2010/12/26 12:39:54 jnemeth Exp $
.\" $NetBSD: printf.3,v 1.63 2013/05/04 19:17:38 wiz Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -33,7 +33,7 @@
.\"
.\" @(#)printf.3 8.1 (Berkeley) 6/4/93
.\"
.Dd December 26, 2010
.Dd May 4, 2013
.Dt PRINTF 3
.Os
.Sh NAME
@@ -42,6 +42,7 @@
.Nm dprintf
.Nm sprintf ,
.Nm snprintf ,
.Nm snprintf_ss ,
.Nm asprintf ,
.Nm vprintf ,
.Nm vfprintf ,
@@ -66,6 +67,8 @@
.Ft int
.Fn snprintf "char * restrict str" "size_t size" "const char * restrict format" ...
.Ft int
.Fn snprintf_ss "char * restrict str" "size_t size" "const char * restrict format" ...
.Ft int
.Fn asprintf "char ** restrict ret" "const char * restrict format" ...
.In stdarg.h
.Ft int
@@ -104,10 +107,11 @@ write output to the given output
.Fn dprintf
and
.Fn vdprintf
write output to the give file descriptor
write output to the given file descriptor
.Fa fd ;
.Fn sprintf ,
.Fn snprintf ,
.Fn snprintf_ss ,
.Fn vsprintf ,
.Fn vsnprintf ,
and
@@ -128,9 +132,11 @@ string that specifies how subsequent arguments
.Xr stdarg 3 )
are converted for output.
.Pp
.Fn snprintf_ss
and
.Fn vsnprintf_ss
is a signal-safe standalone version that does not handle
floating point formats.
are signal-safe standalone versions that do not handle
floating point formats, positional arguments, and wide characters.
.Pp
.Fn asprintf
and
@@ -772,14 +778,14 @@ To allocate a 128 byte string and print into it:
#include \*[Lt]stdarg.h\*[Gt]
char *newfmt(const char *fmt, ...)
{
char *p;
va_list ap;
if ((p = malloc(128)) == NULL)
return (NULL);
va_start(ap, fmt);
(void) vsnprintf(p, 128, fmt, ap);
va_end(ap);
return (p);
char *p;
va_list ap;
if ((p = malloc(128)) == NULL)
return (NULL);
va_start(ap, fmt);
(void) vsnprintf(p, 128, fmt, ap);
va_end(ap);
return (p);
}
.Ed
.Sh ERRORS
@@ -884,7 +890,9 @@ Be sure to use the proper secure idiom:
snprintf(buffer, sizeof(buffer), "%s", string);
.Ed
.Pp
There is no way for printf to know the size of each argument passed.
There is no way for
.Fn printf
to know the size of each argument passed.
If you use positional arguments you must ensure that all parameters, up to the
last positionally specified parameter, are used in the format string.
This allows for the format string to be parsed for this information.

View File

@@ -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;
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: scanf.c,v 1.13 2012/03/15 18:22:30 christos Exp $ */
/* $NetBSD: scanf.c,v 1.14 2013/04/19 23:32:17 joerg Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,10 +37,12 @@
#if 0
static char sccsid[] = "@(#)scanf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: scanf.c,v 1.13 2012/03/15 18:22:30 christos Exp $");
__RCSID("$NetBSD: scanf.c,v 1.14 2013/04/19 23:32:17 joerg Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
@@ -49,6 +51,8 @@ __RCSID("$NetBSD: scanf.c,v 1.13 2012/03/15 18:22:30 christos Exp $");
#include "reentrant.h"
#include "local.h"
__weak_alias(scanf_l, _scanf_l)
int
scanf(char const *fmt, ...)
{
@@ -62,3 +66,17 @@ scanf(char const *fmt, ...)
va_end(ap);
return ret;
}
int
scanf_l(locale_t loc, char const *fmt, ...)
{
int ret;
va_list ap;
_DIAGASSERT(fmt != NULL);
va_start(ap, fmt);
ret = __svfscanf_l(stdin, loc, fmt, ap);
va_end(ap);
return ret;
}

View File

@@ -1,95 +0,0 @@
/* $NetBSD: snprintf.c,v 1.24 2012/03/15 18:22:30 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* 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. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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)
#if 0
static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: snprintf.c,v 1.24 2012/03/15 18:22:30 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include "reentrant.h"
#include "local.h"
#if defined(_FORTIFY_SOURCE) && !defined(__lint__)
#undef snprintf
#define snprintf _snprintf
#endif
#ifdef __weak_alias
__weak_alias(snprintf,_snprintf)
#endif
int
snprintf(char *str, size_t n, char const *fmt, ...)
{
int ret;
va_list ap;
FILE f;
struct __sfileext fext;
unsigned char dummy[1];
_DIAGASSERT(n == 0 || str != NULL);
_DIAGASSERT(fmt != NULL);
if ((int)n < 0) {
errno = EINVAL;
return -1;
}
va_start(ap, fmt);
_FILEEXT_SETUP(&f, &fext);
f._file = -1;
f._flags = __SWR | __SSTR;
if (n == 0) {
f._bf._base = f._p = dummy;
f._bf._size = f._w = 0;
} else {
f._bf._base = f._p = (unsigned char *)str;
_DIAGASSERT(__type_fit(int, n - 1));
f._bf._size = f._w = (int)(n - 1);
}
ret = __vfprintf_unlocked(&f, fmt, ap);
*f._p = 0;
va_end(ap);
return ret;
}

View File

@@ -1,78 +0,0 @@
/* $NetBSD: sprintf.c,v 1.16 2012/03/15 18:22:30 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* 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. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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)
#if 0
static char sccsid[] = "@(#)sprintf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: sprintf.c,v 1.16 2012/03/15 18:22:30 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include "reentrant.h"
#include "local.h"
#ifdef _FORTIFY_SOURCE
#undef sprintf
#endif
int
sprintf(char *str, char const *fmt, ...)
{
int ret;
va_list ap;
FILE f;
struct __sfileext fext;
_DIAGASSERT(str != NULL);
_DIAGASSERT(fmt != NULL);
_FILEEXT_SETUP(&f, &fext);
f._file = -1;
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = INT_MAX;
va_start(ap, fmt);
ret = __vfprintf_unlocked(&f, fmt, ap);
va_end(ap);
*f._p = 0;
return ret;
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: sscanf.c,v 1.20 2012/03/27 15:05:42 christos Exp $ */
/* $NetBSD: sscanf.c,v 1.21 2013/04/19 23:32:17 joerg Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,10 +37,12 @@
#if 0
static char sccsid[] = "@(#)sscanf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: sscanf.c,v 1.20 2012/03/27 15:05:42 christos Exp $");
__RCSID("$NetBSD: sscanf.c,v 1.21 2013/04/19 23:32:17 joerg Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
@@ -50,36 +52,32 @@ __RCSID("$NetBSD: sscanf.c,v 1.20 2012/03/27 15:05:42 christos Exp $");
#include "reentrant.h"
#include "local.h"
/* ARGSUSED */
static ssize_t
eofread(void *cookie, void *buf, size_t len)
{
return 0;
}
__weak_alias(sscanf_l, _sscanf_l)
int
sscanf(const char *str, char const *fmt, ...)
{
int ret;
va_list ap;
FILE f;
size_t len;
struct __sfileext fext;
_DIAGASSERT(str != NULL);
_DIAGASSERT(fmt != NULL);
_FILEEXT_SETUP(&f, &fext);
f._flags = __SRD;
f._bf._base = f._p = __UNCONST(str);
len = strlen(str);
_DIAGASSERT(__type_fit(int, len));
f._bf._size = f._r = (int)len;
f._read = eofread;
_UB(&f)._base = NULL;
va_start(ap, fmt);
ret = __svfscanf_unlocked(&f, fmt, ap);
ret = vsscanf(str, fmt, ap);
va_end(ap);
return ret;
}
int
sscanf_l(const char *str, locale_t loc, char const *fmt, ...)
{
int ret;
va_list ap;
_DIAGASSERT(fmt != NULL);
va_start(ap, fmt);
ret = vsscanf_l(str, loc, fmt, ap);
va_end(ap);
return ret;
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: stdio.c,v 1.21 2012/03/27 15:05:42 christos Exp $ */
/* $NetBSD: stdio.c,v 1.22 2013/05/19 17:07:04 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)stdio.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: stdio.c,v 1.21 2012/03/27 15:05:42 christos Exp $");
__RCSID("$NetBSD: stdio.c,v 1.22 2013/05/19 17:07:04 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -86,8 +86,12 @@ __swrite(void *cookie, const void *buf, size_t n)
_DIAGASSERT(buf != NULL);
if (fp->_flags & __SAPP)
if (lseek(__sfileno(fp), (off_t)0, SEEK_END) == (off_t)-1)
return -1;
if (lseek(__sfileno(fp), (off_t)0, SEEK_END) == (off_t)-1) {
if (errno == ESPIPE) /* if unseekable, OK, */
fp->_flags &= ~__SAPP; /* all writes append. */
else
return -1;
}
fp->_flags &= ~__SOFF; /* in case FAPPEND mode is set */
return write(__sfileno(fp), buf, n);
}

View File

@@ -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 n, const wchar_t * __restrict fmt, ...)
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;
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: swscanf.c,v 1.2 2012/03/15 18:22:30 christos Exp $ */
/* $NetBSD: swscanf.c,v 1.3 2013/04/19 23:32:17 joerg Exp $ */
/*-
* Copyright (c) 2002 Tim J. Robbins
@@ -31,14 +31,18 @@
#if 0
__FBSDID("$FreeBSD: src/lib/libc/stdio/swscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $");
#else
__RCSID("$NetBSD: swscanf.c,v 1.2 2012/03/15 18:22:30 christos Exp $");
__RCSID("$NetBSD: swscanf.c,v 1.3 2013/04/19 23:32:17 joerg Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
__weak_alias(swscanf_l, _swscanf_l)
int
swscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt, ...)
{
@@ -51,3 +55,17 @@ swscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt, ...)
return r;
}
int
swscanf_l(const wchar_t * __restrict str, locale_t loc,
const wchar_t * __restrict fmt, ...)
{
va_list ap;
int r;
va_start(ap, fmt);
r = vswscanf_l(str, loc, fmt, ap);
va_end(ap);
return r;
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: vasprintf.c,v 1.14 2012/03/15 18:22:30 christos Exp $ */
/* $NetBSD: vasprintf.c,v 1.17 2013/05/19 21:45:00 christos Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -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.17 2013/05/19 21:45:00 christos 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;
@@ -53,11 +63,11 @@ vasprintf(char **str, const char *fmt, va_list ap)
_FILEEXT_SETUP(&f, &fext);
f._file = -1;
f._flags = __SWR | __SSTR | __SALC;
f._bf._base = f._p = (unsigned char *)malloc(128);
f._bf._base = f._p = malloc(128);
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;
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: vdprintf.c,v 1.2 2011/07/17 20:54:34 joerg Exp $ */
/* $NetBSD: vdprintf.c,v 1.4 2013/05/17 12:55:57 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.4 2013/05/17 12:55:57 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@@ -43,19 +43,22 @@ __RCSID("$NetBSD: vdprintf.c,v 1.2 2011/07/17 20:54:34 joerg Exp $");
#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 fmt, va_list ap)
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);
}

View File

@@ -1,2 +1,5 @@
#define NARROW
#include "vfwprintf.c"
__weak_alias(vfprintf_l, _vfprintf_l)

View File

@@ -1,4 +1,4 @@
/* $NetBSD: vfscanf.c,v 1.43 2012/03/15 18:22:30 christos Exp $ */
/* $NetBSD: vfscanf.c,v 1.45 2013/05/17 12:55:57 joerg Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -38,7 +38,7 @@
static char sccsid[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93";
__FBSDID("$FreeBSD: src/lib/libc/stdio/vfscanf.c,v 1.41 2007/01/09 00:28:07 imp Exp $");
#else
__RCSID("$NetBSD: vfscanf.c,v 1.43 2012/03/15 18:22:30 christos Exp $");
__RCSID("$NetBSD: vfscanf.c,v 1.45 2013/05/17 12:55:57 joerg Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -57,9 +57,8 @@ __RCSID("$NetBSD: vfscanf.c,v 1.43 2012/03/15 18:22:30 christos Exp $");
#include "reentrant.h"
#include "local.h"
#ifndef NO_FLOATING_POINT
#include <locale.h>
#endif
#include "setlocale_local.h"
/*
* Provide an external name for vfscanf. Note, we don't use the normal
@@ -68,6 +67,7 @@ __RCSID("$NetBSD: vfscanf.c,v 1.43 2012/03/15 18:22:30 christos Exp $");
*/
#ifdef __weak_alias
__weak_alias(vfscanf,__svfscanf)
__weak_alias(vfscanf_l,__svfscanf_l)
#endif
#define BUF 513 /* Maximum length of numeric string. */
@@ -107,22 +107,22 @@ __weak_alias(vfscanf,__svfscanf)
#define CT_INT 3 /* %[dioupxX] conversion */
#define CT_FLOAT 4 /* %[efgEFG] conversion */
static const u_char *__sccl(char *, const u_char *);
static const u_char *__sccl(char *, const u_char *, locale_t);
#ifndef NO_FLOATING_POINT
static size_t parsefloat(FILE *, char *, char *);
static size_t parsefloat(FILE *, char *, char *, locale_t);
#endif
int __scanfdebug = 0;
#define __collate_load_error /*CONSTCOND*/0
static int
__collate_range_cmp(int c1, int c2)
__collate_range_cmp(int c1, int c2, locale_t loc)
{
static char s1[2], s2[2];
s1[0] = c1;
s2[0] = c2;
return strcoll(s1, s2);
return strcoll_l(s1, s2, loc);
}
@@ -131,18 +131,24 @@ __collate_range_cmp(int c1, int c2)
*/
int
__svfscanf(FILE *fp, char const *fmt0, va_list ap)
{
return __svfscanf_l(fp, _current_locale(), fmt0, ap);
}
int
__svfscanf_l(FILE *fp, locale_t loc, char const *fmt0, va_list ap)
{
int ret;
FLOCKFILE(fp);
ret = __svfscanf_unlocked(fp, fmt0, ap);
ret = __svfscanf_unlocked_l(fp, loc, fmt0, ap);
FUNLOCKFILE(fp);
return ret;
}
#define SCANF_SKIP_SPACE() \
do { \
while ((fp->_r > 0 || __srefill(fp) == 0) && isspace(*fp->_p)) \
while ((fp->_r > 0 || __srefill(fp) == 0) && isspace_l(*fp->_p, loc)) \
nread++, fp->_r--, fp->_p++; \
} while (/*CONSTCOND*/ 0)
@@ -150,7 +156,7 @@ do { \
* __svfscanf_unlocked - non-MT-safe version of __svfscanf
*/
int
__svfscanf_unlocked(FILE *fp, const char *fmt0, va_list ap)
__svfscanf_unlocked_l(FILE *fp, locale_t loc, const char *fmt0, va_list ap)
{
const u_char *fmt = (const u_char *)fmt0;
int c; /* character from format, or conversion */
@@ -187,9 +193,9 @@ __svfscanf_unlocked(FILE *fp, const char *fmt0, va_list ap)
c = (unsigned char)*fmt++;
if (c == 0)
return nassigned;
if (isspace(c)) {
if (isspace_l(c, loc)) {
while ((fp->_r > 0 || __srefill(fp) == 0) &&
isspace(*fp->_p))
isspace_l(*fp->_p, loc))
nread++, fp->_r--, fp->_p++;
continue;
}
@@ -300,7 +306,7 @@ literal:
break;
case '[':
fmt = __sccl(ccltab, fmt);
fmt = __sccl(ccltab, fmt, loc);
flags |= NOSKIP;
c = CT_CCL;
break;
@@ -363,7 +369,7 @@ literal:
* that suppress this.
*/
if ((flags & NOSKIP) == 0) {
while (isspace(*fp->_p)) {
while (isspace_l(*fp->_p, loc)) {
nread++;
if (--fp->_r > 0)
fp->_p++;
@@ -393,7 +399,7 @@ literal:
wcp = NULL;
n = 0;
while (width != 0) {
if (n == MB_CUR_MAX) {
if (n == MB_CUR_MAX_L(loc)) {
fp->_flags |= __SERR;
goto input_failure;
}
@@ -401,7 +407,8 @@ literal:
fp->_p++;
fp->_r--;
mbs = initial;
nconv = mbrtowc(wcp, buf, n, &mbs);
nconv = mbrtowc_l(wcp, buf, n, &mbs,
loc);
if (nconv == (size_t)-1) {
fp->_flags |= __SERR;
goto input_failure;
@@ -475,7 +482,7 @@ literal:
n = 0;
nchars = 0;
while (width != 0) {
if (n == MB_CUR_MAX) {
if (n == MB_CUR_MAX_L(loc)) {
fp->_flags |= __SERR;
goto input_failure;
}
@@ -483,7 +490,8 @@ literal:
fp->_p++;
fp->_r--;
mbs = initial;
nconv = mbrtowc(wcp, buf, n, &mbs);
nconv = mbrtowc_l(wcp, buf, n, &mbs,
loc);
if (nconv == (size_t)-1) {
fp->_flags |= __SERR;
goto input_failure;
@@ -491,8 +499,8 @@ literal:
if (nconv == 0)
*wcp = L'\0';
if (nconv != (size_t)-2) {
if (wctob(*wcp) != EOF &&
!ccltab[wctob(*wcp)]) {
if (wctob_l(*wcp, loc) != EOF &&
!ccltab[wctob_l(*wcp, loc)]) {
while (n != 0) {
n--;
(void)ungetc(buf[n],
@@ -575,8 +583,8 @@ literal:
else
wcp = &twc;
n = 0;
while (!isspace(*fp->_p) && width != 0) {
if (n == MB_CUR_MAX) {
while (!isspace_l(*fp->_p, loc) && width != 0) {
if (n == MB_CUR_MAX_L(loc)) {
fp->_flags |= __SERR;
goto input_failure;
}
@@ -584,7 +592,8 @@ literal:
fp->_p++;
fp->_r--;
mbs = initial;
nconv = mbrtowc(wcp, buf, n, &mbs);
nconv = mbrtowc_l(wcp, buf, n, &mbs,
loc);
if (nconv == (size_t)-1) {
fp->_flags |= __SERR;
goto input_failure;
@@ -592,7 +601,7 @@ literal:
if (nconv == 0)
*wcp = L'\0';
if (nconv != (size_t)-2) {
if (iswspace(*wcp)) {
if (iswspace_l(*wcp, loc)) {
while (n != 0) {
n--;
(void)ungetc(buf[n],
@@ -620,7 +629,7 @@ literal:
}
} else if (flags & SUPPRESS) {
n = 0;
while (!isspace(*fp->_p)) {
while (!isspace_l(*fp->_p, loc)) {
n++, fp->_r--, fp->_p++;
if (--width == 0)
break;
@@ -630,7 +639,7 @@ literal:
nread += n;
} else {
p0 = p = va_arg(ap, char *);
while (!isspace(*fp->_p)) {
while (!isspace_l(*fp->_p, loc)) {
fp->_r--;
*p++ = *fp->_p++;
if (--width == 0)
@@ -773,9 +782,11 @@ literal:
*p = 0;
if ((flags & UNSIGNED) == 0)
res = strtoimax(buf, (char **)NULL, base);
res = strtoimax_l(buf, (char **)NULL, base,
loc);
else
res = strtoumax(buf, (char **)NULL, base);
res = strtoumax_l(buf, (char **)NULL, base,
loc);
if (flags & POINTER)
*va_arg(ap, void **) =
(void *)(uintptr_t)res;
@@ -807,17 +818,18 @@ literal:
/* scan a floating point number as if by strtod */
if (width == 0 || width > sizeof(buf) - 1)
width = sizeof(buf) - 1;
if ((width = parsefloat(fp, buf, buf + width)) == 0)
if ((width = parsefloat(fp, buf, buf + width, loc)) == 0)
goto match_failure;
if ((flags & SUPPRESS) == 0) {
if (flags & LONGDBL) {
long double res = strtold(buf, &p);
long double res = strtold_l(buf, &p,
loc);
*va_arg(ap, long double *) = res;
} else if (flags & LONG) {
double res = strtod(buf, &p);
double res = strtod_l(buf, &p, loc);
*va_arg(ap, double *) = res;
} else {
float res = strtof(buf, &p);
float res = strtof_l(buf, &p, loc);
*va_arg(ap, float *) = res;
}
if (__scanfdebug && (size_t)(p - buf) != width)
@@ -843,7 +855,7 @@ match_failure:
* considered part of the scanset.
*/
static const u_char *
__sccl(char *tab, const u_char *fmt)
__sccl(char *tab, const u_char *fmt, locale_t loc)
{
int c, n, v, i;
@@ -901,7 +913,7 @@ doswitch:
*/
n = *fmt;
if (n == ']' || (__collate_load_error ? n < c :
__collate_range_cmp(n, c) < 0)) {
__collate_range_cmp(n, c, loc) < 0)) {
c = '-';
break; /* resume the for(;;) */
}
@@ -913,8 +925,8 @@ doswitch:
while (c < n);
} else {
for (i = 0; i < 256; i ++)
if (__collate_range_cmp(c, i) < 0 &&
__collate_range_cmp(i, n) <= 0)
if (__collate_range_cmp(c, i, loc) < 0 &&
__collate_range_cmp(i, n, loc) <= 0)
tab[i] = v;
}
#if 1 /* XXX another disgusting compatibility hack */
@@ -946,7 +958,7 @@ doswitch:
#ifndef NO_FLOATING_POINT
static size_t
parsefloat(FILE *fp, char *buf, char *end)
parsefloat(FILE *fp, char *buf, char *end, locale_t loc)
{
char *commit, *p;
int infnanpos = 0;
@@ -955,7 +967,7 @@ parsefloat(FILE *fp, char *buf, char *end)
S_DIGITS, S_FRAC, S_EXP, S_EXPDIGITS
} state = S_START;
unsigned char c;
char decpt = *localeconv()->decimal_point;
char decpt = *localeconv_l(loc)->decimal_point;
_Bool gotmantdig = 0, ishex = 0;
/*
@@ -1028,7 +1040,7 @@ reswitch:
if (c == ')') {
commit = p;
infnanpos = -2;
} else if (!isalnum(c) && c != '_')
} else if (!isalnum_l(c, loc) && c != '_')
goto parsedone;
break;
}
@@ -1044,7 +1056,7 @@ reswitch:
goto reswitch;
}
case S_DIGITS:
if ((ishex && isxdigit(c)) || isdigit(c))
if ((ishex && isxdigit_l(c, loc)) || isdigit_l(c, loc))
gotmantdig = 1;
else {
state = S_FRAC;
@@ -1061,7 +1073,7 @@ reswitch:
goto parsedone;
else
state = S_EXP;
} else if ((ishex && isxdigit(c)) || isdigit(c)) {
} else if ((ishex && isxdigit_l(c, loc)) || isdigit_l(c, loc)) {
commit = p;
gotmantdig = 1;
} else
@@ -1074,7 +1086,7 @@ reswitch:
else
goto reswitch;
case S_EXPDIGITS:
if (isdigit(c))
if (isdigit_l(c, loc))
commit = p;
else
goto parsedone;

View File

@@ -1,4 +1,4 @@
/* $NetBSD: vfwprintf.c,v 1.30 2012/03/27 15:05:42 christos Exp $ */
/* $NetBSD: vfwprintf.c,v 1.33 2013/09/23 12:41:37 pooka 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.33 2013/09/23 12:41:37 pooka Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -64,6 +64,7 @@ __RCSID("$NetBSD: vfwprintf.c,v 1.30 2012/03/27 15:05:42 christos Exp $");
#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 2012/03/27 15:05:42 christos Exp $");
#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 2012/03/27 15:05:42 christos Exp $");
#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, enum typeid **, size_t *);
* 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, va_list ap)
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, va_list ap)
* 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 base, int octzero,
* 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, const CHAR_T * __restrict fmt0, va_list a
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 *, int *, int, int *);
* 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 */
@@ -695,7 +712,7 @@ WDECL(__vf,printf_unlocked)(FILE *fp, const CHAR_T *fmt0, va_list ap)
#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
@@ -804,13 +821,12 @@ WDECL(__vf,printf_unlocked)(FILE *fp, const CHAR_T *fmt0, va_list ap)
_SET_ORIENTATION(fp, -1);
ndig = -1; /* XXX gcc */
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] */
ndig = -1; /* XXX gcc */
#endif
convbuf = NULL;
/* sorry, f{w,}printf(read_only_file, L"") returns {W,}EOF, not 0 */
@@ -822,7 +838,7 @@ WDECL(__vf,printf_unlocked)(FILE *fp, const CHAR_T *fmt0, va_list ap)
/* 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;
@@ -862,9 +878,11 @@ WDECL(__vf,printf_unlocked)(FILE *fp, const CHAR_T *fmt0, va_list ap)
prec = -1;
sign = '\0';
ox[1] = '\0';
#ifndef NO_FLOATING_POINT
expchar = '\0';
lead = 0;
nseps = nrepeats = 0;
#endif
ulval = 0;
ujval = 0;
xdigs = NULL;
@@ -903,8 +921,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 +1010,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 +1025,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 +1092,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 +1141,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 +1213,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 +1341,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;

View File

@@ -1,4 +1,4 @@
/* $NetBSD: vfwscanf.c,v 1.8 2012/03/15 18:22:30 christos Exp $ */
/* $NetBSD: vfwscanf.c,v 1.11 2013/09/23 12:41:37 pooka Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -42,7 +42,7 @@
static char sccsid[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95";
__FBSDID("$FreeBSD: src/lib/libc/stdio/vfwscanf.c,v 1.12 2004/05/02 20:13:29 obrien Exp $");
#else
__RCSID("$NetBSD: vfwscanf.c,v 1.8 2012/03/15 18:22:30 christos Exp $");
__RCSID("$NetBSD: vfwscanf.c,v 1.11 2013/09/23 12:41:37 pooka Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -62,9 +62,8 @@ __RCSID("$NetBSD: vfwscanf.c,v 1.8 2012/03/15 18:22:30 christos Exp $");
#include "reentrant.h"
#include "local.h"
#ifndef NO_FLOATING_POINT
#include <locale.h>
#endif
#include "setlocale_local.h"
#define BUF 513 /* Maximum length of numeric string. */
@@ -103,7 +102,9 @@ __RCSID("$NetBSD: vfwscanf.c,v 1.8 2012/03/15 18:22:30 christos Exp $");
#define CT_INT 3 /* %[dioupxX] conversion */
#define CT_FLOAT 4 /* %[efgEFG] conversion */
static int parsefloat(FILE *, wchar_t *, wchar_t *);
#ifndef NO_FLOATING_POINT
static int parsefloat(FILE *, wchar_t *, wchar_t *, locale_t);
#endif
#define INCCL(_c) \
(cclcompl ? (wmemchr(ccls, (_c), (size_t)(ccle - ccls)) == NULL) : \
@@ -114,12 +115,19 @@ static int parsefloat(FILE *, wchar_t *, wchar_t *);
*/
int
vfwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, va_list ap)
{
return vfwscanf_l(fp, _current_locale(), fmt, ap);
}
int
vfwscanf_l(FILE * __restrict fp, locale_t loc, const wchar_t * __restrict fmt,
va_list ap)
{
int ret;
FLOCKFILE(fp);
_SET_ORIENTATION(fp, 1);
ret = __vfwscanf_unlocked(fp, fmt, ap);
ret = __vfwscanf_unlocked_l(fp, loc, fmt, ap);
FUNLOCKFILE(fp);
return ret;
}
@@ -128,7 +136,7 @@ vfwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, va_list ap)
do { \
wint_t tc; \
\
while ((tc = __fgetwc_unlock(fp)) != WEOF && iswspace(tc)) \
while ((tc = __fgetwc_unlock(fp)) != WEOF && iswspace_l(tc, loc)) \
continue; \
if (tc != WEOF) \
ungetwc(tc, fp); \
@@ -138,7 +146,8 @@ do { \
* Non-MT-safe version.
*/
int
__vfwscanf_unlocked(FILE * __restrict fp, const wchar_t * __restrict fmt, va_list ap)
__vfwscanf_unlocked_l(FILE * __restrict fp, locale_t loc,
const wchar_t * __restrict fmt, va_list ap)
{
wint_t c; /* character from format, or conversion */
size_t width; /* field width, or 0 */
@@ -157,10 +166,9 @@ __vfwscanf_unlocked(FILE * __restrict fp, const wchar_t * __restrict fmt, va_lis
wint_t wi; /* handy wint_t */
char *mbp; /* multibyte string pointer for %c %s %[ */
size_t nconv; /* number of bytes in mb. conversion */
char mbbuf[MB_LEN_MAX]; /* temporary mb. character buffer */
static const mbstate_t initial;
mbstate_t mbs;
char mbbuf[MB_LEN_MAX]; /* temporary mb. character buffer */
/* `basefix' is used to avoid `if' tests in the integer scanner */
static short basefix[17] =
{ 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
@@ -176,9 +184,9 @@ __vfwscanf_unlocked(FILE * __restrict fp, const wchar_t * __restrict fmt, va_lis
c = *fmt++;
if (c == 0)
return nassigned;
if (iswspace(c)) {
if (iswspace_l(c, loc)) {
while ((c = __fgetwc_unlock(fp)) != WEOF &&
iswspace(c))
iswspace_l(c, loc))
;
if (c != WEOF)
ungetwc(c, fp);
@@ -360,7 +368,8 @@ literal:
* that suppress this.
*/
if ((flags & NOSKIP) == 0) {
while ((wi = __fgetwc_unlock(fp)) != WEOF && iswspace(wi))
while ((wi = __fgetwc_unlock(fp)) != WEOF &&
iswspace_l(wi, loc))
nread++;
if (wi == WEOF)
goto input_failure;
@@ -398,14 +407,15 @@ literal:
mbs = initial;
while (width != 0 &&
(wi = __fgetwc_unlock(fp)) != WEOF) {
if (width >= MB_CUR_MAX &&
if (width >= MB_CUR_MAX_L(loc) &&
!(flags & SUPPRESS)) {
nconv = wcrtomb(mbp, wi, &mbs);
nconv = wcrtomb_l(mbp, wi,
&mbs, loc);
if (nconv == (size_t)-1)
goto input_failure;
} else {
nconv = wcrtomb(mbbuf, wi,
&mbs);
nconv = wcrtomb_l(mbbuf, wi,
&mbs, loc);
if (nconv == (size_t)-1)
goto input_failure;
if (nconv > width) {
@@ -464,14 +474,15 @@ literal:
mbs = initial;
while ((wi = __fgetwc_unlock(fp)) != WEOF &&
width != 0 && INCCL(wi)) {
if (width >= MB_CUR_MAX &&
if (width >= MB_CUR_MAX_L(loc) &&
!(flags & SUPPRESS)) {
nconv = wcrtomb(mbp, wi, &mbs);
nconv = wcrtomb_l(mbp, wi,
&mbs, loc);
if (nconv == (size_t)-1)
goto input_failure;
} else {
nconv = wcrtomb(mbbuf, wi,
&mbs);
nconv = wcrtomb_l(mbbuf, wi,
&mbs, loc);
if (nconv == (size_t)-1)
goto input_failure;
if (nconv > width)
@@ -503,7 +514,7 @@ literal:
if ((flags & SUPPRESS) && (flags & LONG)) {
while ((wi = __fgetwc_unlock(fp)) != WEOF &&
width-- != 0 &&
!iswspace(wi))
!iswspace_l(wi, loc))
nread++;
if (wi != WEOF)
ungetwc(wi, fp);
@@ -511,7 +522,7 @@ literal:
p0 = p = va_arg(ap, wchar_t *);
while ((wi = __fgetwc_unlock(fp)) != WEOF &&
width-- != 0 &&
!iswspace(wi)) {
!iswspace_l(wi, loc)) {
*p++ = (wchar_t)wi;
nread++;
}
@@ -525,15 +536,16 @@ literal:
mbs = initial;
while ((wi = __fgetwc_unlock(fp)) != WEOF &&
width != 0 &&
!iswspace(wi)) {
if (width >= MB_CUR_MAX &&
!iswspace_l(wi, loc)) {
if (width >= MB_CUR_MAX_L(loc) &&
!(flags & SUPPRESS)) {
nconv = wcrtomb(mbp, wi, &mbs);
nconv = wcrtomb_l(mbp, wi,
&mbs, loc);
if (nconv == (size_t)-1)
goto input_failure;
} else {
nconv = wcrtomb(mbbuf, wi,
&mbs);
nconv = wcrtomb_l(mbbuf, wi,
&mbs, loc);
if (nconv == (size_t)-1)
goto input_failure;
if (nconv > width)
@@ -677,9 +689,9 @@ literal:
*p = 0;
if ((flags & UNSIGNED) == 0)
res = wcstoimax(buf, NULL, base);
res = wcstoimax_l(buf, NULL, base, loc);
else
res = wcstoumax(buf, NULL, base);
res = wcstoumax_l(buf, NULL, base, loc);
if (flags & POINTER)
*va_arg(ap, void **) =
(void *)(uintptr_t)res;
@@ -712,18 +724,19 @@ literal:
if (width == 0 || width > sizeof(buf) /
sizeof(*buf) - 1)
width = sizeof(buf) / sizeof(*buf) - 1;
if ((width = parsefloat(fp, buf, buf + width)) == 0)
if ((width = parsefloat(fp, buf, buf + width, loc)) == 0)
goto match_failure;
if ((flags & SUPPRESS) == 0) {
if (flags & LONGDBL) {
long double res = wcstold(buf, &p);
long double res = wcstold_l(buf, &p,
loc);
*va_arg(ap, long double *) = res;
} else
if (flags & LONG) {
double res = wcstod(buf, &p);
double res = wcstod_l(buf, &p, loc);
*va_arg(ap, double *) = res;
} else {
float res = wcstof(buf, &p);
float res = wcstof_l(buf, &p, loc);
*va_arg(ap, float *) = res;
}
#ifdef DEBUG
@@ -746,7 +759,7 @@ match_failure:
#ifndef NO_FLOATING_POINT
static int
parsefloat(FILE *fp, wchar_t *buf, wchar_t *end)
parsefloat(FILE *fp, wchar_t *buf, wchar_t *end, locale_t loc)
{
wchar_t *commit, *p;
int infnanpos = 0;
@@ -755,7 +768,7 @@ parsefloat(FILE *fp, wchar_t *buf, wchar_t *end)
S_DIGITS, S_FRAC, S_EXP, S_EXPDIGITS
} state = S_START;
wchar_t c;
wchar_t decpt = (wchar_t)(unsigned char)*localeconv()->decimal_point;
wchar_t decpt = (wchar_t)(unsigned char)*localeconv_l(loc)->decimal_point;
int gotmantdig = 0, ishex = 0;
/*
@@ -830,7 +843,7 @@ reswitch:
if (c == ')') {
commit = p;
infnanpos = -2;
} else if (!iswalnum(c) && c != '_')
} else if (!iswalnum_l(c, loc) && c != '_')
goto parsedone;
break;
}
@@ -846,7 +859,8 @@ reswitch:
goto reswitch;
}
case S_DIGITS:
if ((ishex && iswxdigit(c)) || iswdigit(c))
if ((ishex && iswxdigit_l(c, loc)) ||
iswdigit_l(c, loc))
gotmantdig = 1;
else {
state = S_FRAC;
@@ -863,7 +877,8 @@ reswitch:
goto parsedone;
else
state = S_EXP;
} else if ((ishex && iswxdigit(c)) || iswdigit(c)) {
} else if ((ishex && iswxdigit_l(c, loc)) ||
iswdigit_l(c, loc)) {
commit = p;
gotmantdig = 1;
} else
@@ -876,7 +891,7 @@ reswitch:
else
goto reswitch;
case S_EXPDIGITS:
if (iswdigit(c))
if (iswdigit_l(c, loc))
commit = p;
else
goto parsedone;

View File

@@ -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);
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: vscanf.c,v 1.14 2012/03/15 18:22:31 christos Exp $ */
/* $NetBSD: vscanf.c,v 1.15 2013/04/19 23:32:17 joerg Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,10 +37,12 @@
#if 0
static char sccsid[] = "@(#)vscanf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: vscanf.c,v 1.14 2012/03/15 18:22:31 christos Exp $");
__RCSID("$NetBSD: vscanf.c,v 1.15 2013/04/19 23:32:17 joerg Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <errno.h>
#include <stdio.h>
@@ -48,6 +50,8 @@ __RCSID("$NetBSD: vscanf.c,v 1.14 2012/03/15 18:22:31 christos Exp $");
#include "reentrant.h"
#include "local.h"
__weak_alias(vscanf_l, _vscanf_l)
int
vscanf(const char *fmt, va_list ap)
{
@@ -56,3 +60,12 @@ vscanf(const char *fmt, va_list ap)
return __svfscanf(stdin, fmt, ap);
}
int
vscanf_l(locale_t loc, const char *fmt, va_list ap)
{
_DIAGASSERT(fmt != NULL);
return __svfscanf_l(stdin, loc, fmt, ap);
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: vsnprintf.c,v 1.25 2012/03/15 18:22:31 christos Exp $ */
/* $NetBSD: vsnprintf.c,v 1.27 2013/05/17 12:55:57 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.27 2013/05/17 12:55:57 joerg Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -45,21 +45,28 @@ __RCSID("$NetBSD: vsnprintf.c,v 1.25 2012/03/15 18:22:31 christos Exp $");
#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 char *fmt, va_list ap)
_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;
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: vsprintf.c,v 1.17 2012/03/15 18:22:31 christos Exp $ */
/* $NetBSD: vsprintf.c,v 1.19 2013/05/17 12:55:57 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.19 2013/05/17 12:55:57 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_list ap)
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;
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: vsscanf.c,v 1.19 2012/03/27 15:05:42 christos Exp $ */
/* $NetBSD: vsscanf.c,v 1.21 2013/05/17 12:55:57 joerg Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,17 +37,23 @@
#if 0
static char sccsid[] = "@(#)vsscanf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: vsscanf.c,v 1.19 2012/03/27 15:05:42 christos Exp $");
__RCSID("$NetBSD: vsscanf.c,v 1.21 2013/05/17 12:55:57 joerg Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include "reentrant.h"
#include "setlocale_local.h"
#include "local.h"
__weak_alias(vsscanf_l, _vsscanf_l)
/* ARGSUSED */
static ssize_t
eofread(void *cookie, void *buf, size_t len)
@@ -56,7 +62,7 @@ eofread(void *cookie, void *buf, size_t len)
}
int
vsscanf(const char *str, const char *fmt, va_list ap)
vsscanf_l(const char *str, locale_t loc, const char *fmt, va_list ap)
{
FILE f;
struct __sfileext fext;
@@ -73,5 +79,11 @@ vsscanf(const char *str, const char *fmt, va_list ap)
f._bf._size = f._r = (int)len;
f._read = eofread;
_UB(&f)._base = NULL;
return __svfscanf_unlocked(&f, fmt, ap);
return __svfscanf_unlocked_l(&f, loc, fmt, ap);
}
int
vsscanf(const char *str, const char *fmt, va_list ap)
{
return vsscanf_l(str, _current_locale(), fmt, ap);
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: vswprintf.c,v 1.3 2012/03/15 18:22:31 christos Exp $ */
/* $NetBSD: vswprintf.c,v 1.6 2013/05/19 21:45:00 christos Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -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.6 2013/05/19 21:45:00 christos 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;
@@ -64,13 +70,13 @@ vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt,
_FILEEXT_SETUP(&f, &fext);
f._file = -1;
f._flags = __SWR | __SSTR | __SALC;
f._bf._base = f._p = (unsigned char *)malloc(128);
f._bf._base = f._p = malloc(128);
if (f._bf._base == NULL) {
errno = ENOMEM;
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 n, const wchar_t * __restrict fmt,
* 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 n, const wchar_t * __restrict fmt,
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);
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: vswscanf.c,v 1.9 2012/03/27 15:05:42 christos Exp $ */
/* $NetBSD: vswscanf.c,v 1.12 2013/05/17 12:55:57 joerg Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -42,20 +42,26 @@
static char sccsid[] = "@(#)vsscanf.c 8.1 (Berkeley) 6/4/93";
__FBSDID("$FreeBSD: src/lib/libc/stdio/vswscanf.c,v 1.3 2004/04/07 09:55:05 tjr Exp $");
#else
__RCSID("$NetBSD: vswscanf.c,v 1.9 2012/03/27 15:05:42 christos Exp $");
__RCSID("$NetBSD: vswscanf.c,v 1.12 2013/05/17 12:55:57 joerg Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <limits.h>
#include <locale.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include "reentrant.h"
#include "setlocale_local.h"
#include "local.h"
__weak_alias(vswscanf_l, _vswscanf_l)
static ssize_t
/*ARGSUSED*/
eofread(void *cookie, void *buf, size_t len)
@@ -65,8 +71,8 @@ eofread(void *cookie, void *buf, size_t len)
}
int
vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt,
va_list ap)
vswscanf_l(const wchar_t * __restrict str, locale_t loc,
const wchar_t * __restrict fmt, va_list ap)
{
static const mbstate_t initial;
mbstate_t mbs;
@@ -81,10 +87,12 @@ vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt,
* XXX Convert the wide character string to multibyte, which
* __vfwscanf() will convert back to wide characters.
*/
if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX + 1)) == NULL)
mbstr = malloc(wcslen(str) * MB_CUR_MAX_L(loc) + 1);
if (mbstr == NULL)
return EOF;
mbs = initial;
if ((mlen = wcsrtombs(mbstr, &rstr, SIZE_T_MAX, &mbs)) == (size_t)-1) {
if ((mlen = wcsrtombs_l(mbstr, &rstr, SIZE_T_MAX, &mbs, loc))
== (size_t)-1) {
free(mbstr);
return EOF;
}
@@ -97,8 +105,15 @@ vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt,
f._bf._size = f._r = (int)mlen;
f._read = eofread;
_UB(&f)._base = NULL;
r = __vfwscanf_unlocked(&f, fmt, ap);
r = __vfwscanf_unlocked_l(&f, loc, fmt, ap);
free(mbstr);
return r;
}
int
vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt,
va_list ap)
{
return vswscanf_l(str, _current_locale(), fmt, ap);
}

View File

@@ -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)
{

View File

@@ -1,4 +1,4 @@
/* $NetBSD: vwscanf.c,v 1.2 2012/03/15 18:22:31 christos Exp $ */
/* $NetBSD: vwscanf.c,v 1.3 2013/04/19 23:32:17 joerg Exp $ */
/*-
* Copyright (c) 2002 Tim J. Robbins
@@ -31,17 +31,28 @@
#if 0
__FBSDID("$FreeBSD: src/lib/libc/stdio/vwscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $");
#else
__RCSID("$NetBSD: vwscanf.c,v 1.2 2012/03/15 18:22:31 christos Exp $");
__RCSID("$NetBSD: vwscanf.c,v 1.3 2013/04/19 23:32:17 joerg Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
__weak_alias(vwscanf_l, _vwscanf_l)
int
vwscanf(const wchar_t * __restrict fmt, va_list ap)
{
return vfwscanf(stdin, fmt, ap);
}
int
vwscanf_l(locale_t loc, const wchar_t * __restrict fmt, va_list ap)
{
return vfwscanf_l(stdin, loc, fmt, ap);
}

View File

@@ -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;
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: wscanf.c,v 1.2 2012/03/15 18:22:31 christos Exp $ */
/* $NetBSD: wscanf.c,v 1.3 2013/04/19 23:32:17 joerg Exp $ */
/*-
* Copyright (c) 2002 Tim J. Robbins
@@ -31,14 +31,18 @@
#if 0
__FBSDID("$FreeBSD: src/lib/libc/stdio/wscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $");
#else
__RCSID("$NetBSD: wscanf.c,v 1.2 2012/03/15 18:22:31 christos Exp $");
__RCSID("$NetBSD: wscanf.c,v 1.3 2013/04/19 23:32:17 joerg Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
__weak_alias(wscanf_l, _wscanf_l)
int
wscanf(const wchar_t * __restrict fmt, ...)
{
@@ -51,3 +55,16 @@ wscanf(const wchar_t * __restrict fmt, ...)
return r;
}
int
wscanf_l(locale_t loc, const wchar_t * __restrict fmt, ...)
{
va_list ap;
int r;
va_start(ap, fmt);
r = vfwscanf_l(stdin, loc, fmt, ap);
va_end(ap);
return r;
}