diff options
author | Stefan Sperling <stsp@cvs.openbsd.org> | 2010-07-27 16:59:05 +0000 |
---|---|---|
committer | Stefan Sperling <stsp@cvs.openbsd.org> | 2010-07-27 16:59:05 +0000 |
commit | ca2246f7206f312d3507d148d8fca7b5028c4088 (patch) | |
tree | ce30da3359d783bea6fe127d1b15a6d9b6a52b33 /distrib | |
parent | 357ef0a59acd38d0252d97a185411096ea76c5dd (diff) |
Replace the single-byte placeholders for the multi-byte/wide-character
conversion interfaces of libc (mbrtowc(3) and friends) with new
implementations that internally call an API based on NetBSD's citrus.
This allows us to support locales with multi-byte character encodings.
Provide two implementations of the citrus-based API: one based on the old
single-byte placeholders for use with our existing single-byte character
locales (C, ISO8859-*, KOI8, CP1251, etc.), and one that provides support
for UTF-8 encoded characters (code based on FreeBSD's implementation).
Install the en_US.UTF-8 ctype locale support file, and allow the UTF-8
ctype locale to be enabled via setlocale(3) (export LC_CTYPE='en_US.UTF-8').
A lot of programs, especially from ports, will now start using UTF-8 if the
UTF-8 locale is enabled. Use at your own risk, and please report any breakage.
Note that ncurses-based programs cannot display UTF-8 right now, this is being
worked on.
To prevent install media growth, add vfprintf(3) and mbrtowc(3) to libstubs.
The mbrtowc stub was copied unchanged from its old single-byte placeholder.
vfprintf.c doesn't need to be copied, just put in .PATH (hint by fgsch@).
Testing by myself, naddy, sthen, nicm, espie, armani, Dmitrij D. Czarkoff.
ok matthieu espie millert sthen nicm deraadt
Diffstat (limited to 'distrib')
-rw-r--r-- | distrib/special/libstubs/Makefile | 8 | ||||
-rw-r--r-- | distrib/special/libstubs/mbrtowc_sb.c | 64 |
2 files changed, 69 insertions, 3 deletions
diff --git a/distrib/special/libstubs/Makefile b/distrib/special/libstubs/Makefile index 3d26028398b..1be061efab6 100644 --- a/distrib/special/libstubs/Makefile +++ b/distrib/special/libstubs/Makefile @@ -1,20 +1,22 @@ -# $OpenBSD: Makefile,v 1.5 2009/11/18 07:43:22 guenther Exp $ +# $OpenBSD: Makefile,v 1.6 2010/07/27 16:59:03 stsp Exp $ .include <bsd.own.mk> LIB= stubs SRCS= db.c setlocale.c sha2.c getgrent.c getpwent.c \ - ethers.c getaddrinfo.c gethostnamadr.c getnetnamadr.c + ethers.c getaddrinfo.c gethostnamadr.c getnetnamadr.c \ + mbrtowc_sb.c vfprintf.c NOPIC= Yes NOPROFILE=Yes NOMAN= 1 CFLAGS+=-D__DBINTERFACE_PRIVATE -DSHA256_ONLY -UYP -I${LIBCSRCDIR}/include \ - -DNO_LOG_BAD_DNS_RESPONSES + -DNO_LOG_BAD_DNS_RESPONSES -I${LIBCSRCDIR}/locale -I${LIBCSRCDIR}/stdio LIBCSRCDIR=${.CURDIR}/../../../lib/libc .PATH: ${.CURDIR}/../../../lib/libc/hash .PATH: ${.CURDIR}/../../../lib/libc/gen .PATH: ${.CURDIR}/../../../lib/libc/net +.PATH: ${.CURDIR}/../../../lib/libc/stdio .include <bsd.lib.mk> diff --git a/distrib/special/libstubs/mbrtowc_sb.c b/distrib/special/libstubs/mbrtowc_sb.c new file mode 100644 index 00000000000..c31f541f6c8 --- /dev/null +++ b/distrib/special/libstubs/mbrtowc_sb.c @@ -0,0 +1,64 @@ +/* $OpenBSD: mbrtowc_sb.c,v 1.1 2010/07/27 16:59:03 stsp Exp $ */ +/* $NetBSD: multibyte_sb.c,v 1.4 2003/08/07 16:43:04 agc Exp $ */ + +/* + * Copyright (c) 1991 The Regents of the University of California. + * 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. 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 <errno.h> +#include <stdlib.h> +#include <wchar.h> + +/*ARGSUSED*/ +size_t +mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) +{ + + /* pwc may be NULL */ + /* s may be NULL */ + /* ps appears to be unused */ + + if (s == NULL) + return 0; + if (n == 0) + return (size_t)-2; + if (pwc) + *pwc = (wchar_t)(unsigned char)*s; + return (*s != '\0'); +} + +int +mbtowc(wchar_t *pwc, const char *s, size_t n) +{ + + /* pwc may be NULL */ + /* s may be NULL */ + + return mbrtowc(pwc, s, n, NULL); +} + |