am 01933d92
: Merge "Switch to OpenBSD stdio wide printf functions."
* commit '01933d921e9e2a36707dbb96dfc24073e8489912': Switch to OpenBSD stdio wide printf functions.
This commit is contained in:
commit
ff7dec44bd
@ -382,6 +382,7 @@ libc_upstream_openbsd_src_files := \
|
||||
upstream-openbsd/lib/libc/stdio/fvwrite.c \
|
||||
upstream-openbsd/lib/libc/stdio/fwalk.c \
|
||||
upstream-openbsd/lib/libc/stdio/fwide.c \
|
||||
upstream-openbsd/lib/libc/stdio/fwprintf.c \
|
||||
upstream-openbsd/lib/libc/stdio/fwscanf.c \
|
||||
upstream-openbsd/lib/libc/stdio/getc.c \
|
||||
upstream-openbsd/lib/libc/stdio/getchar.c \
|
||||
@ -407,6 +408,7 @@ libc_upstream_openbsd_src_files := \
|
||||
upstream-openbsd/lib/libc/stdio/setbuffer.c \
|
||||
upstream-openbsd/lib/libc/stdio/sscanf.c \
|
||||
upstream-openbsd/lib/libc/stdio/stdio.c \
|
||||
upstream-openbsd/lib/libc/stdio/swprintf.c \
|
||||
upstream-openbsd/lib/libc/stdio/swscanf.c \
|
||||
upstream-openbsd/lib/libc/stdio/tempnam.c \
|
||||
upstream-openbsd/lib/libc/stdio/tmpnam.c \
|
||||
@ -415,15 +417,19 @@ libc_upstream_openbsd_src_files := \
|
||||
upstream-openbsd/lib/libc/stdio/vasprintf.c \
|
||||
upstream-openbsd/lib/libc/stdio/vfprintf.c \
|
||||
upstream-openbsd/lib/libc/stdio/vfscanf.c \
|
||||
upstream-openbsd/lib/libc/stdio/vfwprintf.c \
|
||||
upstream-openbsd/lib/libc/stdio/vfwscanf.c \
|
||||
upstream-openbsd/lib/libc/stdio/vprintf.c \
|
||||
upstream-openbsd/lib/libc/stdio/vscanf.c \
|
||||
upstream-openbsd/lib/libc/stdio/vsnprintf.c \
|
||||
upstream-openbsd/lib/libc/stdio/vsprintf.c \
|
||||
upstream-openbsd/lib/libc/stdio/vsscanf.c \
|
||||
upstream-openbsd/lib/libc/stdio/vswprintf.c \
|
||||
upstream-openbsd/lib/libc/stdio/vswscanf.c \
|
||||
upstream-openbsd/lib/libc/stdio/vwprintf.c \
|
||||
upstream-openbsd/lib/libc/stdio/vwscanf.c \
|
||||
upstream-openbsd/lib/libc/stdio/wbuf.c \
|
||||
upstream-openbsd/lib/libc/stdio/wprintf.c \
|
||||
upstream-openbsd/lib/libc/stdio/wscanf.c \
|
||||
upstream-openbsd/lib/libc/stdlib/atoi.c \
|
||||
upstream-openbsd/lib/libc/stdlib/atol.c \
|
||||
|
@ -36,44 +36,6 @@
|
||||
|
||||
/* stubs for wide-char functions */
|
||||
|
||||
int fwprintf(FILE* stream, const wchar_t* format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int result = vfwprintf(stream, format, args);
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
int wprintf(const wchar_t* format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int result = vwprintf(format, args);
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
int swprintf(wchar_t* s, size_t n, const wchar_t* format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int result = vswprintf(s, n, format, args);
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
int vwprintf(const wchar_t* format, va_list arg) {
|
||||
return vfwprintf(stdout, format, arg);
|
||||
}
|
||||
|
||||
int vfwprintf(FILE* /*stream*/, const wchar_t* /*format*/, va_list /*arg*/) {
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int vswprintf(wchar_t* /*s*/, size_t /*n*/, const wchar_t* /*format*/, va_list /*arg*/) {
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int iswalnum(wint_t wc) { return isalnum(wc); }
|
||||
int iswalpha(wint_t wc) { return isalpha(wc); }
|
||||
int iswblank(wint_t wc) { return isblank(wc); }
|
||||
|
48
libc/upstream-openbsd/lib/libc/stdio/fwprintf.c
Normal file
48
libc/upstream-openbsd/lib/libc/stdio/fwprintf.c
Normal file
@ -0,0 +1,48 @@
|
||||
/* $OpenBSD: fwprintf.c,v 1.3 2011/04/28 17:38:46 stsp 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 <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
|
||||
int
|
||||
fwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
ret = vfwprintf(fp, fmt, ap);
|
||||
va_end(ap);
|
||||
return (ret);
|
||||
}
|
45
libc/upstream-openbsd/lib/libc/stdio/swprintf.c
Normal file
45
libc/upstream-openbsd/lib/libc/stdio/swprintf.c
Normal file
@ -0,0 +1,45 @@
|
||||
/* $OpenBSD: swprintf.c,v 1.5 2012/12/05 23:20:01 deraadt Exp $ */
|
||||
/* $NetBSD: swprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 Tim J. Robbins
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
|
||||
int
|
||||
swprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
ret = vswprintf(s, n, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return (ret);
|
||||
}
|
1526
libc/upstream-openbsd/lib/libc/stdio/vfwprintf.c
Normal file
1526
libc/upstream-openbsd/lib/libc/stdio/vfwprintf.c
Normal file
File diff suppressed because it is too large
Load Diff
96
libc/upstream-openbsd/lib/libc/stdio/vswprintf.c
Normal file
96
libc/upstream-openbsd/lib/libc/stdio/vswprintf.c
Normal file
@ -0,0 +1,96 @@
|
||||
/* $OpenBSD: vswprintf.c,v 1.4 2012/12/05 23:20:01 deraadt Exp $ */
|
||||
/* $NetBSD: vswprintf.c,v 1.1 2005/05/14 23:51:02 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 <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include <stdarg.h>
|
||||
#include "local.h"
|
||||
|
||||
int
|
||||
vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt,
|
||||
__va_list ap)
|
||||
{
|
||||
mbstate_t mbs;
|
||||
FILE f;
|
||||
char *mbp;
|
||||
int ret, sverrno;
|
||||
size_t nwc;
|
||||
struct __sfileext fext;
|
||||
|
||||
if (n == 0) {
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
_FILEEXT_SETUP(&f, &fext);
|
||||
f._file = -1;
|
||||
f._flags = __SWR | __SSTR | __SALC;
|
||||
f._bf._base = f._p = (unsigned char *)malloc(128);
|
||||
if (f._bf._base == NULL) {
|
||||
errno = ENOMEM;
|
||||
return (-1);
|
||||
}
|
||||
f._bf._size = f._w = 127; /* Leave room for the NUL */
|
||||
ret = __vfwprintf(&f, fmt, ap);
|
||||
if (ret < 0) {
|
||||
sverrno = errno;
|
||||
free(f._bf._base);
|
||||
errno = sverrno;
|
||||
return (-1);
|
||||
}
|
||||
if (ret == 0) {
|
||||
s[0] = L'\0';
|
||||
free(f._bf._base);
|
||||
return (0);
|
||||
}
|
||||
*f._p = '\0';
|
||||
mbp = (char *)f._bf._base;
|
||||
/*
|
||||
* XXX Undo the conversion from wide characters to multibyte that
|
||||
* fputwc() did in __vfwprintf().
|
||||
*/
|
||||
bzero(&mbs, sizeof(mbs));
|
||||
nwc = mbsrtowcs(s, (const char **)&mbp, n, &mbs);
|
||||
free(f._bf._base);
|
||||
if (nwc == (size_t)-1) {
|
||||
errno = EILSEQ;
|
||||
return (-1);
|
||||
}
|
||||
if (nwc == n) {
|
||||
s[n - 1] = L'\0';
|
||||
errno = EOVERFLOW;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (ret);
|
||||
}
|
42
libc/upstream-openbsd/lib/libc/stdio/vwprintf.c
Normal file
42
libc/upstream-openbsd/lib/libc/stdio/vwprintf.c
Normal file
@ -0,0 +1,42 @@
|
||||
/* $OpenBSD: vwprintf.c,v 1.3 2011/04/28 17:38:46 stsp 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 <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
|
||||
int
|
||||
vwprintf(const wchar_t * __restrict fmt, __va_list ap)
|
||||
{
|
||||
return (vfwprintf(stdout, fmt, ap));
|
||||
}
|
48
libc/upstream-openbsd/lib/libc/stdio/wprintf.c
Normal file
48
libc/upstream-openbsd/lib/libc/stdio/wprintf.c
Normal file
@ -0,0 +1,48 @@
|
||||
/* $OpenBSD: wprintf.c,v 1.3 2011/04/28 17:38:46 stsp 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 <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
|
||||
int
|
||||
wprintf(const wchar_t * __restrict fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
ret = vfwprintf(stdout, fmt, ap);
|
||||
va_end(ap);
|
||||
return (ret);
|
||||
}
|
Loading…
Reference in New Issue
Block a user