Sun Jan 4 17:02:20 2009 UTC ()
merge with head.


(christos)
diff -r1.204 -r1.204.6.1 src/lib/libc/shlib_version
diff -r1.3 -r0 src/lib/libc/arch/mips/gen/sf_modf.c
diff -r1.7 -r1.7.8.1 src/lib/libc/arch/sparc64/sys/__sigaction14_sigtramp.c
diff -r1.5 -r1.5.34.1 src/lib/libc/citrus/Makefile.inc
diff -r0 -r1.1.2.2 src/lib/libc/citrus/citrus_aliasname_local.h
diff -r0 -r1.1.2.2 src/lib/libc/citrus/citrus_bcs_strtol.c
diff -r0 -r1.1.2.2 src/lib/libc/citrus/citrus_bcs_strtoul.c
diff -r0 -r1.1.2.2 src/lib/libc/citrus/citrus_fix_grouping.h
diff -r0 -r1.1.2.2 src/lib/libc/citrus/citrus_lc_ctype.c
diff -r0 -r1.1.2.2 src/lib/libc/citrus/citrus_lc_messages.c
diff -r0 -r1.1.2.2 src/lib/libc/citrus/citrus_lc_messages.h
diff -r0 -r1.1.2.2 src/lib/libc/citrus/citrus_lc_monetary.c
diff -r0 -r1.1.2.2 src/lib/libc/citrus/citrus_lc_monetary.h
diff -r0 -r1.1.2.2 src/lib/libc/citrus/citrus_lc_numeric.c
diff -r0 -r1.1.2.2 src/lib/libc/citrus/citrus_lc_numeric.h
diff -r0 -r1.1.2.2 src/lib/libc/citrus/citrus_lc_template.h
diff -r0 -r1.1.2.2 src/lib/libc/citrus/citrus_lc_template_decl.h
diff -r0 -r1.1.2.2 src/lib/libc/citrus/citrus_lc_time.c
diff -r0 -r1.1.2.2 src/lib/libc/citrus/citrus_lc_time.h
diff -r1.4 -r1.4.12.1 src/lib/libc/citrus/citrus_bcs.h
diff -r1.8 -r1.8.12.1 src/lib/libc/citrus/citrus_csmapper.c
diff -r1.7 -r1.7.6.1 src/lib/libc/citrus/citrus_module.c
diff -r1.6 -r1.6.28.1 src/lib/libc/citrus/citrus_namespace.h
diff -r1.12 -r1.12.6.1 src/lib/libc/citrus/modules/citrus_euc.c
diff -r1.163 -r1.163.6.1 src/lib/libc/gen/Makefile.inc
diff -r1.26 -r1.26.28.1 src/lib/libc/gen/directory.3
diff -r1.34 -r1.34.6.1 src/lib/libc/gen/fts.c
diff -r1.16 -r1.16.40.1 src/lib/libc/gen/isctype.c
diff -r1.33 -r1.33.12.1 src/lib/libc/gen/opendir.c
diff -r1.18 -r1.18.28.1 src/lib/libc/gen/setmode.3
diff -r1.194 -r1.194.6.1 src/lib/libc/gen/sysctl.3
diff -r1.45.2.1 -r1.45.2.2 src/lib/libc/gen/syslog.c
diff -r1.9 -r1.9.40.1 src/lib/libc/gen/tolower_.c
diff -r1.9 -r1.9.40.1 src/lib/libc/gen/toupper_.c
diff -r1.2 -r1.2.40.1 src/lib/libc/iconv/Makefile.inc
diff -r1.6 -r1.6.26.1 src/lib/libc/iconv/iconv.c
diff -r1.134.2.4 -r1.134.2.5 src/lib/libc/include/namespace.h
diff -r1.52 -r1.52.6.1 src/lib/libc/locale/Makefile.inc
diff -r1.10 -r0 src/lib/libc/locale/___runetype_mb.c
diff -r1.6 -r1.6.34.1 src/lib/libc/locale/_wctrans.c
diff -r1.2 -r1.2.40.1 src/lib/libc/locale/_wctrans_local.h
diff -r0 -r1.1.2.2 src/lib/libc/locale/_wctype.c
diff -r0 -r1.1.2.2 src/lib/libc/locale/_wctype_local.h
diff -r0 -r1.1.2.2 src/lib/libc/locale/bsdctype.c
diff -r0 -r1.1.2.2 src/lib/libc/locale/bsdctype.h
diff -r0 -r1.1.2.2 src/lib/libc/locale/current_locale.c
diff -r0 -r1.1.2.2 src/lib/libc/locale/dummy_lc_collate.c
diff -r0 -r1.1.2.2 src/lib/libc/locale/dummy_lc_template.h
diff -r0 -r1.1.2.2 src/lib/libc/locale/fix_grouping.c
diff -r0 -r1.1.2.2 src/lib/libc/locale/fix_grouping.h
diff -r0 -r1.1.2.2 src/lib/libc/locale/generic_lc_all.c
diff -r0 -r1.1.2.2 src/lib/libc/locale/generic_lc_template.h
diff -r0 -r1.1.2.2 src/lib/libc/locale/generic_lc_template_decl.h
diff -r0 -r1.1.2.2 src/lib/libc/locale/global_locale.c
diff -r0 -r1.1.2.2 src/lib/libc/locale/iswctype_mb.c
diff -r0 -r1.1.2.2 src/lib/libc/locale/localeio_lc_ctype.c
diff -r0 -r1.1.2.2 src/lib/libc/locale/localeio_lc_messages.c
diff -r0 -r1.1.2.2 src/lib/libc/locale/localeio_lc_monetary.c
diff -r0 -r1.1.2.2 src/lib/libc/locale/localeio_lc_numeric.c
diff -r0 -r1.1.2.2 src/lib/libc/locale/localeio_lc_time.c
diff -r0 -r1.1.2.2 src/lib/libc/locale/nb_lc_messages_misc.h
diff -r0 -r1.1.2.2 src/lib/libc/locale/nb_lc_monetary_misc.h
diff -r0 -r1.1.2.2 src/lib/libc/locale/nb_lc_numeric_misc.h
diff -r0 -r1.1.2.2 src/lib/libc/locale/nb_lc_template.h
diff -r0 -r1.1.2.2 src/lib/libc/locale/nb_lc_template_decl.h
diff -r0 -r1.1.2.2 src/lib/libc/locale/nb_lc_time_misc.h
diff -r0 -r1.1.2.2 src/lib/libc/locale/setlocale_local.h
diff -r1.2 -r1.2.34.1 src/lib/libc/locale/aliasname.c
diff -r1.1 -r1.1.44.1 src/lib/libc/locale/aliasname_local.h
diff -r1.7 -r1.7.28.1 src/lib/libc/locale/ctypeio.c
diff -r1.1 -r1.1.56.1 src/lib/libc/locale/ctypeio.h
diff -r1.16 -r0 src/lib/libc/locale/iswctype.c
diff -r1.5 -r1.5.6.1 src/lib/libc/locale/iswctype_sb.c
diff -r1.1 -r0 src/lib/libc/locale/lcmessages.c
diff -r1.1 -r0 src/lib/libc/locale/lcmessages.h
diff -r1.1 -r0 src/lib/libc/locale/lcmonetary.c
diff -r1.1 -r0 src/lib/libc/locale/lcmonetary.h
diff -r1.1 -r0 src/lib/libc/locale/lcnumeric.c
diff -r1.1 -r0 src/lib/libc/locale/lcnumeric.h
diff -r1.1 -r0 src/lib/libc/locale/lctime.c
diff -r1.1 -r0 src/lib/libc/locale/lctime.h
diff -r1.14 -r1.14.20.1 src/lib/libc/locale/localeconv.c
diff -r1.1 -r1.1.10.1 src/lib/libc/locale/localeio.c
diff -r1.1 -r1.1.10.1 src/lib/libc/locale/localeio.h
diff -r1.3 -r1.3.40.1 src/lib/libc/locale/multibyte.h
diff -r1.5 -r1.5.40.1 src/lib/libc/locale/multibyte_amd1.c
diff -r1.4 -r1.4.40.1 src/lib/libc/locale/multibyte_c90.c
diff -r1.11 -r1.11.28.1 src/lib/libc/locale/nl_langinfo.c
diff -r1.30 -r1.30.14.1 src/lib/libc/locale/rune.c
diff -r1.12 -r1.12.14.1 src/lib/libc/locale/rune.h
diff -r1.10 -r1.10.10.1 src/lib/libc/locale/rune_local.h
diff -r1.13 -r1.13.2.1 src/lib/libc/locale/runeglue.c
diff -r1.17 -r1.17.6.1 src/lib/libc/locale/runetable.c
diff -r1.54 -r1.54.6.1 src/lib/libc/locale/setlocale.c
diff -r1.18 -r0 src/lib/libc/locale/setrunelocale.c
diff -r1.8 -r1.8.62.1 src/lib/libc/nls/Makefile.inc
diff -r1.25 -r1.25.8.1 src/lib/libc/nls/catopen.c
diff -r1.7 -r1.7.8.1 src/lib/libc/resolv/res_state.c
diff -r1.11 -r1.11.40.1 src/lib/libc/rpc/rpc_soc.3
diff -r1.12 -r1.12.40.1 src/lib/libc/stdio/fread.3
diff -r1.44 -r1.44.20.1 src/lib/libc/stdio/printf.3
diff -r1.3 -r1.3.6.1 src/lib/libc/stdio/vfwscanf.c
diff -r1.3 -r1.3.28.1 src/lib/libc/stdio/vswscanf.c
diff -r1.2 -r1.2.28.1 src/lib/libc/stdio/wprintf.3
diff -r1.16 -r0 src/lib/libc/stdlib/heapsort.c
diff -r1.15 -r1.15.10.1 src/lib/libc/stdlib/qsort.c
diff -r1.67 -r1.67.20.1 src/lib/libc/string/Makefile.inc
diff -r1.5 -r1.5.40.1 src/lib/libc/string/wcscmp.c
diff -r1.5 -r1.5.40.1 src/lib/libc/string/wcsncmp.c
diff -r1.5 -r0 src/lib/libc/string/wcswidth.c
diff -r1.3 -r1.3.40.1 src/lib/libc/string/wmemcmp.c
diff -r1.33 -r1.33.6.1 src/lib/libc/sys/chmod.2
diff -r1.19 -r1.19.12.1 src/lib/libc/sys/dup.2
diff -r1.49 -r1.49.12.1 src/lib/libc/sys/intro.2
diff -r1.12 -r1.12.34.1 src/lib/libc/sys/undelete.2

cvs diff -r1.204 -r1.204.6.1 src/lib/libc/shlib_version (expand / switch to unified diff)

--- src/lib/libc/shlib_version 2008/08/04 21:29:27 1.204
+++ src/lib/libc/shlib_version 2008/08/04 21:29:27 1.204.6.1
@@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
1# $NetBSD: shlib_version,v 1.204 2008/08/04 21:29:27 matt Exp $ 
2# Remember to update distrib/sets/lists/base/shl.* when changing 
3# 
4# things we wish to do on next major version bump: 
5# - libc/net/rcmd.c: make __ivaliduser() and __ivaliduser_sa() static 
6# - libc/net: resolver update to BIND8/9? 
7# - md2, md4, md5, rmd160 & sha1 functions should take the same arguments AFAP 
8# - libc/gen/assert.c: __{diag,}assert13() -> __{diag,}assert() 
9# - libc/gen/times.c: remove; __times13() -> times() 
10# - libc/gen/timezone.c: remove; __timezone13 -> timezone 
11# - libc/net/getaddrinfo.c, netdb.h: remove __ai_pad0 
12# - libc/gen/utmpx.c, utmpx.h: remove lastlogxname, __getlastlogx13 -> getlastlogx 
13# - infinity{,f,l}.c, math.h: __infinity -> __huge_val 
14# - libc/gen/is{inf,nan}d_ieee754.c: remove is{inf,nan} aliases 
15# - libc/arch/vax/gen/is{inf,nan}.c: remove 
16# - libc/db/hash/ndbm.c: remove; __ndbm13 -> ndbm 
17# - libc/net/getnet{ent,namadr}.c, netdb.h: remove __n_pad0 
18# - libc/stdio: make _file an int, hide struct FILE, stdin, stdout, stderr impls 
19# - libc/stdio: make fpos_t larger. see BUGS section in fgetpos(3). 
20# probably s/fpos_t/off_t/ in __sFILE and __sseek(). it involves 
21# funopen(3) api change. 
22# - libc/locale/{__mb_cur_max.c,rune.h}: remove __mb_len_max_runtime 
23# - libc/locale/setlocale.c: __setlocale -> setlocale 
24# - libc/locale/setlocale{1,32}.c: remove 
25# - libc/locale/setrunelocale.c: __MB_LEN_MAX_RUNTIME -> MB_LEN_MAX 
26# - remove frexp, ldexp, modf: they belong to libm. 
27# - make sure we can support thread local [on arm don't use r9 for example] 
28major=12 
29minor=163 

File Deleted: src/lib/libc/arch/mips/gen/Attic/sf_modf.c

cvs diff -r1.7 -r1.7.8.1 src/lib/libc/arch/sparc64/sys/Attic/__sigaction14_sigtramp.c (expand / switch to unified diff)

--- src/lib/libc/arch/sparc64/sys/Attic/__sigaction14_sigtramp.c 2008/04/28 20:22:57 1.7
+++ src/lib/libc/arch/sparc64/sys/Attic/__sigaction14_sigtramp.c 2008/04/28 20:22:57 1.7.8.1
@@ -1,74 +0,0 @@ @@ -1,74 +0,0 @@
1/* $NetBSD: __sigaction14_sigtramp.c,v 1.7 2008/04/28 20:22:57 martin Exp $ */ 
2 
3/*- 
4 * Copyright (c) 2002 The NetBSD Foundation, Inc. 
5 * All rights reserved. 
6 * 
7 * This code is derived from software contributed to The NetBSD Foundation 
8 * by Jason R. Thorpe. 
9 * 
10 * Redistribution and use in source and binary forms, with or without 
11 * modification, are permitted provided that the following conditions 
12 * are met: 
13 * 1. Redistributions of source code must retain the above copyright 
14 * notice, this list of conditions and the following disclaimer. 
15 * 2. Redistributions in binary form must reproduce the above copyright 
16 * notice, this list of conditions and the following disclaimer in the 
17 * documentation and/or other materials provided with the distribution. 
18 * 
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
29 * POSSIBILITY OF SUCH DAMAGE. 
30 */ 
31 
32#include <sys/cdefs.h> 
33#if defined(LIBC_SCCS) && !defined(lint) 
34__RCSID("$NetBSD: __sigaction14_sigtramp.c,v 1.7 2008/04/28 20:22:57 martin Exp $"); 
35#endif /* LIBC_SCCS and not lint */ 
36 
37#define __LIBC12_SOURCE__ 
38 
39#include <sys/types.h> 
40#include <signal.h> 
41#include <errno.h> 
42 
43#include "extern.h" 
44 
45__weak_alias(__sigaction14, __libc_sigaction14) 
46 
47int 
48__libc_sigaction14(int sig, const struct sigaction *act, struct sigaction *oact) 
49{ 
50 extern void __sigtramp_siginfo_2(void); 
51 
52#ifdef __LIBC12_SOURCE__ 
53 /* 
54 * We select the compatibility SIGCONTEXT trampoline if SA_SIGINFO 
55 * is not set in the sigaction. 
56 */ 
57 if (act && (act->sa_flags & SA_SIGINFO) == 0) { 
58 extern void __sigtramp_sigcontext_1(void); 
59 int sav = errno; 
60 int rv = __sigaction_sigtramp(sig, act, oact, 
61 __sigtramp_sigcontext_1, 1); 
62 /* 
63 * EINVAL might indicate that trampoline version 1 is 
64 * not supported by the kernel; fall back on native 
65 * SIGINFO trampoline. 
66 */ 
67 if (rv >= 0 || errno != EINVAL) 
68 return rv; 
69 errno = sav; 
70 } 
71#endif 
72 
73 return __sigaction_sigtramp(sig, act, oact, __sigtramp_siginfo_2, 2); 
74} 

cvs diff -r1.5 -r1.5.34.1 src/lib/libc/citrus/Makefile.inc (expand / switch to unified diff)

--- src/lib/libc/citrus/Makefile.inc 2004/07/21 20:27:46 1.5
+++ src/lib/libc/citrus/Makefile.inc 2009/01/04 17:02:18 1.5.34.1
@@ -1,18 +1,29 @@ @@ -1,18 +1,29 @@
1# $NetBSD: Makefile.inc,v 1.5 2004/07/21 20:27:46 tshiozak Exp $ 1# $NetBSD: Makefile.inc,v 1.5.34.1 2009/01/04 17:02:18 christos Exp $
2 2
3# sources 3# sources
4.PATH: ${ARCHDIR}/citrus ${.CURDIR}/citrus 4.PATH: ${ARCHDIR}/citrus ${.CURDIR}/citrus
5 5
6CITRUS?= yes 6CITRUS?= yes
7 7
8.if ${CITRUS} == "yes" 8.if ${CITRUS} == "yes"
9MODULE_SHLIB_MAJOR!= . ${NETBSDSRCDIR}/lib/i18n_module/shlib_version ; echo $$major 9MODULE_SHLIB_MAJOR!= . ${NETBSDSRCDIR}/lib/i18n_module/shlib_version ; echo $$major
10CPPFLAGS+= -DI18NMODULE_MAJOR=${MODULE_SHLIB_MAJOR} -DCITRUS 10CPPFLAGS.citrus_module.c+=-DI18NMODULE_MAJOR=${MODULE_SHLIB_MAJOR}
11 11SRCS+= citrus_bcs.c citrus_bcs_strtol.c citrus_bcs_strtoul.c \
12SRCS+= citrus_bcs.c citrus_csmapper.c citrus_ctype.c citrus_ctype_fallback.c \ 12 citrus_csmapper.c citrus_ctype.c citrus_ctype_fallback.c \
13 citrus_db.c citrus_db_hash.c citrus_esdb.c citrus_hash.c \ 13 citrus_db.c citrus_db_hash.c citrus_esdb.c citrus_hash.c \
14 citrus_iconv.c citrus_lookup.c \ 14 citrus_iconv.c citrus_lookup.c \
15 citrus_mapper.c citrus_memstream.c citrus_mmap.c citrus_module.c \ 15 citrus_mapper.c citrus_memstream.c citrus_mmap.c citrus_module.c \
16 citrus_none.c citrus_stdenc.c 16 citrus_none.c citrus_stdenc.c
17 17SRCS+= citrus_lc_ctype.c \
 18 citrus_lc_monetary.c \
 19 citrus_lc_numeric.c \
 20 citrus_lc_time.c \
 21 citrus_lc_messages.c
 22CPPFLAGS.citrus_bcs_strtol.c+= -I${LIBCDIR}/../../common/lib/libc/stdlib
 23CPPFLAGS.citrus_bcs_strtoul.c+= -I${LIBCDIR}/../../common/lib/libc/stdlib
 24CPPFLAGS.citrus_lc_ctype.c+= -I${LIBCDIR}/locale
 25CPPFLAGS.citrus_lc_monetary.c+= -I${LIBCDIR}/locale
 26CPPFLAGS.citrus_lc_numeric.c+= -I${LIBCDIR}/locale
 27CPPFLAGS.citrus_lc_time.c+= -I${LIBCDIR}/locale
 28CPPFLAGS.citrus_lc_messages.c+= -I${LIBCDIR}/locale
18.endif 29.endif

File Added: src/lib/libc/citrus/citrus_aliasname_local.h
/* $NetBSD: citrus_aliasname_local.h,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _CITRUS_ALIASNAME_LOCAL_H_
#define _CITRUS_ALIASNAME_LOCAL_H_

static __inline const char *
__unaliasname(const char *dbname, const char *alias,
    void *buf, size_t bufsize)
{
	return _lookup_simple(dbname, alias,
	    buf, bufsize, _LOOKUP_CASE_SENSITIVE);
}

static __inline int
__isforcemapping(const char *name)
{
	_DIAGASSERT(name != NULL);

	return _bcs_strcasecmp("/force", name);
}

#endif /*_CITRUS_ALIASNAME_LOCAL_H_*/

File Added: src/lib/libc/citrus/citrus_bcs_strtol.c
/* $NetBSD: citrus_bcs_strtol.c,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $ */

/*-
 * Copyright (c) 2005 The DragonFly Project.  All rights reserved.
 * Copyright (c) 2003, 2008 Citrus Project,
 * 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 <sys/cdefs.h>
__RCSID("$NetBSD: citrus_bcs_strtol.c,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $");

#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>

#include "citrus_namespace.h"
#include "citrus_bcs.h"

#define	_FUNCNAME	_bcs_strtol
#define	__INT		long int
#define	__INT_MIN	LONG_MIN
#define	__INT_MAX	LONG_MAX

#undef isspace
#define isspace(c)	_bcs_isspace(c)

#undef isdigit
#define isdigit(c)	_bcs_isdigit(c)

#undef isalpha
#define isalpha(c)	_bcs_isalpha(c)

#undef isupper
#define isupper(c)	_bcs_isupper(c)

#include "_strtol.h"

File Added: src/lib/libc/citrus/citrus_bcs_strtoul.c
/* $NetBSD: citrus_bcs_strtoul.c,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $ */

/*-
 * Copyright (c) 2005 The DragonFly Project.  All rights reserved.
 * Copyright (c) 2003, 2008 Citrus Project,
 * 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 <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: citrus_bcs_strtoul.c,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $");
#endif /* not lint */

#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif

#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>

#include "citrus_namespace.h"
#include "citrus_bcs.h"

#define	_FUNCNAME	_bcs_strtoul
#define	__UINT		unsigned long int
#define	__UINT_MAX	ULONG_MAX

#undef isspace
#define isspace(c)	_bcs_isspace(c)

#undef isdigit
#define isdigit(c)	_bcs_isdigit(c)

#undef isalpha
#define isalpha(c)	_bcs_isalpha(c)

#undef isupper
#define isupper(c)	_bcs_isupper(c)

#include "_strtoul.h"

File Added: src/lib/libc/citrus/citrus_fix_grouping.h
/* $NetBSD: citrus_fix_grouping.h,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _CITRUS_FIX_GROUPING_H_
#define _CITRUS_FIX_GROUPING_H_

#define _CITRUS_LC_GROUPING_VALUE_MIN		0
#define _CITRUS_LC_GROUPING_VALUE_MAX		126
#define _CITRUS_LC_GROUPING_VALUE_NO_FUTHER	127

#if CHAR_MAX != _CITRUS_LC_GROUPING_VALUE_NO_FUTHER
static __inline void
_citrus_fixup_char_max_md(char *grouping)
{
	char *p;

	_DIAGASSERT(grouping != NULL);

	for (p = grouping; *p != '\0'; ++p) {
		if (*p == _CITRUS_LC_GROUPING_VALUE_NO_FUTHER)
			*p = (char)CHAR_MAX;
	}
}
#define _CITRUS_FIXUP_CHAR_MAX_MD(grouping) \
    _citrus_fixup_char_max_md(__UNCONST(grouping))
#else
#define _CITRUS_FIXUP_CHAR_MAX_MD(grouping)	/* nothing to do */
#endif

#endif /*_CITRUS_FIX_GROUPING_H_*/

File Added: src/lib/libc/citrus/citrus_lc_ctype.c
/* $NetBSD: citrus_lc_ctype.c,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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 <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: citrus_lc_ctype.c,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include "reentrant.h"
#include <sys/types.h>
#include <sys/queue.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <langinfo.h>
#include <limits.h>
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>

#include "setlocale_local.h"

#include "citrus_namespace.h"
#include "citrus_bcs.h"
#include "citrus_region.h"
#include "citrus_lookup.h"
#include "citrus_aliasname_local.h"
#include "citrus_module.h"
#include "citrus_ctype.h"

#include "rune.h"
#include "rune_local.h"
#include "multibyte.h"

/*
 * macro required by all template headers
 */
#define _PREFIX(name)		__CONCAT(_citrus_LC_CTYPE_, name)

/*
 * macro required by nb_lc_template(_decl).h
 */
#define _CATEGORY_TYPE          _RuneLocale

#include "nb_lc_template_decl.h"

static int
_citrus_LC_CTYPE_create_impl(const char * __restrict root,
    const char * __restrict name, _RuneLocale ** __restrict pdata)
{
	char path[PATH_MAX + 1];
	FILE *fp;
	_RuneLocale *data;
	int ret;

	_DIAGASSERT(root != NULL);
	_DIAGASSERT(name != NULL);
	_DIAGASSERT(pdata != NULL);

	snprintf(path, sizeof(path),
	    "%s/%s/LC_CTYPE", root, name);
	fp = fopen(path, "r");
	if (fp == NULL)
		return ENOENT;
	data = _Read_RuneMagi(fp);
	if (data == NULL) {
		data = _Read_CTypeAsRune(fp);
		if (data == NULL) {
			fclose(fp);
			return EFTYPE;
		}
	}
	fclose(fp);
	ret = _citrus_ctype_open(&data->rl_citrus_ctype, data->rl_encoding,
	   data->rl_variable, data->rl_variable_len, _PRIVSIZE);
	if (!ret)
		ret = __runetable_to_netbsd_ctype(data);
	if (ret || __MB_LEN_MAX_RUNTIME <
	    _citrus_ctype_get_mb_cur_max(data->rl_citrus_ctype)) {
		_NukeRune(data);
		return EINVAL;
	}
	*pdata = data;
	return 0;
}

static __inline void
_PREFIX(build_cache)(struct _locale_cache_t * __restrict cache,
    _RuneLocale * __restrict data)
{
	_DIAGASSERT(cache != NULL);
	_DIAGASSERT(data != NULL);

	cache->ctype_tab = data->rl_ctype_tab;
	cache->tolower_tab = data->rl_tolower_tab;
	cache->toupper_tab = data->rl_toupper_tab;
	cache->mb_cur_max = _citrus_ctype_get_mb_cur_max(data->rl_citrus_ctype);
	cache->items[(size_t)CODESET] = data->rl_codeset;
}

static __inline void
_PREFIX(fixup)(_RuneLocale *data)
{
	_DIAGASSERT(data != NULL);

	__mb_cur_max = _citrus_ctype_get_mb_cur_max(data->rl_citrus_ctype);
	_ctype_ = data->rl_ctype_tab;
	_tolower_tab_ = data->rl_tolower_tab;
	_toupper_tab_ = data->rl_toupper_tab;
	_CurrentRuneLocale = data;
}

/*
 * macro required by nb_lc_template.h
 */
#define _CATEGORY_ID		LC_CTYPE
#define _CATEGORY_NAME		"LC_CTYPE"
#define _CATEGORY_DEFAULT	_DefaultRuneLocale

#include "nb_lc_template.h"
_LOCALE_CATEGORY_ENTRY(_citrus_LC_CTYPE_);

File Added: src/lib/libc/citrus/citrus_lc_messages.c
/* $NetBSD: citrus_lc_messages.c,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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 <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: citrus_lc_messages.c,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include "namespace.h"
#include "reentrant.h"
#include <sys/types.h>
#include <sys/localedef.h>
#include <sys/queue.h>
#include <assert.h>
#include <errno.h>
#include <langinfo.h>
#include <limits.h>
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "setlocale_local.h"

#include "citrus_namespace.h"
#include "citrus_types.h"
#include "citrus_bcs.h"
#include "citrus_region.h"
#include "citrus_lookup.h"
#include "citrus_aliasname_local.h"
#include "citrus_module.h"
#include "citrus_mmap.h"
#include "citrus_hash.h"
#include "citrus_db.h"
#include "citrus_db_hash.h"
#include "citrus_memstream.h"
#include "rune.h"

/*
 * macro required by all template headers
 */
#define _PREFIX(name)		__CONCAT(_citrus_LC_MESSAGES_, name)

#include "nb_lc_messages_misc.h"
#include "citrus_lc_template_decl.h"

static __inline void
_citrus_LC_MESSAGES_uninit(_MessagesLocale *data)
{
	free(__UNCONST(data->yesexpr));
	free(__UNCONST(data->noexpr));
	free(__UNCONST(data->yesstr));
	free(__UNCONST(data->nostr));
}

#include "citrus_lc_messages.h"

struct _citrus_LC_MESSAGES_key {
	const char *name;
	size_t offset;
};

#define OFFSET(field) (offsetof(_MessagesLocale, field))
static const struct _citrus_LC_MESSAGES_key keys[] = {
  { _CITRUS_LC_MESSAGES_SYM_YESEXPR, OFFSET(yesexpr) },
  { _CITRUS_LC_MESSAGES_SYM_NOEXPR,  OFFSET(noexpr ) },
  { _CITRUS_LC_MESSAGES_SYM_YESSTR,  OFFSET(yesstr ) },
  { _CITRUS_LC_MESSAGES_SYM_NOSTR,   OFFSET(nostr  ) },
  { NULL, 0 }
};

static __inline int
_citrus_LC_MESSAGES_init_normal(_MessagesLocale * __restrict data,
    struct _citrus_db * __restrict db)
{
	const struct _citrus_LC_MESSAGES_key *key;
	char **p;
	const char *s;

	_DIAGASSERT(data != NULL);
	_DIAGASSERT(db != NULL);

	memset(data, 0, sizeof(*data));
	for (key = &keys[0]; key->name != NULL; ++key) {
		if (_db_lookupstr_by_s(db, key->name, &s, NULL))
			goto fatal;
		p = (char **)(void *)
		    (((char *)(void *)data) + key->offset);
		*p = strdup(s);
		if (*p == NULL)
			goto fatal;
	}
	return 0;

fatal:
	_citrus_LC_MESSAGES_uninit(data);
	return EFTYPE;
}

static __inline int
_citrus_LC_MESSAGES_init_fallback(_MessagesLocale * __restrict data,
    struct _memstream * __restrict ms)
{
	const struct _citrus_LC_MESSAGES_key *key;
	char **p;
	const char *s;
	size_t n;

	_DIAGASSERT(data != NULL);
	_DIAGASSERT(ms != NULL);

	memset(data, 0, sizeof(*data));
	for (key = &keys[0]; key->name != NULL; ++key) {
		if ((s = _memstream_getln(ms, &n)) == NULL)
			goto fatal;
		p = (char **)(void *)
		    (((char *)(void *)data) + key->offset);
		*p = strndup(s, n - 1);
		if (*p == NULL)
			goto fatal;
	}
	return 0;

fatal:
	_citrus_LC_MESSAGES_uninit(data);
	return EFTYPE;
}

/*
 * macro required by citrus_lc_template.h
 */
#define _CATEGORY_DB		"LC_MESSAGES/SYS_LC_MESSAGES"
#define _CATEGORY_MAGIC		_CITRUS_LC_MESSAGES_MAGIC_1

#include "citrus_lc_template.h"
_LOCALE_CATEGORY_ENTRY(_citrus_LC_MESSAGES_);

File Added: src/lib/libc/citrus/citrus_lc_messages.h
/* $NetBSD: citrus_lc_messages.h,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _CITRUS_LC_MESSAGES_H_
#define _CITRUS_LC_MESSAGES_H_

/*
 *
 */
#define _CITRUS_LC_MESSAGES_MAGIC_1		"CtrsME10"
#define _CITRUS_LC_MESSAGES_SYM_VERSION		"version"
#define _CITRUS_LC_MESSAGES_VERSION		0x00000001

/*
 *
 */
#define _CITRUS_LC_MESSAGES_SYM_YESEXPR			"yesexpr"
#define _CITRUS_LC_MESSAGES_SYM_NOEXPR			"noexpr"
#define _CITRUS_LC_MESSAGES_SYM_YESSTR			"yesstr"
#define _CITRUS_LC_MESSAGES_SYM_NOSTR			"nostr"

#endif /*_CITRUS_LC_MESSAGES_H_*/

File Added: src/lib/libc/citrus/citrus_lc_monetary.c
/* $NetBSD: citrus_lc_monetary.c,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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 <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: citrus_lc_monetary.c,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include "namespace.h"
#include "reentrant.h"
#include <sys/types.h>
#include <sys/localedef.h>
#include <sys/queue.h>
#include <assert.h>
#include <errno.h>
#include <langinfo.h>
#include <limits.h>
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "setlocale_local.h"

#include "citrus_namespace.h"
#include "citrus_types.h"
#include "citrus_bcs.h"
#include "citrus_region.h"
#include "citrus_lookup.h"
#include "citrus_aliasname_local.h"
#include "citrus_module.h"
#include "citrus_mmap.h"
#include "citrus_hash.h"
#include "citrus_db.h"
#include "citrus_db_hash.h"
#include "citrus_memstream.h"
#include "rune.h"

#include "fix_grouping.h"
#include "citrus_fix_grouping.h"

/*
 * macro required by all template headers
 */
#define _PREFIX(name)		__CONCAT(_citrus_LC_MONETARY_, name)

#include "nb_lc_monetary_misc.h"
#include "citrus_lc_template_decl.h"

static __inline void
_citrus_LC_MONETARY_uninit(_MonetaryLocale *data)
{
	_DIAGASSERT(data != NULL);

	free(__UNCONST(data->int_curr_symbol));
	free(__UNCONST(data->currency_symbol));
	free(__UNCONST(data->mon_decimal_point));
	free(__UNCONST(data->mon_thousands_sep));
	free(__UNCONST(data->mon_grouping));
	free(__UNCONST(data->positive_sign));
	free(__UNCONST(data->negative_sign));
}

#include "citrus_lc_monetary.h"

struct _citrus_LC_MONETARY_key {
	const char *name;
	size_t offset;
};

#define OFFSET(field) (offsetof(_MonetaryLocale, field))
static const struct _citrus_LC_MONETARY_key keys_string[] = {
  { _CITRUS_LC_MONETARY_SYM_INT_CURR_SYMBOL,    OFFSET(int_curr_symbol   ) },
  { _CITRUS_LC_MONETARY_SYM_CURRENCY_SYMBOL,    OFFSET(currency_symbol   ) },
  { _CITRUS_LC_MONETARY_SYM_MON_DECIMAL_POINT,  OFFSET(mon_decimal_point ) },
  { _CITRUS_LC_MONETARY_SYM_MON_THOUSANDS_SEP,  OFFSET(mon_thousands_sep ) },
  { _CITRUS_LC_MONETARY_SYM_MON_GROUPING,       OFFSET(mon_grouping      ) },
  { _CITRUS_LC_MONETARY_SYM_POSITIVE_SIGN,      OFFSET(positive_sign     ) },
  { _CITRUS_LC_MONETARY_SYM_NEGATIVE_SIGN,      OFFSET(negative_sign     ) },
  { NULL, (size_t)0 }
};
static const struct _citrus_LC_MONETARY_key keys_char[] = {
  { _CITRUS_LC_MONETARY_SYM_INT_FRAC_DIGITS,    OFFSET(int_frac_digits   ) },
  { _CITRUS_LC_MONETARY_SYM_FRAC_DIGITS,        OFFSET(frac_digits       ) },
  { _CITRUS_LC_MONETARY_SYM_P_CS_PRECEDES,      OFFSET(p_cs_precedes     ) },
  { _CITRUS_LC_MONETARY_SYM_P_SEP_BY_SPACE,     OFFSET(p_sep_by_space    ) },
  { _CITRUS_LC_MONETARY_SYM_N_CS_PRECEDES,      OFFSET(n_cs_precedes     ) },
  { _CITRUS_LC_MONETARY_SYM_N_SEP_BY_SPACE,     OFFSET(n_sep_by_space    ) },
  { _CITRUS_LC_MONETARY_SYM_P_SIGN_POSN,        OFFSET(p_sign_posn       ) },
  { _CITRUS_LC_MONETARY_SYM_N_SIGN_POSN,        OFFSET(n_sign_posn       ) },
  { _CITRUS_LC_MONETARY_SYM_INT_P_CS_PRECEDES,  OFFSET(int_p_cs_precedes ) },
  { _CITRUS_LC_MONETARY_SYM_INT_N_CS_PRECEDES,  OFFSET(int_n_cs_precedes ) },
  { _CITRUS_LC_MONETARY_SYM_INT_P_SEP_BY_SPACE, OFFSET(int_p_sep_by_space) },
  { _CITRUS_LC_MONETARY_SYM_INT_N_SEP_BY_SPACE, OFFSET(int_n_sep_by_space) },
  { _CITRUS_LC_MONETARY_SYM_INT_P_SIGN_POSN,    OFFSET(int_p_sign_posn   ) },
  { _CITRUS_LC_MONETARY_SYM_INT_N_SIGN_POSN,    OFFSET(int_n_sign_posn   ) },
  { NULL, (size_t)0 }
};

static __inline int
_citrus_LC_MONETARY_init_normal(_MonetaryLocale * __restrict data,
    struct _citrus_db * __restrict db)
{
	const struct _citrus_LC_MONETARY_key *key;
	char **p_string, *p_char;
	const char *s;
	uint8_t u8;

	_DIAGASSERT(data != NULL);
	_DIAGASSERT(db != NULL);

	memset(data, 0, sizeof(*data));
	for (key = &keys_string[0]; key->name != NULL; ++key) {
		if (_db_lookupstr_by_s(db, key->name, &s, NULL))
			goto fatal;
		p_string = (char **)(void *)
		    (((char *)(void *)data) + key->offset);
		*p_string = strdup(s);
		if (*p_string == NULL)
			goto fatal;
	}
	for (key = &keys_char[0]; key->name != NULL; ++key) {
		if (_db_lookup8_by_s(db, key->name, &u8, NULL))
			goto fatal;
		p_char = ((char *)(void *)data) + key->offset;
		*p_char = (char)(unsigned char)u8;
	}
	_CITRUS_FIXUP_CHAR_MAX_MD(data->mon_grouping);

	return 0;

fatal:
	_citrus_LC_MONETARY_uninit(data);
	return EFTYPE;
}

static __inline int
_citrus_LC_MONETARY_init_fallback(_MonetaryLocale * __restrict data,
    struct _memstream * __restrict ms)
{
	const struct _citrus_LC_MONETARY_key *key;
	char **p_string, *p_char;
	const char *s;
	size_t n;
	char *t;
	long int l;

	_DIAGASSERT(data != NULL);
	_DIAGASSERT(ms != NULL);

	memset(data, 0, sizeof(*data));
	for (key = &keys_string[0]; key->name != NULL; ++key) {
		if ((s = _memstream_getln(ms, &n)) == NULL)
			goto fatal;
		p_string = (char **)(void *)
		    (((char *)(void *)data) + key->offset);
		*p_string = strndup(s, n - 1);
		if (*p_string == NULL)
			goto fatal;
	}
	for (key = &keys_char[0]; key->name != NULL; ++key) {
		if ((s = _memstream_getln(ms, &n)) == NULL)
			goto fatal;
		t = strndup(s, n - 1);
		if (t == NULL)
			goto fatal;
		s = (const char *)t;
		l = _bcs_strtol(s, &t, 0);
		if (s == t || l < 0 || l > 0x7fL) {
			free(t);
			goto fatal;
		}
		free(t);
		p_char = ((char *)(void *)data) + key->offset;
		*p_char = (char)(l & 0x7fL);
	}
        data->mon_grouping =
	    __fix_locale_grouping_str(data->mon_grouping);
	return 0;

fatal:
	_citrus_LC_MONETARY_uninit(data);
	return EFTYPE;
}

/*
 * macro required by citrus_lc_template.h
 */
#define _CATEGORY_DB		"LC_MONETARY"
#define _CATEGORY_MAGIC		_CITRUS_LC_MONETARY_MAGIC_1

#include "citrus_lc_template.h"
_LOCALE_CATEGORY_ENTRY(_citrus_LC_MONETARY_);

File Added: src/lib/libc/citrus/citrus_lc_monetary.h
/* $NetBSD: citrus_lc_monetary.h,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _CITRUS_LC_MONETARY_H_
#define _CITRUS_LC_MONETARY_H_

/*
 *
 */
#define _CITRUS_LC_MONETARY_MAGIC_1		"CtrsMO10"
#define _CITRUS_LC_MONETARY_SYM_VERSION		"version"
#define _CITRUS_LC_MONETARY_VERSION		0x00000001

/*
 *
 */
#define _CITRUS_LC_MONETARY_SYM_INT_CURR_SYMBOL		"int_curr_symbol"
#define _CITRUS_LC_MONETARY_SYM_CURRENCY_SYMBOL		"currency_symbol"
#define _CITRUS_LC_MONETARY_SYM_MON_DECIMAL_POINT	"mon_decimal_point"
#define _CITRUS_LC_MONETARY_SYM_MON_THOUSANDS_SEP	"mon_thousands_sep"
#define _CITRUS_LC_MONETARY_SYM_MON_GROUPING		"mon_grouping"
#define _CITRUS_LC_MONETARY_SYM_POSITIVE_SIGN		"positive_sign"
#define _CITRUS_LC_MONETARY_SYM_NEGATIVE_SIGN		"negative_sign"
#define _CITRUS_LC_MONETARY_SYM_INT_FRAC_DIGITS		"int_frac_digits"
#define _CITRUS_LC_MONETARY_SYM_FRAC_DIGITS		"frac_digits"
#define _CITRUS_LC_MONETARY_SYM_P_CS_PRECEDES		"p_cs_precedes"
#define _CITRUS_LC_MONETARY_SYM_P_SEP_BY_SPACE		"p_sep_by_space"
#define _CITRUS_LC_MONETARY_SYM_N_CS_PRECEDES		"n_cs_precedes"
#define _CITRUS_LC_MONETARY_SYM_N_SEP_BY_SPACE		"n_sep_by_space"
#define _CITRUS_LC_MONETARY_SYM_P_SIGN_POSN		"p_sign_posn"
#define _CITRUS_LC_MONETARY_SYM_N_SIGN_POSN		"n_sign_posn"
#define _CITRUS_LC_MONETARY_SYM_INT_P_CS_PRECEDES	"int_p_cs_precedes"
#define _CITRUS_LC_MONETARY_SYM_INT_N_CS_PRECEDES	"int_n_cs_precedes"
#define _CITRUS_LC_MONETARY_SYM_INT_P_SEP_BY_SPACE	"int_p_sep_by_space"
#define _CITRUS_LC_MONETARY_SYM_INT_N_SEP_BY_SPACE	"int_n_sep_by_space"
#define _CITRUS_LC_MONETARY_SYM_INT_P_SIGN_POSN		"int_p_sign_posn"
#define _CITRUS_LC_MONETARY_SYM_INT_N_SIGN_POSN		"int_n_sign_posn"

#endif /*_CITRUS_LC_MONETARY_H_*/

File Added: src/lib/libc/citrus/citrus_lc_numeric.c
/* $NetBSD: citrus_lc_numeric.c,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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 <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: citrus_lc_numeric.c,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include "namespace.h"
#include "reentrant.h"
#include <sys/types.h>
#include <sys/localedef.h>
#include <sys/queue.h>
#include <assert.h>
#include <errno.h>
#include <langinfo.h>
#include <limits.h>
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "setlocale_local.h"

#include "citrus_namespace.h"
#include "citrus_types.h"
#include "citrus_bcs.h"
#include "citrus_region.h"
#include "citrus_lookup.h"
#include "citrus_aliasname_local.h"
#include "citrus_module.h"
#include "citrus_mmap.h"
#include "citrus_hash.h"
#include "citrus_db.h"
#include "citrus_db_hash.h"
#include "citrus_memstream.h"
#include "rune.h"

#include "fix_grouping.h"
#include "citrus_fix_grouping.h"

/*
 * macro required by all template headers
 */
#define _PREFIX(name)		__CONCAT(_citrus_LC_NUMERIC_, name)

#include "nb_lc_numeric_misc.h"
#include "citrus_lc_template_decl.h"

static __inline void
_citrus_LC_NUMERIC_uninit(_NumericLocale *data)
{
	free(__UNCONST(data->decimal_point));
	free(__UNCONST(data->thousands_sep));
	free(__UNCONST(data->grouping));
}

#include "citrus_lc_numeric.h"

struct _citrus_LC_NUMERIC_key {
	const char *name;
	size_t offset;
};

#define OFFSET(field) (offsetof(_NumericLocale, field))
static const struct _citrus_LC_NUMERIC_key keys[] = {
  { _CITRUS_LC_NUMERIC_SYM_DECIMAL_POINT, OFFSET(decimal_point) },
  { _CITRUS_LC_NUMERIC_SYM_THOUSANDS_SEP, OFFSET(thousands_sep) },
  { _CITRUS_LC_NUMERIC_SYM_GROUPING,      OFFSET(grouping     ) },
  { NULL, 0 }
};

static __inline int
_citrus_LC_NUMERIC_init_normal(_NumericLocale * __restrict data,
    struct _citrus_db * __restrict db)
{
	const struct _citrus_LC_NUMERIC_key *key;
	char **p;
	const char *s;

	_DIAGASSERT(data != NULL);
	_DIAGASSERT(db != NULL);

	memset(data, 0, sizeof(*data));
	for (key = &keys[0]; key->name != NULL; ++key) {
		if (_db_lookupstr_by_s(db, key->name, &s, NULL))
			goto fatal;
		p = (char **)(void *)
		    (((char *)(void *)data) + key->offset);
		*p = strdup(s);
		if (*p == NULL)
			goto fatal;
	}
	_CITRUS_FIXUP_CHAR_MAX_MD(data->grouping);

	return 0;

fatal:
	_citrus_LC_NUMERIC_uninit(data);
	return EFTYPE;
}

static __inline int
_citrus_LC_NUMERIC_init_fallback(_NumericLocale * __restrict data,
    struct _memstream * __restrict ms)
{
	const struct _citrus_LC_NUMERIC_key *key;
	char **p;
	const char *s;
	size_t n;

	_DIAGASSERT(data != NULL);
	_DIAGASSERT(ms != NULL);

	memset(data, 0, sizeof(*data));
	for (key = &keys[0]; key->name != NULL; ++key) {
		if ((s = _memstream_getln(ms, &n)) == NULL)
			goto fatal;
		p = (char **)(void *)
		    (((char *)(void *)data) + key->offset);
		*p = strndup(s, n - 1);
		if (*p == NULL)
			goto fatal;
	}
	data->grouping =
	    __fix_locale_grouping_str(data->grouping);

	return 0;

fatal:
	_citrus_LC_NUMERIC_uninit(data);
	return EFTYPE;
}

/*
 * macro required by citrus_lc_template.h
 */
#define _CATEGORY_DB		"LC_NUMERIC"
#define _CATEGORY_MAGIC		_CITRUS_LC_NUMERIC_MAGIC_1

#include "citrus_lc_template.h"
_LOCALE_CATEGORY_ENTRY(_citrus_LC_NUMERIC_);

File Added: src/lib/libc/citrus/citrus_lc_numeric.h
/* $NetBSD: citrus_lc_numeric.h,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _CITRUS_LC_NUMERIC_H_
#define _CITRUS_LC_NUMERIC_H_

/*
 *
 */
#define _CITRUS_LC_NUMERIC_MAGIC_1	"CtrsNU10"
#define _CITRUS_LC_NUMERIC_SYM_VERSION	"version"
#define _CITRUS_LC_NUMERIC_VERSION	0x00000001

/*
 *
 */
#define _CITRUS_LC_NUMERIC_SYM_DECIMAL_POINT		"decimal_point"
#define _CITRUS_LC_NUMERIC_SYM_THOUSANDS_SEP		"thousands_sep"
#define _CITRUS_LC_NUMERIC_SYM_GROUPING			"grouping"

#endif /*_CITRUS_LC_NUMERIC_H_*/

File Added: src/lib/libc/citrus/citrus_lc_template.h
/* $NetBSD: citrus_lc_template.h,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _CITRUS_LC_TEMPLATE_H_
#define _CITRUS_LC_TEMPLATE_H_

static __inline int
_PREFIX(create_impl)(const char * __restrict root,
    const char * __restrict name, _CATEGORY_TYPE ** __restrict pdata)
{
	char path[PATH_MAX + 1];
	int ret;
	struct _region file;
	struct _citrus_db *db;
	struct _memstream ms;
	_CATEGORY_TYPE *data;

	snprintf(path, sizeof(path),
	    "%s/%s/" _CATEGORY_DB, root, name);
	ret = _map_file(&file, path);
	if (ret) {
		ret = ENOENT;
	} else {
		data = malloc(sizeof(*data));
		if (!data) {
			ret = ENOMEM;
		} else {
			ret = _db_open(&db, &file, _CATEGORY_MAGIC,
			    &_db_hash_std, NULL);
			if (!ret) {
				ret = _PREFIX(init_normal)(data, db);
				_db_close(db);
			} else {
				_memstream_bind(&ms, &file);
				ret = _PREFIX(init_fallback)(data, &ms);
			}
			if (!ret)
				*pdata = data;
			else
				free(data);
		}
		_unmap_file(&file);
	}
	return ret;
}

#include "nb_lc_template.h"

#endif /* _CITRUS_LC_TEMPLATE_H_ */

File Added: src/lib/libc/citrus/citrus_lc_template_decl.h
/* $NetBSD: citrus_lc_template_decl.h,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _CITRUS_LC_TEMPLATE_DECL_H_
#define _CITRUS_LC_TEMPLATE_DECL_H_

#include "nb_lc_template_decl.h"

static __inline int
_PREFIX(init_normal)(_CATEGORY_TYPE * __restrict,
    struct _citrus_db * __restrict db);

static __inline int
_PREFIX(init_fallback)(_CATEGORY_TYPE * __restrict,
    struct _memstream * __restrict);

#endif /*_CITRUS_LC_TEMPLATE_DECL_H_*/

File Added: src/lib/libc/citrus/citrus_lc_time.c
/* $NetBSD: citrus_lc_time.c,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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 <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: citrus_lc_time.c,v 1.1.2.2 2009/01/04 17:02:18 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include "namespace.h"
#include "reentrant.h"
#include <sys/types.h>
#include <sys/localedef.h>
#include <sys/queue.h>
#include <assert.h>
#include <errno.h>
#include <langinfo.h>
#include <limits.h>
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "setlocale_local.h"

#include "citrus_namespace.h"
#include "citrus_types.h"
#include "citrus_bcs.h"
#include "citrus_region.h"
#include "citrus_lookup.h"
#include "citrus_aliasname_local.h"
#include "citrus_module.h"
#include "citrus_mmap.h"
#include "citrus_hash.h"
#include "citrus_db.h"
#include "citrus_db_hash.h"
#include "citrus_memstream.h"
#include "rune.h"

/*
 * macro required by all template headers
 */
#define _PREFIX(name)		__CONCAT(_citrus_LC_TIME_, name)

#include "nb_lc_time_misc.h"
#include "citrus_lc_template_decl.h"

static __inline void
_citrus_LC_TIME_uninit(_TimeLocale *data)
{
	size_t i, j;

	_DIAGASSERT(data != NULL);

	for (i = ABDAY_IDX(ABDAY_1), j = ABDAY_IDX(ABDAY_7);  i <= j; ++i)
		free(__UNCONST(data->abday[i]));
	for (i = DAY_IDX(DAY_1),     j = DAY_IDX(DAY_7);      i <= j; ++i)
		free(__UNCONST(data->day[i]));
	for (i = ABMON_IDX(ABMON_1), j = ABMON_IDX(ABMON_12); i <= j; ++i)
		free(__UNCONST(data->abmon[i]));
	for (i = MON_IDX(MON_1),     j = MON_IDX(MON_12);     i <= j; ++i)
		free(__UNCONST(data->mon[i]));
	for (i = AM_PM_IDX(AM_STR),  j = AM_PM_IDX(PM_STR);   i <= j; ++i)
		free(__UNCONST(data->am_pm[i]));
	free(__UNCONST(data->d_t_fmt));
	free(__UNCONST(data->d_fmt));
	free(__UNCONST(data->t_fmt));
	free(__UNCONST(data->t_fmt_ampm));
}

#include "citrus_lc_time.h"

struct _citrus_LC_TIME_key {
	const char *name;
	size_t offset;
};

#define OFFSET(field) offsetof(_TimeLocale, field)
static const struct _citrus_LC_TIME_key keys[] = {
  { _CITRUS_LC_TIME_SYM_ABDAY_1,  OFFSET(abday[ABDAY_IDX(ABDAY_1)] ) },
  { _CITRUS_LC_TIME_SYM_ABDAY_2,  OFFSET(abday[ABDAY_IDX(ABDAY_2)] ) },
  { _CITRUS_LC_TIME_SYM_ABDAY_3,  OFFSET(abday[ABDAY_IDX(ABDAY_3)] ) },
  { _CITRUS_LC_TIME_SYM_ABDAY_4,  OFFSET(abday[ABDAY_IDX(ABDAY_4)] ) },
  { _CITRUS_LC_TIME_SYM_ABDAY_5,  OFFSET(abday[ABDAY_IDX(ABDAY_5)] ) },
  { _CITRUS_LC_TIME_SYM_ABDAY_6,  OFFSET(abday[ABDAY_IDX(ABDAY_6)] ) },
  { _CITRUS_LC_TIME_SYM_ABDAY_7,  OFFSET(abday[ABDAY_IDX(ABDAY_7)] ) },
  { _CITRUS_LC_TIME_SYM_DAY_1,    OFFSET(day[DAY_IDX(DAY_1)]       ) },
  { _CITRUS_LC_TIME_SYM_DAY_2,    OFFSET(day[DAY_IDX(DAY_2)]       ) },
  { _CITRUS_LC_TIME_SYM_DAY_3,    OFFSET(day[DAY_IDX(DAY_3)]       ) },
  { _CITRUS_LC_TIME_SYM_DAY_4,    OFFSET(day[DAY_IDX(DAY_4)]       ) },
  { _CITRUS_LC_TIME_SYM_DAY_5,    OFFSET(day[DAY_IDX(DAY_5)]       ) },
  { _CITRUS_LC_TIME_SYM_DAY_6,    OFFSET(day[DAY_IDX(DAY_6)]       ) },
  { _CITRUS_LC_TIME_SYM_DAY_7,    OFFSET(day[DAY_IDX(DAY_7)]       ) },
  { _CITRUS_LC_TIME_SYM_ABMON_1,  OFFSET(abmon[ABMON_IDX(ABMON_1)] ) },
  { _CITRUS_LC_TIME_SYM_ABMON_2,  OFFSET(abmon[ABMON_IDX(ABMON_2)] ) },
  { _CITRUS_LC_TIME_SYM_ABMON_3,  OFFSET(abmon[ABMON_IDX(ABMON_3)] ) },
  { _CITRUS_LC_TIME_SYM_ABMON_4,  OFFSET(abmon[ABMON_IDX(ABMON_4)] ) },
  { _CITRUS_LC_TIME_SYM_ABMON_5,  OFFSET(abmon[ABMON_IDX(ABMON_5)] ) },
  { _CITRUS_LC_TIME_SYM_ABMON_6,  OFFSET(abmon[ABMON_IDX(ABMON_6)] ) },
  { _CITRUS_LC_TIME_SYM_ABMON_7,  OFFSET(abmon[ABMON_IDX(ABMON_7)] ) },
  { _CITRUS_LC_TIME_SYM_ABMON_8,  OFFSET(abmon[ABMON_IDX(ABMON_8)] ) },
  { _CITRUS_LC_TIME_SYM_ABMON_9,  OFFSET(abmon[ABMON_IDX(ABMON_9)] ) },
  { _CITRUS_LC_TIME_SYM_ABMON_10, OFFSET(abmon[ABMON_IDX(ABMON_10)]) },
  { _CITRUS_LC_TIME_SYM_ABMON_11, OFFSET(abmon[ABMON_IDX(ABMON_11)]) },
  { _CITRUS_LC_TIME_SYM_ABMON_12, OFFSET(abmon[ABMON_IDX(ABMON_12)]) },
  { _CITRUS_LC_TIME_SYM_MON_1,    OFFSET(mon[MON_IDX(MON_1)]       ) },
  { _CITRUS_LC_TIME_SYM_MON_2,    OFFSET(mon[MON_IDX(MON_2)]       ) },
  { _CITRUS_LC_TIME_SYM_MON_3,    OFFSET(mon[MON_IDX(MON_3)]       ) },
  { _CITRUS_LC_TIME_SYM_MON_4,    OFFSET(mon[MON_IDX(MON_4)]       ) },
  { _CITRUS_LC_TIME_SYM_MON_5,    OFFSET(mon[MON_IDX(MON_5)]       ) },
  { _CITRUS_LC_TIME_SYM_MON_6,    OFFSET(mon[MON_IDX(MON_6)]       ) },
  { _CITRUS_LC_TIME_SYM_MON_7,    OFFSET(mon[MON_IDX(MON_7)]       ) },
  { _CITRUS_LC_TIME_SYM_MON_8,    OFFSET(mon[MON_IDX(MON_8)]       ) },
  { _CITRUS_LC_TIME_SYM_MON_9,    OFFSET(mon[MON_IDX(MON_9)]       ) },
  { _CITRUS_LC_TIME_SYM_MON_10,   OFFSET(mon[MON_IDX(MON_10)]      ) },
  { _CITRUS_LC_TIME_SYM_MON_11,   OFFSET(mon[MON_IDX(MON_11)]      ) },
  { _CITRUS_LC_TIME_SYM_MON_12,   OFFSET(mon[MON_IDX(MON_12)]      ) },
  { _CITRUS_LC_TIME_SYM_AM_STR,   OFFSET(am_pm[AM_PM_IDX(AM_STR)]  ) },
  { _CITRUS_LC_TIME_SYM_PM_STR,   OFFSET(am_pm[AM_PM_IDX(PM_STR)]  ) },
  { _CITRUS_LC_TIME_SYM_D_T_FMT,  OFFSET(d_t_fmt                   ) },
  { _CITRUS_LC_TIME_SYM_D_FMT,    OFFSET(d_fmt                     ) },
  { _CITRUS_LC_TIME_SYM_T_FMT,    OFFSET(t_fmt                     ) },
  { _CITRUS_LC_TIME_SYM_T_FMT,    OFFSET(t_fmt_ampm                ) },
  { NULL, 0 }
};

static __inline int
_citrus_LC_TIME_init_normal(_TimeLocale * __restrict data,
    struct _citrus_db * __restrict db)
{
        const struct _citrus_LC_TIME_key *key;
	char **p;
	const char *s;

	_DIAGASSERT(data != NULL);
	_DIAGASSERT(db != NULL);

	memset(data, 0, sizeof(*data));
	for (key = &keys[0]; key->name != NULL; ++key) {
		if (_db_lookupstr_by_s(db, key->name, &s, NULL))
			goto fatal;
		p = (char **)(void *)
		    (((char *)(void *)data) + key->offset);
		*p = strdup(s);
		if (*p == NULL)
			goto fatal;
	}
	return 0;

fatal:
	_citrus_LC_TIME_uninit(data);
	return EFTYPE;
}

static __inline int
_citrus_LC_TIME_init_fallback(_TimeLocale * __restrict data,
    struct _memstream * __restrict ms)
{
        const struct _citrus_LC_TIME_key *key;
	char **p;
	const char *s;
	size_t n;

	memset(data, 0, sizeof(*data));
	for (key = &keys[0]; key->name != NULL; ++key) {
		if ((s = _memstream_getln(ms, &n)) == NULL)
			goto fatal;
		p = (char **)(void *)
		    (((char *)(void *)data) + key->offset);
		*p = strndup(s, n - 1);
		if (*p == NULL)
			goto fatal;
	}
	return 0;

fatal:
	_citrus_LC_TIME_uninit(data);
	return EFTYPE;
}

/*
 * macro required by citrus_lc_template.h
 */
#define _CATEGORY_DB		"LC_TIME"
#define _CATEGORY_MAGIC		_CITRUS_LC_TIME_MAGIC_1

#include "citrus_lc_template.h"
_LOCALE_CATEGORY_ENTRY(_citrus_LC_TIME_);

File Added: src/lib/libc/citrus/citrus_lc_time.h
/* $NetBSD: citrus_lc_time.h,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _CITRUS_LC_TIME_H_
#define _CITRUS_LC_TIME_H_

/*
 *
 */
#define _CITRUS_LC_TIME_MAGIC_1		"CtrsTI10"
#define _CITRUS_LC_TIME_SYM_VERSION	"version"
#define _CITRUS_LC_TIME_VERSION		0x00000001

/*
 *
 */
#define _CITRUS_LC_TIME_SYM_ABDAY_1			"abday1"
#define _CITRUS_LC_TIME_SYM_ABDAY_2			"abday2"
#define _CITRUS_LC_TIME_SYM_ABDAY_3			"abday3"
#define _CITRUS_LC_TIME_SYM_ABDAY_4			"abday4"
#define _CITRUS_LC_TIME_SYM_ABDAY_5			"abday5"
#define _CITRUS_LC_TIME_SYM_ABDAY_6			"abday6"
#define _CITRUS_LC_TIME_SYM_ABDAY_7			"abday7"
#define _CITRUS_LC_TIME_SYM_DAY_1			"day1"
#define _CITRUS_LC_TIME_SYM_DAY_2			"day2"
#define _CITRUS_LC_TIME_SYM_DAY_3			"day3"
#define _CITRUS_LC_TIME_SYM_DAY_4			"day4"
#define _CITRUS_LC_TIME_SYM_DAY_5			"day5"
#define _CITRUS_LC_TIME_SYM_DAY_6			"day6"
#define _CITRUS_LC_TIME_SYM_DAY_7			"day7"
#define _CITRUS_LC_TIME_SYM_ABMON_1			"abmon_1"
#define _CITRUS_LC_TIME_SYM_ABMON_2			"abmon_2"
#define _CITRUS_LC_TIME_SYM_ABMON_3			"abmon_3"
#define _CITRUS_LC_TIME_SYM_ABMON_4			"abmon_4"
#define _CITRUS_LC_TIME_SYM_ABMON_5			"abmon_5"
#define _CITRUS_LC_TIME_SYM_ABMON_6			"abmon_6"
#define _CITRUS_LC_TIME_SYM_ABMON_7			"abmon_7"
#define _CITRUS_LC_TIME_SYM_ABMON_8			"abmon_8"
#define _CITRUS_LC_TIME_SYM_ABMON_9			"abmon_9"
#define _CITRUS_LC_TIME_SYM_ABMON_10			"abmon_10"
#define _CITRUS_LC_TIME_SYM_ABMON_11			"abmon_11"
#define _CITRUS_LC_TIME_SYM_ABMON_12			"abmon_12"
#define _CITRUS_LC_TIME_SYM_MON_1			"mon_1"
#define _CITRUS_LC_TIME_SYM_MON_2			"mon_2"
#define _CITRUS_LC_TIME_SYM_MON_3			"mon_3"
#define _CITRUS_LC_TIME_SYM_MON_4			"mon_4"
#define _CITRUS_LC_TIME_SYM_MON_5			"mon_5"
#define _CITRUS_LC_TIME_SYM_MON_6			"mon_6"
#define _CITRUS_LC_TIME_SYM_MON_7			"mon_7"
#define _CITRUS_LC_TIME_SYM_MON_8			"mon_8"
#define _CITRUS_LC_TIME_SYM_MON_9			"mon_9"
#define _CITRUS_LC_TIME_SYM_MON_10			"mon_10"
#define _CITRUS_LC_TIME_SYM_MON_11			"mon_11"
#define _CITRUS_LC_TIME_SYM_MON_12			"mon_12"
#define _CITRUS_LC_TIME_SYM_AM_STR			"am_str"
#define _CITRUS_LC_TIME_SYM_PM_STR			"pm_str"
#define _CITRUS_LC_TIME_SYM_D_T_FMT			"d_t_fmt"
#define _CITRUS_LC_TIME_SYM_D_FMT			"d_fmt"
#define _CITRUS_LC_TIME_SYM_T_FMT			"t_fmt"
#define _CITRUS_LC_TIME_SYM_T_FMT_AMPM			"t_fmt_ampm"

#endif /*_CITRUS_LC_TIME_H_*/

cvs diff -r1.4 -r1.4.12.1 src/lib/libc/citrus/citrus_bcs.h (expand / switch to unified diff)

--- src/lib/libc/citrus/citrus_bcs.h 2008/02/09 14:56:20 1.4
+++ src/lib/libc/citrus/citrus_bcs.h 2009/01/04 17:02:18 1.4.12.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: citrus_bcs.h,v 1.4 2008/02/09 14:56:20 junyoung Exp $ */ 1/* $NetBSD: citrus_bcs.h,v 1.4.12.1 2009/01/04 17:02:18 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2003 Citrus Project, 4 * Copyright (c)2003 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -77,16 +77,22 @@ _citrus_bcs_tolower(uint8_t c) @@ -77,16 +77,22 @@ _citrus_bcs_tolower(uint8_t c)
77__BEGIN_DECLS 77__BEGIN_DECLS
78int _citrus_bcs_strcasecmp(const char * __restrict, const char * __restrict); 78int _citrus_bcs_strcasecmp(const char * __restrict, const char * __restrict);
79int _citrus_bcs_strncasecmp(const char * __restrict, const char * __restrict, 79int _citrus_bcs_strncasecmp(const char * __restrict, const char * __restrict,
80 size_t); 80 size_t);
81const char *_citrus_bcs_skip_ws(const char * __restrict); 81const char *_citrus_bcs_skip_ws(const char * __restrict);
82const char *_citrus_bcs_skip_nonws(const char * __restrict); 82const char *_citrus_bcs_skip_nonws(const char * __restrict);
83const char *_citrus_bcs_skip_ws_len(const char * __restrict, 83const char *_citrus_bcs_skip_ws_len(const char * __restrict,
84 size_t * __restrict); 84 size_t * __restrict);
85const char *_citrus_bcs_skip_nonws_len(const char * __restrict, 85const char *_citrus_bcs_skip_nonws_len(const char * __restrict,
86 size_t * __restrict); 86 size_t * __restrict);
87void _citrus_bcs_trunc_rws_len(const char * __restrict, size_t * __restrict); 87void _citrus_bcs_trunc_rws_len(const char * __restrict, size_t * __restrict);
88void _citrus_bcs_convert_to_lower(char *); 88void _citrus_bcs_convert_to_lower(char *);
89void _citrus_bcs_convert_to_upper(char *); 89void _citrus_bcs_convert_to_upper(char *);
 90
 91long int _citrus_bcs_strtol(
 92 const char * __restrict, char ** __restrict, int);
 93unsigned long int _citrus_bcs_strtoul(
 94 const char * __restrict, char ** __restrict, int);
 95
90__END_DECLS 96__END_DECLS
91 97
92#endif 98#endif

cvs diff -r1.8 -r1.8.12.1 src/lib/libc/citrus/citrus_csmapper.c (expand / switch to unified diff)

--- src/lib/libc/citrus/citrus_csmapper.c 2008/02/09 14:56:20 1.8
+++ src/lib/libc/citrus/citrus_csmapper.c 2009/01/04 17:02:18 1.8.12.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: citrus_csmapper.c,v 1.8 2008/02/09 14:56:20 junyoung Exp $ */ 1/* $NetBSD: citrus_csmapper.c,v 1.8.12.1 2009/01/04 17:02:18 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2003 Citrus Project, 4 * Copyright (c)2003 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -18,27 +18,27 @@ @@ -18,27 +18,27 @@
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31__RCSID("$NetBSD: citrus_csmapper.c,v 1.8 2008/02/09 14:56:20 junyoung Exp $"); 31__RCSID("$NetBSD: citrus_csmapper.c,v 1.8.12.1 2009/01/04 17:02:18 christos Exp $");
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
34#include "namespace.h" 34#include "namespace.h"
35#include "reentrant.h" 35#include "reentrant.h"
36#include <assert.h> 36#include <assert.h>
37#include <stdio.h> 37#include <stdio.h>
38#include <stdlib.h> 38#include <stdlib.h>
39#include <string.h> 39#include <string.h>
40#include <errno.h> 40#include <errno.h>
41#include <limits.h> 41#include <limits.h>
42#include <paths.h> 42#include <paths.h>
43#include <sys/types.h> 43#include <sys/types.h>
44#include <sys/queue.h> 44#include <sys/queue.h>
@@ -198,27 +198,27 @@ parse_line(struct parse_arg *pa, struct  @@ -198,27 +198,27 @@ parse_line(struct parse_arg *pa, struct
198 z1.end = _bcs_skip_nonws_len(z1.begin, &len); 198 z1.end = _bcs_skip_nonws_len(z1.begin, &len);
199 if (len == 0) 199 if (len == 0)
200 return EFTYPE; 200 return EFTYPE;
201 z2.begin = _bcs_skip_ws_len(z1.end, &len); 201 z2.begin = _bcs_skip_ws_len(z1.end, &len);
202 if (len == 0) 202 if (len == 0)
203 return EFTYPE; 203 return EFTYPE;
204 z2.end = _bcs_skip_nonws_len(z2.begin, &len); 204 z2.end = _bcs_skip_nonws_len(z2.begin, &len);
205 205
206 /* z1 : dst name, z2 : norm */ 206 /* z1 : dst name, z2 : norm */
207 snprintf(pa->dst, sizeof(pa->dst), 207 snprintf(pa->dst, sizeof(pa->dst),
208 "%.*s", (int)(z1.end-z1.begin), z1.begin); 208 "%.*s", (int)(z1.end-z1.begin), z1.begin);
209 snprintf(buf, sizeof(buf), 209 snprintf(buf, sizeof(buf),
210 "%.*s", (int)(z2.end-z2.begin), z2.begin); 210 "%.*s", (int)(z2.end-z2.begin), z2.begin);
211 pa->norm = strtoul(buf, NULL, 0); 211 pa->norm = _bcs_strtoul(buf, NULL, 0);
212 212
213 return 0; 213 return 0;
214} 214}
215 215
216static int 216static int
217find_dst(struct parse_arg *pasrc, const char *dst) 217find_dst(struct parse_arg *pasrc, const char *dst)
218{ 218{
219 int ret; 219 int ret;
220 struct parse_arg padst; 220 struct parse_arg padst;
221 struct _lookup *cl; 221 struct _lookup *cl;
222 struct _region data; 222 struct _region data;
223 223
224 ret = _lookup_seq_open(&cl, CS_PIVOT, _LOOKUP_CASE_IGNORE); 224 ret = _lookup_seq_open(&cl, CS_PIVOT, _LOOKUP_CASE_IGNORE);

cvs diff -r1.7 -r1.7.6.1 src/lib/libc/citrus/citrus_module.c (expand / switch to unified diff)

--- src/lib/libc/citrus/citrus_module.c 2008/06/14 16:01:07 1.7
+++ src/lib/libc/citrus/citrus_module.c 2008/06/14 16:01:07 1.7.6.1
@@ -1,355 +0,0 @@ @@ -1,355 +0,0 @@
1/* $NetBSD: citrus_module.c,v 1.7 2008/06/14 16:01:07 tnozaki Exp $ */ 
2 
3/*- 
4 * Copyright (c)1999, 2000, 2001, 2002 Citrus Project, 
5 * All rights reserved. 
6 * 
7 * Redistribution and use in source and binary forms, with or without 
8 * modification, are permitted provided that the following conditions 
9 * are met: 
10 * 1. Redistributions of source code must retain the above copyright 
11 * notice, this list of conditions and the following disclaimer. 
12 * 2. Redistributions in binary form must reproduce the above copyright 
13 * notice, this list of conditions and the following disclaimer in the 
14 * documentation and/or other materials provided with the distribution. 
15 * 
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
26 * SUCH DAMAGE. 
27 */ 
28 
29/*- 
30 * Copyright (c) 1998 The NetBSD Foundation, Inc. 
31 * All rights reserved. 
32 * 
33 * This code is derived from software contributed to The NetBSD Foundation 
34 * by Paul Kranenburg. 
35 * 
36 * Redistribution and use in source and binary forms, with or without 
37 * modification, are permitted provided that the following conditions 
38 * are met: 
39 * 1. Redistributions of source code must retain the above copyright 
40 * notice, this list of conditions and the following disclaimer. 
41 * 2. Redistributions in binary form must reproduce the above copyright 
42 * notice, this list of conditions and the following disclaimer in the 
43 * documentation and/or other materials provided with the distribution. 
44 * 
45 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 
46 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
47 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
48 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 
49 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
50 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
51 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
52 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
53 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
55 * POSSIBILITY OF SUCH DAMAGE. 
56 */ 
57 
58/*- 
59 * Copyright (c) 1993 
60 * The Regents of the University of California. All rights reserved. 
61 * 
62 * This code is derived from software contributed to Berkeley by 
63 * Paul Borman at Krystal Technologies. 
64 * 
65 * Redistribution and use in source and binary forms, with or without 
66 * modification, are permitted provided that the following conditions 
67 * are met: 
68 * 1. Redistributions of source code must retain the above copyright 
69 * notice, this list of conditions and the following disclaimer. 
70 * 2. Redistributions in binary form must reproduce the above copyright 
71 * notice, this list of conditions and the following disclaimer in the 
72 * documentation and/or other materials provided with the distribution. 
73 * 3. Neither the name of the University nor the names of its contributors 
74 * may be used to endorse or promote products derived from this software 
75 * without specific prior written permission. 
76 * 
77 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 
78 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
79 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
80 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 
81 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
82 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
83 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
84 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
85 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
86 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
87 * SUCH DAMAGE. 
88 */ 
89 
90#include <sys/cdefs.h> 
91#if defined(LIBC_SCCS) && !defined(lint) 
92__RCSID("$NetBSD: citrus_module.c,v 1.7 2008/06/14 16:01:07 tnozaki Exp $"); 
93#endif /* LIBC_SCCS and not lint */ 
94 
95#include <assert.h> 
96#include <errno.h> 
97#include <limits.h> 
98#include <string.h> 
99#include <stdio.h> 
100#include <stdlib.h> 
101#include <unistd.h> 
102#include <stddef.h> 
103#include <paths.h> 
104#include "citrus_module.h" 
105 
106#include <sys/types.h> 
107#include <dirent.h> 
108#include <dlfcn.h> 
109 
110#ifdef _I18N_DYNAMIC 
111 
112static int _getdewey(int [], char *); 
113static int _cmpndewey(int [], int, int [], int); 
114static const char *_findshlib(char *, int *, int *); 
115 
116static const char *_pathI18nModule = NULL; 
117 
118/* from libexec/ld.aout_so/shlib.c */ 
119#undef major 
120#undef minor 
121#define MAXDEWEY 3 /*ELF*/ 
122 
123static int 
124_getdewey(int dewey[], char *cp) 
125{ 
126 int i, n; 
127 
128 _DIAGASSERT(dewey != NULL); 
129 _DIAGASSERT(cp != NULL); 
130 
131 for (n = 0, i = 0; i < MAXDEWEY; i++) { 
132 if (*cp == '\0') 
133 break; 
134 
135 if (*cp == '.') cp++; 
136 if (*cp < '0' || '9' < *cp) 
137 return 0; 
138 
139 dewey[n++] = (int)strtol(cp, &cp, 10); 
140 } 
141 
142 return n; 
143} 
144 
145/* 
146 * Compare two dewey arrays. 
147 * Return -1 if `d1' represents a smaller value than `d2'. 
148 * Return 1 if `d1' represents a greater value than `d2'. 
149 * Return 0 if equal. 
150 */ 
151static int 
152_cmpndewey(int d1[], int n1, int d2[], int n2) 
153{ 
154 register int i; 
155 
156 _DIAGASSERT(d1 != NULL); 
157 _DIAGASSERT(d2 != NULL); 
158 
159 for (i = 0; i < n1 && i < n2; i++) { 
160 if (d1[i] < d2[i]) 
161 return -1; 
162 if (d1[i] > d2[i]) 
163 return 1; 
164 } 
165 
166 if (n1 == n2) 
167 return 0; 
168 
169 if (i == n1) 
170 return -1; 
171 
172 if (i == n2) 
173 return 1; 
174 
175 /* XXX cannot happen */ 
176 return 0; 
177} 
178 
179static const char * 
180_findshlib(char *name, int *majorp, int *minorp) 
181{ 
182 int dewey[MAXDEWEY]; 
183 int ndewey; 
184 int tmp[MAXDEWEY]; 
185 int i; 
186 int len; 
187 char *lname; 
188 static char path[PATH_MAX]; 
189 int major, minor; 
190 const char *search_dirs[1]; 
191 const int n_search_dirs = 1; 
192 
193 _DIAGASSERT(name != NULL); 
194 _DIAGASSERT(majorp != NULL); 
195 _DIAGASSERT(minorp != NULL); 
196 
197 major = *majorp; 
198 minor = *minorp; 
199 path[0] = '\0'; 
200 search_dirs[0] = _pathI18nModule; 
201 len = strlen(name); 
202 lname = name; 
203 
204 ndewey = 0; 
205 
206 for (i = 0; i < n_search_dirs; i++) { 
207 DIR *dd = opendir(search_dirs[i]); 
208 struct dirent *dp; 
209 int found_dot_a = 0; 
210 int found_dot_so = 0; 
211 
212 if (dd == NULL) 
213 continue; 
214 
215 while ((dp = readdir(dd)) != NULL) { 
216 int n; 
217 
218 if (dp->d_namlen < len + 4) 
219 continue; 
220 if (strncmp(dp->d_name, lname, (size_t)len) != 0) 
221 continue; 
222 if (strncmp(dp->d_name+len, ".so.", 4) != 0) 
223 continue; 
224 
225 if ((n = _getdewey(tmp, dp->d_name+len+4)) == 0) 
226 continue; 
227 
228 if (major != -1 && found_dot_a) 
229 found_dot_a = 0; 
230 
231 /* XXX should verify the library is a.out/ELF? */ 
232 
233 if (major == -1 && minor == -1) { 
234 goto compare_version; 
235 } else if (major != -1 && minor == -1) { 
236 if (tmp[0] == major) 
237 goto compare_version; 
238 } else if (major != -1 && minor != -1) { 
239 if (tmp[0] == major) { 
240 if (n == 1 || tmp[1] >= minor) 
241 goto compare_version; 
242 } 
243 } 
244 
245 /* else, this file does not qualify */ 
246 continue; 
247 
248 compare_version: 
249 if (_cmpndewey(tmp, n, dewey, ndewey) <= 0) 
250 continue; 
251 
252 /* We have a better version */ 
253 found_dot_so = 1; 
254 snprintf(path, sizeof(path), "%s/%s", search_dirs[i], 
255 dp->d_name); 
256 found_dot_a = 0; 
257 bcopy(tmp, dewey, sizeof(dewey)); 
258 ndewey = n; 
259 *majorp = dewey[0]; 
260 *minorp = dewey[1]; 
261 } 
262 closedir(dd); 
263 
264 if (found_dot_a || found_dot_so) 
265 /* 
266 * There's a lib in this dir; take it. 
267 */ 
268 return path[0] ? path : NULL; 
269 } 
270 
271 return path[0] ? path : NULL; 
272} 
273 
274void * 
275_citrus_find_getops(_citrus_module_t handle, const char *modname, 
276 const char *ifname) 
277{ 
278 char name[PATH_MAX]; 
279 void *p; 
280 
281 _DIAGASSERT(handle != NULL); 
282 _DIAGASSERT(modname != NULL); 
283 _DIAGASSERT(ifname != NULL); 
284 
285 snprintf(name, sizeof(name), _C_LABEL_STRING("_citrus_%s_%s_getops"), 
286 modname, ifname); 
287 p = dlsym((void *)handle, name); 
288 return p; 
289} 
290 
291int 
292_citrus_load_module(_citrus_module_t *rhandle, const char *encname) 
293{ 
294 const char *p; 
295 char path[PATH_MAX]; 
296 int maj, min; 
297 void *handle; 
298 
299 _DIAGASSERT(rhandle != NULL); 
300 
301 if (_pathI18nModule == NULL) { 
302 p = getenv("PATH_I18NMODULE"); 
303 if (p != NULL && !issetugid()) { 
304 _pathI18nModule = strdup(p); 
305 if (_pathI18nModule == NULL) 
306 return ENOMEM; 
307 } else 
308 _pathI18nModule = _PATH_I18NMODULE; 
309 } 
310 
311 (void)snprintf(path, sizeof(path), "lib%s", encname); 
312 maj = I18NMODULE_MAJOR; 
313 min = -1; 
314 p = _findshlib(path, &maj, &min); 
315 if (!p) 
316 return (EINVAL); 
317 handle = dlopen(p, RTLD_LAZY); 
318 if (!handle) 
319 return (EINVAL); 
320 
321 *rhandle = (_citrus_module_t)handle; 
322 
323 return (0); 
324} 
325 
326void 
327_citrus_unload_module(_citrus_module_t handle) 
328{ 
329 if (handle) 
330 dlclose((void *)handle); 
331} 
332#else 
333/* !_I18N_DYNAMIC */ 
334 
335void * 
336/*ARGSUSED*/ 
337_citrus_find_getops(_citrus_module_t handle, const char *modname, 
338 const char *ifname) 
339{ 
340 return (NULL); 
341} 
342 
343int 
344/*ARGSUSED*/ 
345_citrus_load_module(_citrus_module_t *rhandle, char const *modname) 
346{ 
347 return (EINVAL); 
348} 
349 
350void 
351/*ARGSUSED*/ 
352_citrus_unload_module(_citrus_module_t handle) 
353{ 
354} 
355#endif 

cvs diff -r1.6 -r1.6.28.1 src/lib/libc/citrus/citrus_namespace.h (expand / switch to unified diff)

--- src/lib/libc/citrus/citrus_namespace.h 2005/10/29 18:02:04 1.6
+++ src/lib/libc/citrus/citrus_namespace.h 2009/01/04 17:02:19 1.6.28.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: citrus_namespace.h,v 1.6 2005/10/29 18:02:04 tshiozak Exp $ */ 1/* $NetBSD: citrus_namespace.h,v 1.6.28.1 2009/01/04 17:02:19 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2003 Citrus Project, 4 * Copyright (c)2003 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -46,26 +46,28 @@ @@ -46,26 +46,28 @@
46#define _bcs_isupper _citrus_bcs_isupper 46#define _bcs_isupper _citrus_bcs_isupper
47#define _bcs_isxdigit _citrus_bcs_isxdigit 47#define _bcs_isxdigit _citrus_bcs_isxdigit
48#define _bcs_skip_nonws _citrus_bcs_skip_nonws 48#define _bcs_skip_nonws _citrus_bcs_skip_nonws
49#define _bcs_skip_nonws_len _citrus_bcs_skip_nonws_len 49#define _bcs_skip_nonws_len _citrus_bcs_skip_nonws_len
50#define _bcs_skip_ws _citrus_bcs_skip_ws 50#define _bcs_skip_ws _citrus_bcs_skip_ws
51#define _bcs_skip_ws_len _citrus_bcs_skip_ws_len 51#define _bcs_skip_ws_len _citrus_bcs_skip_ws_len
52#define _bcs_strcasecmp _citrus_bcs_strcasecmp 52#define _bcs_strcasecmp _citrus_bcs_strcasecmp
53#define _bcs_strncasecmp _citrus_bcs_strncasecmp 53#define _bcs_strncasecmp _citrus_bcs_strncasecmp
54#define _bcs_tolower _citrus_bcs_tolower 54#define _bcs_tolower _citrus_bcs_tolower
55#define _bcs_toupper _citrus_bcs_toupper 55#define _bcs_toupper _citrus_bcs_toupper
56#define _bcs_trunc_rws_len _citrus_bcs_trunc_rws_len 56#define _bcs_trunc_rws_len _citrus_bcs_trunc_rws_len
57#define _bcs_convert_to_lower _citrus_bcs_convert_to_lower 57#define _bcs_convert_to_lower _citrus_bcs_convert_to_lower
58#define _bcs_convert_to_upper _citrus_bcs_convert_to_upper 58#define _bcs_convert_to_upper _citrus_bcs_convert_to_upper
 59#define _bcs_strtol _citrus_bcs_strtol
 60#define _bcs_strtoul _citrus_bcs_strtoul
59#endif /* _CITRUS_BCS_NO_NAMESPACE */ 61#endif /* _CITRUS_BCS_NO_NAMESPACE */
60 62
61/* citrus_csmapper */ 63/* citrus_csmapper */
62#ifndef _CITRUS_CSMAPPER_NO_NAMESPACE 64#ifndef _CITRUS_CSMAPPER_NO_NAMESPACE
63#define _csmapper _citrus_csmapper 65#define _csmapper _citrus_csmapper
64#define _csmapper_open _citrus_csmapper_open 66#define _csmapper_open _citrus_csmapper_open
65#define _csmapper_close _citrus_csmapper_close 67#define _csmapper_close _citrus_csmapper_close
66#define _csmapper_convert _citrus_csmapper_convert 68#define _csmapper_convert _citrus_csmapper_convert
67#define _csmapper_init_state _citrus_csmapper_init_state 69#define _csmapper_init_state _citrus_csmapper_init_state
68#define _csmapper_get_state_size _citrus_csmapper_get_state_size 70#define _csmapper_get_state_size _citrus_csmapper_get_state_size
69#define _csmapper_get_src_max _citrus_csmapper_get_src_max 71#define _csmapper_get_src_max _citrus_csmapper_get_src_max
70#define _csmapper_get_dst_max _citrus_csmapper_get_dst_max 72#define _csmapper_get_dst_max _citrus_csmapper_get_dst_max
71#define _CSMAPPER_F_PREVENT_PIVOT _CITRUS_CSMAPPER_F_PREVENT_PIVOT 73#define _CSMAPPER_F_PREVENT_PIVOT _CITRUS_CSMAPPER_F_PREVENT_PIVOT

cvs diff -r1.12 -r1.12.6.1 src/lib/libc/citrus/modules/citrus_euc.c (expand / switch to unified diff)

--- src/lib/libc/citrus/modules/citrus_euc.c 2008/06/14 16:01:07 1.12
+++ src/lib/libc/citrus/modules/citrus_euc.c 2008/06/14 16:01:07 1.12.6.1
@@ -1,434 +0,0 @@ @@ -1,434 +0,0 @@
1/* $NetBSD: citrus_euc.c,v 1.12 2008/06/14 16:01:07 tnozaki Exp $ */ 
2 
3/*- 
4 * Copyright (c)2002 Citrus Project, 
5 * All rights reserved. 
6 * 
7 * Redistribution and use in source and binary forms, with or without 
8 * modification, are permitted provided that the following conditions 
9 * are met: 
10 * 1. Redistributions of source code must retain the above copyright 
11 * notice, this list of conditions and the following disclaimer. 
12 * 2. Redistributions in binary form must reproduce the above copyright 
13 * notice, this list of conditions and the following disclaimer in the 
14 * documentation and/or other materials provided with the distribution. 
15 * 
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
26 * SUCH DAMAGE. 
27 */ 
28 
29/*- 
30 * Copyright (c) 1993 
31 * The Regents of the University of California. All rights reserved. 
32 * 
33 * This code is derived from software contributed to Berkeley by 
34 * Paul Borman at Krystal Technologies. 
35 * 
36 * Redistribution and use in source and binary forms, with or without 
37 * modification, are permitted provided that the following conditions 
38 * are met: 
39 * 1. Redistributions of source code must retain the above copyright 
40 * notice, this list of conditions and the following disclaimer. 
41 * 2. Redistributions in binary form must reproduce the above copyright 
42 * notice, this list of conditions and the following disclaimer in the 
43 * documentation and/or other materials provided with the distribution. 
44 * 3. Neither the name of the University nor the names of its contributors 
45 * may be used to endorse or promote products derived from this software 
46 * without specific prior written permission. 
47 * 
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
58 * SUCH DAMAGE. 
59 */ 
60 
61#include <sys/cdefs.h> 
62#if defined(LIBC_SCCS) && !defined(lint) 
63__RCSID("$NetBSD: citrus_euc.c,v 1.12 2008/06/14 16:01:07 tnozaki Exp $"); 
64#endif /* LIBC_SCCS and not lint */ 
65 
66#include <assert.h> 
67#include <errno.h> 
68#include <string.h> 
69#include <stdio.h> 
70#include <stdlib.h> 
71#include <stddef.h> 
72#include <wchar.h> 
73#include <sys/types.h> 
74#include <limits.h> 
75 
76#include "citrus_namespace.h" 
77#include "citrus_types.h" 
78#include "citrus_module.h" 
79#include "citrus_ctype.h" 
80#include "citrus_stdenc.h" 
81#include "citrus_euc.h" 
82 
83 
84/* ---------------------------------------------------------------------- 
85 * private stuffs used by templates 
86 */ 
87 
88typedef struct { 
89 char ch[3]; 
90 int chlen; 
91} _EUCState; 
92 
93typedef struct { 
94 unsigned count[4]; 
95 wchar_t bits[4]; 
96 wchar_t mask; 
97 unsigned mb_cur_max; 
98} _EUCEncodingInfo; 
99 
100typedef struct { 
101 _EUCEncodingInfo ei; 
102 struct { 
103 /* for future multi-locale facility */ 
104 _EUCState s_mblen; 
105 _EUCState s_mbrlen; 
106 _EUCState s_mbrtowc; 
107 _EUCState s_mbtowc; 
108 _EUCState s_mbsrtowcs; 
109 _EUCState s_wcrtomb; 
110 _EUCState s_wcsrtombs; 
111 _EUCState s_wctomb; 
112 } states; 
113} _EUCCTypeInfo; 
114 
115#define _SS2 0x008e 
116#define _SS3 0x008f 
117 
118#define _CEI_TO_EI(_cei_) (&(_cei_)->ei) 
119#define _CEI_TO_STATE(_cei_, _func_) (_cei_)->states.s_##_func_ 
120 
121#define _FUNCNAME(m) _citrus_EUC_##m 
122#define _ENCODING_INFO _EUCEncodingInfo 
123#define _CTYPE_INFO _EUCCTypeInfo 
124#define _ENCODING_STATE _EUCState 
125#define _ENCODING_MB_CUR_MAX(_ei_) (_ei_)->mb_cur_max 
126#define _ENCODING_IS_STATE_DEPENDENT 0 
127#define _STATE_NEEDS_EXPLICIT_INIT(_ps_) 0 
128 
129 
130static __inline int 
131_citrus_EUC_cs(unsigned int c) 
132{ 
133 c &= 0xff; 
134 
135 return ((c & 0x80) ? c == _SS3 ? 3 : c == _SS2 ? 2 : 1 : 0); 
136} 
137 
138static __inline int 
139_citrus_EUC_parse_variable(_EUCEncodingInfo *ei, 
140 const void *var, size_t lenvar) 
141{ 
142 const char *v, *e; 
143 int x; 
144 
145 /* parse variable string */ 
146 if (!var) 
147 return (EFTYPE); 
148 
149 v = (const char *) var; 
150 
151 while (*v == ' ' || *v == '\t') 
152 ++v; 
153 
154 ei->mb_cur_max = 1; 
155 for (x = 0; x < 4; ++x) { 
156 ei->count[x] = (int) strtol(v, (char **)&e, 0); 
157 if (v == e || !(v = e) || ei->count[x]<1 || ei->count[x]>4) { 
158 return (EFTYPE); 
159 } 
160 if (ei->mb_cur_max < ei->count[x]) 
161 ei->mb_cur_max = ei->count[x]; 
162 while (*v == ' ' || *v == '\t') 
163 ++v; 
164 ei->bits[x] = (int) strtol(v, (char **)&e, 0); 
165 if (v == e || !(v = e)) { 
166 return (EFTYPE); 
167 } 
168 while (*v == ' ' || *v == '\t') 
169 ++v; 
170 } 
171 ei->mask = (int)strtol(v, (char **)&e, 0); 
172 if (v == e || !(v = e)) { 
173 return (EFTYPE); 
174 } 
175 
176 return 0; 
177} 
178 
179 
180static __inline void 
181/*ARGSUSED*/ 
182_citrus_EUC_init_state(_EUCEncodingInfo *ei, _EUCState *s) 
183{ 
184 memset(s, 0, sizeof(*s)); 
185} 
186 
187static __inline void 
188/*ARGSUSED*/ 
189_citrus_EUC_pack_state(_EUCEncodingInfo *ei, void *pspriv, const _EUCState *s) 
190{ 
191 memcpy(pspriv, (const void *)s, sizeof(*s)); 
192} 
193 
194static __inline void 
195/*ARGSUSED*/ 
196_citrus_EUC_unpack_state(_EUCEncodingInfo *ei, _EUCState *s, 
197 const void *pspriv) 
198{ 
199 memcpy((void *)s, pspriv, sizeof(*s)); 
200} 
201 
202static int 
203_citrus_EUC_mbrtowc_priv(_EUCEncodingInfo *ei, wchar_t *pwc, const char **s, 
204 size_t n, _EUCState *psenc, size_t *nresult) 
205{ 
206 wchar_t wchar; 
207 int c, cs, len; 
208 int chlenbak; 
209 const char *s0, *s1 = NULL; 
210 
211 _DIAGASSERT(nresult != 0); 
212 _DIAGASSERT(ei != NULL); 
213 _DIAGASSERT(psenc != NULL); 
214 _DIAGASSERT(s != NULL); 
215 
216 s0 = *s; 
217 
218 if (s0 == NULL) { 
219 _citrus_EUC_init_state(ei, psenc); 
220 *nresult = 0; /* state independent */ 
221 return (0); 
222 } 
223 
224 chlenbak = psenc->chlen; 
225 
226 /* make sure we have the first byte in the buffer */ 
227 switch (psenc->chlen) { 
228 case 0: 
229 if (n < 1) 
230 goto restart; 
231 psenc->ch[0] = *s0++; 
232 psenc->chlen = 1; 
233 n--; 
234 break; 
235 case 1: 
236 case 2: 
237 break; 
238 default: 
239 /* illgeal state */ 
240 goto encoding_error; 
241 } 
242 
243 c = ei->count[cs = _citrus_EUC_cs(psenc->ch[0] & 0xff)]; 
244 if (c == 0) 
245 goto encoding_error; 
246 while (psenc->chlen < c) { 
247 if (n < 1) 
248 goto restart; 
249 psenc->ch[psenc->chlen] = *s0++; 
250 psenc->chlen++; 
251 n--; 
252 } 
253 *s = s0; 
254 
255 switch (cs) { 
256 case 3: 
257 case 2: 
258 /* skip SS2/SS3 */ 
259 len = c - 1; 
260 s1 = &psenc->ch[1]; 
261 break; 
262 case 1: 
263 case 0: 
264 len = c; 
265 s1 = &psenc->ch[0]; 
266 break; 
267 default: 
268 goto encoding_error; 
269 } 
270 wchar = 0; 
271 while (len-- > 0) 
272 wchar = (wchar << 8) | (*s1++ & 0xff); 
273 wchar = (wchar & ~ei->mask) | ei->bits[cs]; 
274 
275 psenc->chlen = 0; 
276 if (pwc) 
277 *pwc = wchar; 
278 
279 if (!wchar) { 
280 *nresult = 0; 
281 } else { 
282 *nresult = (size_t)(c - chlenbak); 
283 } 
284 
285 return 0; 
286 
287encoding_error: 
288 psenc->chlen = 0; 
289 *nresult = (size_t)-1; 
290 return (EILSEQ); 
291 
292restart: 
293 *nresult = (size_t)-2; 
294 *s = s0; 
295 return (0); 
296} 
297 
298static int 
299_citrus_EUC_wcrtomb_priv(_EUCEncodingInfo *ei, char *s, size_t n, wchar_t wc, 
300 _EUCState *psenc, size_t *nresult) 
301{ 
302 wchar_t m, nm; 
303 int cs, i, ret; 
304 
305 _DIAGASSERT(ei != NULL); 
306 _DIAGASSERT(nresult != 0); 
307 _DIAGASSERT(s != NULL); 
308 
309 m = wc & ei->mask; 
310 nm = wc & ~m; 
311 
312 for (cs = 0; 
313 cs < sizeof(ei->count)/sizeof(ei->count[0]); 
314 cs++) { 
315 if (m == ei->bits[cs]) 
316 break; 
317 } 
318 /* fallback case - not sure if it is necessary */ 
319 if (cs == sizeof(ei->count)/sizeof(ei->count[0])) 
320 cs = 1; 
321 
322 i = ei->count[cs]; 
323 if (n < i) { 
324 ret = E2BIG; 
325 goto err; 
326 } 
327 m = (cs) ? 0x80 : 0x00; 
328 switch (cs) { 
329 case 2: 
330 *s++ = _SS2; 
331 i--; 
332 break; 
333 case 3: 
334 *s++ = _SS3; 
335 i--; 
336 break; 
337 } 
338 
339 while (i-- > 0) 
340 *s++ = ((nm >> (i << 3)) & 0xff) | m; 
341 
342 *nresult = (size_t)ei->count[cs]; 
343 return 0; 
344 
345err: 
346 *nresult = (size_t)-1; 
347 return ret; 
348} 
349 
350static __inline int 
351/*ARGSUSED*/ 
352_citrus_EUC_stdenc_wctocs(_EUCEncodingInfo * __restrict ei, 
353 _csid_t * __restrict csid, 
354 _index_t * __restrict idx, wchar_t wc) 
355{ 
356 wchar_t m, nm; 
357 
358 _DIAGASSERT(ei != NULL && csid != NULL && idx != NULL); 
359 
360 m = wc & ei->mask; 
361 nm = wc & ~m; 
362 
363 *csid = (_citrus_csid_t)m; 
364 *idx = (_citrus_index_t)nm; 
365 
366 return (0); 
367} 
368 
369static __inline int 
370/*ARGSUSED*/ 
371_citrus_EUC_stdenc_cstowc(_EUCEncodingInfo * __restrict ei, 
372 wchar_t * __restrict wc, 
373 _csid_t csid, _index_t idx) 
374{ 
375 
376 _DIAGASSERT(ei != NULL && wc != NULL); 
377 
378 if ((csid & ~ei->mask) != 0 || (idx & ei->mask) != 0) 
379 return (EINVAL); 
380 
381 *wc = (wchar_t)csid | (wchar_t)idx; 
382 
383 return (0); 
384} 
385 
386static __inline int 
387/*ARGSUSED*/ 
388_citrus_EUC_stdenc_get_state_desc_generic(_EUCEncodingInfo * __restrict ei, 
389 _EUCState * __restrict psenc, 
390 int * __restrict rstate) 
391{ 
392 
393 if (psenc->chlen == 0) 
394 *rstate = _STDENC_SDGEN_INITIAL; 
395 else 
396 *rstate = _STDENC_SDGEN_INCOMPLETE_CHAR; 
397 
398 return 0; 
399} 
400 
401static int 
402/*ARGSUSED*/ 
403_citrus_EUC_encoding_module_init(_EUCEncodingInfo * __restrict ei, 
404 const void * __restrict var, size_t lenvar) 
405{ 
406 
407 _DIAGASSERT(ei != NULL); 
408 
409 return (_citrus_EUC_parse_variable(ei, var, lenvar)); 
410} 
411 
412static void 
413/*ARGSUSED*/ 
414_citrus_EUC_encoding_module_uninit(_EUCEncodingInfo * __restrict ei) 
415{ 
416} 
417 
418/* ---------------------------------------------------------------------- 
419 * public interface for ctype 
420 */ 
421 
422_CITRUS_CTYPE_DECLS(EUC); 
423_CITRUS_CTYPE_DEF_OPS(EUC); 
424 
425#include "citrus_ctype_template.h" 
426 
427/* ---------------------------------------------------------------------- 
428 * public interface for stdenc 
429 */ 
430 
431_CITRUS_STDENC_DECLS(EUC); 
432_CITRUS_STDENC_DEF_OPS(EUC); 
433 
434#include "citrus_stdenc_template.h" 

cvs diff -r1.163 -r1.163.6.1 src/lib/libc/gen/Makefile.inc (expand / switch to unified diff)

--- src/lib/libc/gen/Makefile.inc 2008/09/05 04:52:34 1.163
+++ src/lib/libc/gen/Makefile.inc 2008/09/05 04:52:34 1.163.6.1
@@ -1,155 +0,0 @@ @@ -1,155 +0,0 @@
1# $NetBSD: Makefile.inc,v 1.163 2008/09/05 04:52:34 lukem Exp $ 
2# from: @(#)Makefile.inc 8.6 (Berkeley) 5/4/95 
3 
4# gen sources 
5.PATH: ${ARCHDIR}/gen ${.CURDIR}/gen 
6 
7SRCS+= _errno.c alarm.c alphasort.c arc4random.c assert.c basename.c clock.c \ 
8 closedir.c closefrom.c confstr.c ctermid.c ctype_.c daemon.c \ 
9 dehumanize_number.c devname.c dirname.c disklabel.c err.c errx.c \ 
10 errlist.c errno.c execl.c execle.c execlp.c execv.c execvp.c \ 
11 extattr.c fmtcheck.c fmtmsg.c fnmatch.c fstab.c ftok.c \ 
12 fts.c ftw.c getbsize.c getcap.c getcwd.c \ 
13 getdevmajor.c getdomainname.c getgrent.c \ 
14 getgrouplist.c getgroupmembership.c gethostname.c \ 
15 getloadavg.c getlogin.c getmntinfo.c \ 
16 getnetgrent.c getpagesize.c \ 
17 getpass.c getprogname.c getpwent.c getttyent.c \ 
18 getusershell.c glob.c humanize_number.c initgroups.c \ 
19 isascii.c isatty.c isctype.c lockf.c nftw.c \ 
20 nice.c nlist.c nlist_aout.c \ 
21 nlist_coff.c nlist_ecoff.c nlist_elf32.c nlist_elf64.c opendir.c \ 
22 pause.c popen.c psignal.c pthread_atfork.c pwcache.c \ 
23 pw_scan.c raise.c randomid.c rb.c readdir.c rewinddir.c \ 
24 scandir.c seekdir.c setdomainname.c \ 
25 sethostname.c setjmperr.c setmode.c setproctitle.c setprogname.c \ 
26 shquote.c shquotev.c sighold.c sigignore.c siginterrupt.c \ 
27 siglist.c signal.c signame.c sigrelse.c \ 
28 sigset.c sigsetops.c sleep.c \ 
29 stringlist.c sysconf.c sysctl.c sysctlbyname.c sysctlgetmibinfo.c \ 
30 sysctlnametomib.c syslog.c telldir.c time.c \ 
31 times.c toascii.c tolower_.c ttyname.c ttyslot.c \ 
32 toupper_.c ualarm.c ulimit.c uname.c unvis.c usleep.c utime.c utmp.c \ 
33 utmpx.c valloc.c vis.c wait.c wait3.c waitpid.c warn.c warnx.c \ 
34 vwarn.c vwarnx.c verr.c verrx.c wordexp.c 
35 
36# indirect reference stubs, to be removed soon. 
37SRCS+= _err.c _errx.c \ 
38 _sysconf.c _verr.c _verrx.c _vwarn.c _vwarnx.c _warn.c _warnx.c 
39 
40# uses alloca 
41COPTS.execvp.c = -Wno-stack-protector 
42COPTS.execl.c = -Wno-stack-protector 
43COPTS.execle.c = -Wno-stack-protector 
44COPTS.execlp.c = -Wno-stack-protector 
45 
46# machine-dependent gen sources 
47# m-d Makefile.inc must include sources for: 
48# _setjmp() bswap16() bswap32() bswap64() fabs() infinity 
49# isinf() setjmp() sigsetjmp() 
50 
51.include "${ARCHDIR}/gen/Makefile.inc" 
52 
53MAN+= alarm.3 arc4random.3 basename.3 bswap.3 clock.3 closefrom.3 confstr.3 \ 
54 cpuset.3 ctermid.3 ctype.3 daemon.3 devname.3 directory.3 dirname.3 \ 
55 endutxent.3 err.3 exec.3 extattr.3 \ 
56 fmtcheck.3 fmtmsg.3 fnmatch.3 fpclassify.3 fpgetmask.3 \ 
57 ftok.3 fts.3 ftw.3 \ 
58 getbsize.3 cgetcap.3 getcwd.3 getdevmajor.3 \ 
59 getdomainname.3 getdiskbyname.3 getfsent.3 \ 
60 getgrent.3 getgrouplist.3 gethostname.3 getlastlogx.3 getloadavg.3 \ 
61 getmntinfo.3 getnetgrent.3 getpagesize.3 getpass.3 \ 
62 getprogname.3 getpwent.3 getttyent.3 getusershell.3 glob.3 \ 
63 humanize_number.3 \ 
64 initgroups.3 isalnum.3 isalpha.3 isascii.3 isblank.3 iscntrl.3 \ 
65 isdigit.3 isfinite.3 isgraph.3 isgreater.3 isinf.3 islower.3 isnan.3 \ 
66 isnormal.3 isprint.3 ispunct.3 isspace.3 isupper.3 isxdigit.3 \ 
67 lockf.3 _lwp_makecontext.3 makecontext.3 \ 
68 nice.3 nlist.3 \ 
69 pause.3 popen.3 psignal.3 pwcache.3 pthread_atfork.3 \ 
70 raise.3 randomid.3 realpath.3 scandir.3 setjmp.3 setmode.3 \ 
71 setproctitle.3 shquote.3 sighold.3 sigignore.3 siginterrupt.3 \ 
72 signal.3 signbit.3 sigrelse.3 sigset.3 sigsetops.3 sleep.3 \ 
73 stringlist.3 sysconf.3 sysctl.3 syslog.3 time.3 times.3 \ 
74 timezone.3 toascii.3 tolower.3 toupper.3 ttyname.3 \ 
75 ualarm.3 ulimit.3 uname.3 unvis.3 usleep.3 utime.3 valloc.3 vis.3 \ 
76 wordexp.3 
77 
78MLINKS+=bswap.3 bswap16.3 bswap.3 bswap32.3 bswap.3 bswap64.3 
79MLINKS+=cpuset.3 cpuset_create.3 cpuset.3 cpuset_destroy.3 \ 
80 cpuset.3 cpuset_zero.3 cpuset.3 cpuset_set.3 cpuset.3 cpuset_clr.3 \ 
81 cpuset.3 cpuset_isset.3 cpuset.3 cpuset_size.3 
82MLINKS+=directory.3 closedir.3 directory.3 dirfd.3 directory.3 opendir.3 \ 
83 directory.3 readdir.3 directory.3 readdir_r.3 directory.3 \ 
84 rewinddir.3 directory.3 seekdir.3 directory.3 telldir.3 
85MLINKS+=endutxent.3 getutxent.3 endutxent.3 getutxid.3 \ 
86 endutxent.3 getutxline.3 endutxent.3 pututxline.3 \ 
87 endutxent.3 setutxent.3 
88MLINKS+=err.3 verr.3 err.3 errx.3 err.3 verrx.3 err.3 warn.3 err.3 vwarn.3 \ 
89 err.3 warnx.3 err.3 vwarnx.3 
90MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 execv.3 \ 
91 exec.3 execvp.3 exec.3 exect.3 
92MLINKS+=extattr.3 extattr_namespace_to_string.3 \ 
93 extattr.3 extattr_string_to_namespace.3 
94MLINKS+=fpgetmask.3 fpgetround.3 fpgetmask.3 fpgetsticky.3 \ 
95 fpgetmask.3 fpsetmask.3 fpgetmask.3 fpsetround.3 \ 
96 fpgetmask.3 fpsetsticky.3 
97MLINKS+=fts.3 fts_open.3 fts.3 fts_read.3 fts.3 fts_children.3 \ 
98 fts.3 fts_set.3 fts.3 fts_close.3 
99MLINKS+=ftw.3 nftw.3 
100MLINKS+=cgetcap.3 cgetclose.3 cgetcap.3 cgetent.3 \ 
101 cgetcap.3 cgetfirst.3 cgetcap.3 cgetmatch.3 cgetcap.3 cgetnext.3 \ 
102 cgetcap.3 cgetnum.3 cgetcap.3 cgetset.3 cgetcap.3 cgetstr.3 \ 
103 cgetcap.3 cgetustr.3 
104MLINKS+=getcwd.3 getwd.3 
105MLINKS+=getdiskbyname.3 setdisktab.3 
106MLINKS+=getdomainname.3 setdomainname.3 
107MLINKS+=getfsent.3 endfsent.3 getfsent.3 getfsfile.3 getfsent.3 getfsspec.3 \ 
108 getfsent.3 setfsent.3 
109MLINKS+=getgrent.3 endgrent.3 getgrent.3 setgroupent.3 getgrent.3 getgrgid.3 \ 
110 getgrent.3 getgrnam.3 getgrent.3 setgrent.3 
111MLINKS+=getgrent.3 getgrgid_r.3 getgrent.3 getgrnam_r.3 getgrent.3 getgrent_r.3 
112MLINKS+=getgrouplist.3 getgroupmembership.3 
113MLINKS+=gethostname.3 sethostname.3 
114MLINKS+=getlastlogx.3 getutmp.3 getlastlogx.3 getutmpx.3 
115MLINKS+=getlastlogx.3 updlastlogx.3 getlastlogx.3 updwtmpx.3 
116MLINKS+=getlastlogx.3 utmpxname.3 
117MLINKS+=getnetgrent.3 endnetgrent.3 getnetgrent.3 innetgr.3 \ 
118 getnetgrent.3 setnetgrent.3 
119MLINKS+=getprogname.3 setprogname.3 
120MLINKS+=getpwent.3 endpwent.3 getpwent.3 setpassent.3 getpwent.3 getpwnam.3 \ 
121 getpwent.3 getpwuid.3 getpwent.3 setpwent.3 
122MLINKS+=getpwent.3 getpwnam_r.3 getpwent.3 getpwuid_r.3 getpwent.3 getpwent_r.3 
123# getpwent.3 setpwfile.3 - deprecated 
124MLINKS+=getttyent.3 endttyent.3 getttyent.3 getttynam.3 \ 
125 getttyent.3 setttyent.3 getttyent.3 setttyentpath.3 
126MLINKS+=getusershell.3 endusershell.3 getusershell.3 setusershell.3 
127MLINKS+=glob.3 globfree.3 
128MLINKS+=humanize_number.3 dehumanize_number.3 
129MLINKS+=makecontext.3 swapcontext.3 
130MLINKS+=popen.3 pclose.3 
131MLINKS+=psignal.3 sys_siglist.3 psignal.3 sys_signame.3 
132MLINKS+=pwcache.3 user_from_uid.3 pwcache.3 group_from_gid.3 
133MLINKS+=pwcache.3 uid_from_user.3 pwcache.3 gid_from_group.3 
134MLINKS+=pwcache.3 pwcache_userdb.3 pwcache.3 pwcache_groupdb.3 
135MLINKS+=randomid.3 randomid_new.3 randomid.3 randomid_delete.3 
136MLINKS+=scandir.3 alphasort.3 
137MLINKS+=setjmp.3 _longjmp.3 setjmp.3 _setjmp.3 setjmp.3 longjmp.3 \ 
138 setjmp.3 longjmperror.3 setjmp.3 sigsetjmp.3 setjmp.3 siglongjmp.3 
139MLINKS+=setmode.3 getmode.3 
140MLINKS+=shquote.3 shquotev.3 
141MLINKS+=sigsetops.3 sigemptyset.3 sigsetops.3 sigfillset.3 \ 
142 sigsetops.3 sigaddset.3 sigsetops.3 sigdelset.3 \ 
143 sigsetops.3 sigismember.3 
144MLINKS+=stringlist.3 sl_init.3 stringlist.3 sl_free.3 stringlist.3 sl_add.3 \ 
145 stringlist.3 sl_find.3 
146MLINKS+=sysctl.3 sysctlbyname.3 sysctl.3 sysctlgetmibinfo.3 \ 
147 sysctl.3 sysctlnametomib.3 
148MLINKS+=syslog.3 closelog.3 syslog.3 openlog.3 syslog.3 setlogmask.3 \ 
149 syslog.3 vsyslog.3 
150MLINKS+=syslog.3 closelog_r.3 syslog.3 openlog_r.3 syslog.3 setlogmask_r.3 \ 
151 syslog.3 syslog_r.3 syslog.3 vsyslog_r.3 
152MLINKS+=ttyname.3 isatty.3 ttyname.3 ttyslot.3 ttyname.3 ttyname_r.3 
153MLINKS+=unvis.3 strunvis.3 unvis.3 strunvisx.3 
154MLINKS+=vis.3 svis.3 vis.3 strvis.3 vis.3 strvisx.3 vis.3 strsvis.3 \ 
155 vis.3 strsvisx.3 

cvs diff -r1.26 -r1.26.28.1 src/lib/libc/gen/directory.3 (expand / switch to unified diff)

--- src/lib/libc/gen/directory.3 2006/05/18 15:30:36 1.26
+++ src/lib/libc/gen/directory.3 2009/01/04 17:02:19 1.26.28.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: directory.3,v 1.26 2006/05/18 15:30:36 christos Exp $ 1.\" $NetBSD: directory.3,v 1.26.28.1 2009/01/04 17:02:19 christos Exp $
2.\" 2.\"
3.\" Copyright (c) 1983, 1991, 1993 3.\" Copyright (c) 1983, 1991, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
5.\" 5.\"
6.\" Redistribution and use in source and binary forms, with or without 6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions 7.\" modification, are permitted provided that the following conditions
8.\" are met: 8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright 9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer. 10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the 12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution. 13.\" documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors 14.\" 3. Neither the name of the University nor the names of its contributors
@@ -19,70 +19,82 @@ @@ -19,70 +19,82 @@
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE. 28.\" SUCH DAMAGE.
29.\" 29.\"
30.\" @(#)directory.3 8.1 (Berkeley) 6/4/93 30.\" @(#)directory.3 8.1 (Berkeley) 6/4/93
31.\" 31.\"
32.Dd May 18, 2006 32.Dd December 5, 2008
33.Dt DIRECTORY 3 33.Dt DIRECTORY 3
34.Os 34.Os
35.Sh NAME 35.Sh NAME
 36.Nm fdopendir ,
36.Nm opendir , 37.Nm opendir ,
37.Nm readdir , 38.Nm readdir ,
38.Nm readdir_r , 39.Nm readdir_r ,
39.Nm telldir , 40.Nm telldir ,
40.Nm seekdir , 41.Nm seekdir ,
41.Nm rewinddir , 42.Nm rewinddir ,
42.Nm closedir , 43.Nm closedir ,
43.Nm dirfd 44.Nm dirfd
44.Nd directory operations 45.Nd directory operations
45.Sh LIBRARY 46.Sh LIBRARY
46.Lb libc 47.Lb libc
47.Sh SYNOPSIS 48.Sh SYNOPSIS
48.In dirent.h 49.In dirent.h
49.Ft DIR * 50.Ft DIR *
 51.Fn fdopendir "int fd"
 52.Ft DIR *
50.Fn opendir "const char *filename" 53.Fn opendir "const char *filename"
51.Ft struct dirent * 54.Ft struct dirent *
52.Fn readdir "DIR *dirp" 55.Fn readdir "DIR *dirp"
53.Ft int 56.Ft int
54.Fn readdir_r "DIR * restrict dirp" "struct dirent * restrict entry" "struct dirent ** restrict result" 57.Fn readdir_r "DIR * restrict dirp" "struct dirent * restrict entry" "struct dirent ** restrict result"
55.Ft long 58.Ft long
56.Fn telldir "DIR *dirp" 59.Fn telldir "DIR *dirp"
57.Ft void 60.Ft void
58.Fn seekdir "DIR *dirp" "long loc" 61.Fn seekdir "DIR *dirp" "long loc"
59.Ft void 62.Ft void
60.Fn rewinddir "DIR *dirp" 63.Fn rewinddir "DIR *dirp"
61.Ft int 64.Ft int
62.Fn closedir "DIR *dirp" 65.Fn closedir "DIR *dirp"
63.Ft int 66.Ft int
64.Fn dirfd "DIR *dirp" 67.Fn dirfd "DIR *dirp"
65.Sh DESCRIPTION 68.Sh DESCRIPTION
66The 69The
67.Fn opendir 70.Fn opendir
68function 71function opens the directory named by
69opens the directory named by 72.Fa filename
70.Fa filename , 73and associates a
71associates a 
72.Em directory stream 74.Em directory stream
73with it 75with it.
74and 76.Pp
75returns a pointer to be used to identify the 77The
 78.Fn fdopendir
 79function associates a
 80.Em directory stream
 81with the directory file descriptor
 82.Fa fd .
 83The file descriptor
 84.Fa fd
 85must not be used further by the caller in any way.
 86.Pp
 87Both functions return a pointer to be used to identify the
76.Em directory stream 88.Em directory stream
77in subsequent operations. 89in subsequent operations.
78The pointer 90The pointer
79.Dv NULL 91.Dv NULL
80is returned if 92is returned if
81.Fa filename 93.Fa filename
82cannot be accessed, or if it cannot 94cannot be accessed, or if it cannot
83.Xr malloc 3 95.Xr malloc 3
84enough memory to hold the whole thing. 96enough memory to hold the whole thing.
85.Pp 97.Pp
86The 98The
87.Fn readdir 99.Fn readdir
88function 100function
@@ -90,27 +102,28 @@ returns a pointer to the next directory  @@ -90,27 +102,28 @@ returns a pointer to the next directory
90It returns 102It returns
91.Dv NULL 103.Dv NULL
92upon reaching the end of the directory or detecting an invalid 104upon reaching the end of the directory or detecting an invalid
93.Fn seekdir 105.Fn seekdir
94operation. 106operation.
95.Pp 107.Pp
96The 108The
97.Fn readdir_r 109.Fn readdir_r
98function 110function
99provides the same functionality as 111provides the same functionality as
100.Fn readdir , 112.Fn readdir ,
101but the caller must provide a directory 113but the caller must provide a directory
102.Fa entry 114.Fa entry
103buffer to store the results in. If the read succeeds, 115buffer to store the results in.
 116If the read succeeds,
104.Fa result 117.Fa result
105is pointed at the 118is pointed at the
106.Fa entry ; 119.Fa entry ;
107upon reaching the end of the directory 120upon reaching the end of the directory
108.Fa result 121.Fa result
109is set to 122is set to
110.Dv NULL . 123.Dv NULL .
111The 124The
112.Fn readdir_r 125.Fn readdir_r
113function 126function
114returns 0 on success or an error number to indicate failure. 127returns 0 on success or an error number to indicate failure.
115.Pp 128.Pp
116The 129The

cvs diff -r1.34 -r1.34.6.1 src/lib/libc/gen/fts.c (expand / switch to unified diff)

--- src/lib/libc/gen/fts.c 2008/09/27 15:12:00 1.34
+++ src/lib/libc/gen/fts.c 2008/09/27 15:12:00 1.34.6.1
@@ -1,1212 +0,0 @@ @@ -1,1212 +0,0 @@
1/* $NetBSD: fts.c,v 1.34 2008/09/27 15:12:00 lukem Exp $ */ 
2 
3/*- 
4 * Copyright (c) 1990, 1993, 1994 
5 * The Regents of the University of California. All rights reserved. 
6 * 
7 * Redistribution and use in source and binary forms, with or without 
8 * modification, are permitted provided that the following conditions 
9 * are met: 
10 * 1. Redistributions of source code must retain the above copyright 
11 * notice, this list of conditions and the following disclaimer. 
12 * 2. Redistributions in binary form must reproduce the above copyright 
13 * notice, this list of conditions and the following disclaimer in the 
14 * documentation and/or other materials provided with the distribution. 
15 * 3. Neither the name of the University nor the names of its contributors 
16 * may be used to endorse or promote products derived from this software 
17 * without specific prior written permission. 
18 * 
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
29 * SUCH DAMAGE. 
30 */ 
31 
32#if HAVE_NBTOOL_CONFIG_H 
33#include "nbtool_config.h" 
34#endif 
35 
36#include <sys/cdefs.h> 
37#if defined(LIBC_SCCS) && !defined(lint) 
38#if 0 
39static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94"; 
40#else 
41__RCSID("$NetBSD: fts.c,v 1.34 2008/09/27 15:12:00 lukem Exp $"); 
42#endif 
43#endif /* LIBC_SCCS and not lint */ 
44 
45#include "namespace.h" 
46#include <sys/param.h> 
47#include <sys/stat.h> 
48 
49#include <assert.h> 
50#include <dirent.h> 
51#include <errno.h> 
52#include <fcntl.h> 
53#include <fts.h> 
54#include <stdlib.h> 
55#include <string.h> 
56#include <unistd.h> 
57 
58#if ! HAVE_NBTOOL_CONFIG_H 
59#define HAVE_STRUCT_DIRENT_D_NAMLEN 
60#endif 
61 
62static FTSENT *fts_alloc(FTS *, const char *, size_t); 
63static FTSENT *fts_build(FTS *, int); 
64static void fts_free(FTSENT *); 
65static void fts_lfree(FTSENT *); 
66static void fts_load(FTS *, FTSENT *); 
67static size_t fts_maxarglen(char * const *); 
68static size_t fts_pow2(size_t); 
69static int fts_palloc(FTS *, size_t); 
70static void fts_padjust(FTS *, FTSENT *); 
71static FTSENT *fts_sort(FTS *, FTSENT *, size_t); 
72static unsigned short fts_stat(FTS *, FTSENT *, int); 
73static int fts_safe_changedir(const FTS *, const FTSENT *, int, 
74 const char *); 
75 
76#if defined(ALIGNBYTES) && defined(ALIGN) 
77#define FTS_ALLOC_ALIGNED 1 
78#else 
79#undef FTS_ALLOC_ALIGNED 
80#endif 
81 
82#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) 
83 
84#define CLR(opt) (sp->fts_options &= ~(opt)) 
85#define ISSET(opt) (sp->fts_options & (opt)) 
86#define SET(opt) (sp->fts_options |= (opt)) 
87 
88#define CHDIR(sp, path) (!ISSET(FTS_NOCHDIR) && chdir(path)) 
89#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd)) 
90 
91/* fts_build flags */ 
92#define BCHILD 1 /* fts_children */ 
93#define BNAMES 2 /* fts_children, names only */ 
94#define BREAD 3 /* fts_read */ 
95 
96#ifndef DTF_HIDEW 
97#undef FTS_WHITEOUT 
98#endif 
99 
100FTS * 
101fts_open(char * const *argv, int options, 
102 int (*compar)(const FTSENT **, const FTSENT **)) 
103{ 
104 FTS *sp; 
105 FTSENT *p, *root; 
106 size_t nitems; 
107 FTSENT *parent, *tmp = NULL; /* pacify gcc */ 
108 size_t len; 
109 
110 _DIAGASSERT(argv != NULL); 
111 
112 /* Options check. */ 
113 if (options & ~FTS_OPTIONMASK) { 
114 errno = EINVAL; 
115 return (NULL); 
116 } 
117 
118 /* Allocate/initialize the stream */ 
119 if ((sp = malloc((unsigned int)sizeof(FTS))) == NULL) 
120 return (NULL); 
121 memset(sp, 0, sizeof(FTS)); 
122 sp->fts_compar = compar; 
123 sp->fts_options = options; 
124 
125 /* Logical walks turn on NOCHDIR; symbolic links are too hard. */ 
126 if (ISSET(FTS_LOGICAL)) 
127 SET(FTS_NOCHDIR); 
128 
129 /* 
130 * Start out with 1K of path space, and enough, in any case, 
131 * to hold the user's paths. 
132 */ 
133 if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN))) 
134 goto mem1; 
135 
136 /* Allocate/initialize root's parent. */ 
137 if ((parent = fts_alloc(sp, "", 0)) == NULL) 
138 goto mem2; 
139 parent->fts_level = FTS_ROOTPARENTLEVEL; 
140 
141 /* Allocate/initialize root(s). */ 
142 for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) { 
143 /* Don't allow zero-length paths. */ 
144 if ((len = strlen(*argv)) == 0) { 
145 errno = ENOENT; 
146 goto mem3; 
147 } 
148 
149 if ((p = fts_alloc(sp, *argv, len)) == NULL) 
150 goto mem3; 
151 p->fts_level = FTS_ROOTLEVEL; 
152 p->fts_parent = parent; 
153 p->fts_accpath = p->fts_name; 
154 p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW)); 
155 
156 /* Command-line "." and ".." are real directories. */ 
157 if (p->fts_info == FTS_DOT) 
158 p->fts_info = FTS_D; 
159 
160 /* 
161 * If comparison routine supplied, traverse in sorted 
162 * order; otherwise traverse in the order specified. 
163 */ 
164 if (compar) { 
165 p->fts_link = root; 
166 root = p; 
167 } else { 
168 p->fts_link = NULL; 
169 if (root == NULL) 
170 tmp = root = p; 
171 else { 
172 tmp->fts_link = p; 
173 tmp = p; 
174 } 
175 } 
176 } 
177 if (compar && nitems > 1) 
178 root = fts_sort(sp, root, nitems); 
179 
180 /* 
181 * Allocate a dummy pointer and make fts_read think that we've just 
182 * finished the node before the root(s); set p->fts_info to FTS_INIT 
183 * so that everything about the "current" node is ignored. 
184 */ 
185 if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL) 
186 goto mem3; 
187 sp->fts_cur->fts_link = root; 
188 sp->fts_cur->fts_info = FTS_INIT; 
189 
190 /* 
191 * If using chdir(2), grab a file descriptor pointing to dot to insure 
192 * that we can get back here; this could be avoided for some paths, 
193 * but almost certainly not worth the effort. Slashes, symbolic links, 
194 * and ".." are all fairly nasty problems. Note, if we can't get the 
195 * descriptor we run anyway, just more slowly. 
196 */ 
197 if (!ISSET(FTS_NOCHDIR)) { 
198 if ((sp->fts_rfd = open(".", O_RDONLY, 0)) == -1) 
199 SET(FTS_NOCHDIR); 
200 else if (fcntl(sp->fts_rfd, F_SETFD, FD_CLOEXEC) == -1) { 
201 close(sp->fts_rfd); 
202 SET(FTS_NOCHDIR); 
203 } 
204 } 
205 
206 if (nitems == 0) 
207 fts_free(parent); 
208 
209 return (sp); 
210 
211mem3: fts_lfree(root); 
212 fts_free(parent); 
213mem2: free(sp->fts_path); 
214mem1: free(sp); 
215 return (NULL); 
216} 
217 
218static void 
219fts_load(FTS *sp, FTSENT *p) 
220{ 
221 size_t len; 
222 char *cp; 
223 
224 _DIAGASSERT(sp != NULL); 
225 _DIAGASSERT(p != NULL); 
226 
227 /* 
228 * Load the stream structure for the next traversal. Since we don't 
229 * actually enter the directory until after the preorder visit, set 
230 * the fts_accpath field specially so the chdir gets done to the right 
231 * place and the user can access the first node. From fts_open it's 
232 * known that the path will fit. 
233 */ 
234 len = p->fts_pathlen = p->fts_namelen; 
235 memmove(sp->fts_path, p->fts_name, len + 1); 
236 if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { 
237 len = strlen(++cp); 
238 memmove(p->fts_name, cp, len + 1); 
239 p->fts_namelen = len; 
240 } 
241 p->fts_accpath = p->fts_path = sp->fts_path; 
242 sp->fts_dev = p->fts_dev; 
243} 
244 
245int 
246fts_close(FTS *sp) 
247{ 
248 FTSENT *freep, *p; 
249 int saved_errno = 0; 
250 
251 _DIAGASSERT(sp != NULL); 
252 
253 /* 
254 * This still works if we haven't read anything -- the dummy structure 
255 * points to the root list, so we step through to the end of the root 
256 * list which has a valid parent pointer. 
257 */ 
258 if (sp->fts_cur) { 
259 if (ISSET(FTS_SYMFOLLOW)) 
260 (void)close(sp->fts_cur->fts_symfd); 
261 for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { 
262 freep = p; 
263 p = p->fts_link ? p->fts_link : p->fts_parent; 
264 fts_free(freep); 
265 } 
266 fts_free(p); 
267 } 
268 
269 /* Free up child linked list, sort array, path buffer. */ 
270 if (sp->fts_child) 
271 fts_lfree(sp->fts_child); 
272 if (sp->fts_array) 
273 free(sp->fts_array); 
274 free(sp->fts_path); 
275 
276 /* Return to original directory, save errno if necessary. */ 
277 if (!ISSET(FTS_NOCHDIR)) { 
278 if (fchdir(sp->fts_rfd) == -1) 
279 saved_errno = errno; 
280 (void)close(sp->fts_rfd); 
281 } 
282 
283 /* Free up the stream pointer. */ 
284 free(sp); 
285 if (saved_errno) { 
286 errno = saved_errno; 
287 return -1; 
288 } 
289 
290 return 0; 
291} 
292 
293#if !defined(__FTS_COMPAT_TAILINGSLASH) 
294 
295/* 
296 * Special case of "/" at the end of the path so that slashes aren't 
297 * appended which would cause paths to be written as "....//foo". 
298 */ 
299#define NAPPEND(p) \ 
300 (p->fts_path[p->fts_pathlen - 1] == '/' \ 
301 ? p->fts_pathlen - 1 : p->fts_pathlen) 
302 
303#else /* !defined(__FTS_COMPAT_TAILINGSLASH) */ 
304 
305/* 
306 * compatibility with the old behaviour. 
307 * 
308 * Special case a root of "/" so that slashes aren't appended which would 
309 * cause paths to be written as "//foo". 
310 */ 
311 
312#define NAPPEND(p) \ 
313 (p->fts_level == FTS_ROOTLEVEL && p->fts_pathlen == 1 && \ 
314 p->fts_path[0] == '/' ? 0 : p->fts_pathlen) 
315 
316#endif /* !defined(__FTS_COMPAT_TAILINGSLASH) */ 
317 
318FTSENT * 
319fts_read(FTS *sp) 
320{ 
321 FTSENT *p, *tmp; 
322 int instr; 
323 char *t; 
324 int saved_errno; 
325 
326 _DIAGASSERT(sp != NULL); 
327 
328 /* If finished or unrecoverable error, return NULL. */ 
329 if (sp->fts_cur == NULL || ISSET(FTS_STOP)) 
330 return (NULL); 
331 
332 /* Set current node pointer. */ 
333 p = sp->fts_cur; 
334 
335 /* Save and zero out user instructions. */ 
336 instr = p->fts_instr; 
337 p->fts_instr = FTS_NOINSTR; 
338 
339 /* Any type of file may be re-visited; re-stat and re-turn. */ 
340 if (instr == FTS_AGAIN) { 
341 p->fts_info = fts_stat(sp, p, 0); 
342 return (p); 
343 } 
344 
345 /* 
346 * Following a symlink -- SLNONE test allows application to see 
347 * SLNONE and recover. If indirecting through a symlink, have 
348 * keep a pointer to current location. If unable to get that 
349 * pointer, follow fails. 
350 */ 
351 if (instr == FTS_FOLLOW && 
352 (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { 
353 p->fts_info = fts_stat(sp, p, 1); 
354 if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { 
355 if ((p->fts_symfd = open(".", O_RDONLY, 0)) == -1) { 
356 p->fts_errno = errno; 
357 p->fts_info = FTS_ERR; 
358 } else if (fcntl(p->fts_symfd, F_SETFD, FD_CLOEXEC) == -1) { 
359 p->fts_errno = errno; 
360 p->fts_info = FTS_ERR; 
361 close(p->fts_symfd); 
362 } else 
363 p->fts_flags |= FTS_SYMFOLLOW; 
364 } 
365 return (p); 
366 } 
367 
368 /* Directory in pre-order. */ 
369 if (p->fts_info == FTS_D) { 
370 /* If skipped or crossed mount point, do post-order visit. */ 
371 if (instr == FTS_SKIP || 
372 (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) { 
373 if (p->fts_flags & FTS_SYMFOLLOW) 
374 (void)close(p->fts_symfd); 
375 if (sp->fts_child) { 
376 fts_lfree(sp->fts_child); 
377 sp->fts_child = NULL; 
378 } 
379 p->fts_info = FTS_DP; 
380 return (p); 
381 } 
382 
383 /* Rebuild if only read the names and now traversing. */ 
384 if (sp->fts_child && ISSET(FTS_NAMEONLY)) { 
385 CLR(FTS_NAMEONLY); 
386 fts_lfree(sp->fts_child); 
387 sp->fts_child = NULL; 
388 } 
389 
390 /* 
391 * Cd to the subdirectory. 
392 * 
393 * If have already read and now fail to chdir, whack the list 
394 * to make the names come out right, and set the parent errno 
395 * so the application will eventually get an error condition. 
396 * Set the FTS_DONTCHDIR flag so that when we logically change 
397 * directories back to the parent we don't do a chdir. 
398 * 
399 * If haven't read do so. If the read fails, fts_build sets 
400 * FTS_STOP or the fts_info field of the node. 
401 */ 
402 if (sp->fts_child) { 
403 if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) { 
404 p->fts_errno = errno; 
405 p->fts_flags |= FTS_DONTCHDIR; 
406 for (p = sp->fts_child; p; p = p->fts_link) 
407 p->fts_accpath = 
408 p->fts_parent->fts_accpath; 
409 } 
410 } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) { 
411 if (ISSET(FTS_STOP)) 
412 return (NULL); 
413 return (p); 
414 } 
415 p = sp->fts_child; 
416 sp->fts_child = NULL; 
417 goto name; 
418 } 
419 
420 /* Move to the next node on this level. */ 
421next: tmp = p; 
422 if ((p = p->fts_link) != NULL) { 
423 fts_free(tmp); 
424 
425 /* 
426 * If reached the top, return to the original directory, and 
427 * load the paths for the next root. 
428 */ 
429 if (p->fts_level == FTS_ROOTLEVEL) { 
430 if (FCHDIR(sp, sp->fts_rfd)) { 
431 SET(FTS_STOP); 
432 return (NULL); 
433 } 
434 fts_load(sp, p); 
435 return (sp->fts_cur = p); 
436 } 
437 
438 /* 
439 * User may have called fts_set on the node. If skipped, 
440 * ignore. If followed, get a file descriptor so we can 
441 * get back if necessary. 
442 */ 
443 if (p->fts_instr == FTS_SKIP) 
444 goto next; 
445 if (p->fts_instr == FTS_FOLLOW) { 
446 p->fts_info = fts_stat(sp, p, 1); 
447 if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { 
448 if ((p->fts_symfd = 
449 open(".", O_RDONLY, 0)) == -1) { 
450 p->fts_errno = errno; 
451 p->fts_info = FTS_ERR; 
452 } else if (fcntl(p->fts_symfd, F_SETFD, FD_CLOEXEC) == -1) { 
453 p->fts_errno = errno; 
454 p->fts_info = FTS_ERR; 
455 close(p->fts_symfd); 
456 } else 
457 p->fts_flags |= FTS_SYMFOLLOW; 
458 } 
459 p->fts_instr = FTS_NOINSTR; 
460 } 
461 
462name: t = sp->fts_path + NAPPEND(p->fts_parent); 
463 *t++ = '/'; 
464 memmove(t, p->fts_name, (size_t)(p->fts_namelen + 1)); 
465 return (sp->fts_cur = p); 
466 } 
467 
468 /* Move up to the parent node. */ 
469 p = tmp->fts_parent; 
470 fts_free(tmp); 
471 
472 if (p->fts_level == FTS_ROOTPARENTLEVEL) { 
473 /* 
474 * Done; free everything up and set errno to 0 so the user 
475 * can distinguish between error and EOF. 
476 */ 
477 fts_free(p); 
478 errno = 0; 
479 return (sp->fts_cur = NULL); 
480 } 
481 
482 /* Nul terminate the pathname. */ 
483 sp->fts_path[p->fts_pathlen] = '\0'; 
484 
485 /* 
486 * Return to the parent directory. If at a root node or came through 
487 * a symlink, go back through the file descriptor. Otherwise, cd up 
488 * one directory. 
489 */ 
490 if (p->fts_level == FTS_ROOTLEVEL) { 
491 if (FCHDIR(sp, sp->fts_rfd)) { 
492 SET(FTS_STOP); 
493 return (NULL); 
494 } 
495 } else if (p->fts_flags & FTS_SYMFOLLOW) { 
496 if (FCHDIR(sp, p->fts_symfd)) { 
497 saved_errno = errno; 
498 (void)close(p->fts_symfd); 
499 errno = saved_errno; 
500 SET(FTS_STOP); 
501 return (NULL); 
502 } 
503 (void)close(p->fts_symfd); 
504 } else if (!(p->fts_flags & FTS_DONTCHDIR) && 
505 fts_safe_changedir(sp, p->fts_parent, -1, "..")) { 
506 SET(FTS_STOP); 
507 return (NULL); 
508 } 
509 p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP; 
510 return (sp->fts_cur = p); 
511} 
512 
513/* 
514 * Fts_set takes the stream as an argument although it's not used in this 
515 * implementation; it would be necessary if anyone wanted to add global 
516 * semantics to fts using fts_set. An error return is allowed for similar 
517 * reasons. 
518 */ 
519/* ARGSUSED */ 
520int 
521fts_set(FTS *sp, FTSENT *p, int instr) 
522{ 
523 
524 _DIAGASSERT(sp != NULL); 
525 _DIAGASSERT(p != NULL); 
526 
527 if (instr && instr != FTS_AGAIN && instr != FTS_FOLLOW && 
528 instr != FTS_NOINSTR && instr != FTS_SKIP) { 
529 errno = EINVAL; 
530 return (1); 
531 } 
532 p->fts_instr = instr; 
533 return (0); 
534} 
535 
536FTSENT * 
537fts_children(FTS *sp, int instr) 
538{ 
539 FTSENT *p; 
540 int fd; 
541 
542 _DIAGASSERT(sp != NULL); 
543 
544 if (instr && instr != FTS_NAMEONLY) { 
545 errno = EINVAL; 
546 return (NULL); 
547 } 
548 
549 /* Set current node pointer. */ 
550 p = sp->fts_cur; 
551 
552 /* 
553 * Errno set to 0 so user can distinguish empty directory from 
554 * an error. 
555 */ 
556 errno = 0; 
557 
558 /* Fatal errors stop here. */ 
559 if (ISSET(FTS_STOP)) 
560 return (NULL); 
561 
562 /* Return logical hierarchy of user's arguments. */ 
563 if (p->fts_info == FTS_INIT) 
564 return (p->fts_link); 
565 
566 /* 
567 * If not a directory being visited in pre-order, stop here. Could 
568 * allow FTS_DNR, assuming the user has fixed the problem, but the 
569 * same effect is available with FTS_AGAIN. 
570 */ 
571 if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */) 
572 return (NULL); 
573 
574 /* Free up any previous child list. */ 
575 if (sp->fts_child) 
576 fts_lfree(sp->fts_child); 
577 
578 if (instr == FTS_NAMEONLY) { 
579 SET(FTS_NAMEONLY); 
580 instr = BNAMES; 
581 } else 
582 instr = BCHILD; 
583 
584 /* 
585 * If using chdir on a relative path and called BEFORE fts_read does 
586 * its chdir to the root of a traversal, we can lose -- we need to 
587 * chdir into the subdirectory, and we don't know where the current 
588 * directory is, so we can't get back so that the upcoming chdir by 
589 * fts_read will work. 
590 */ 
591 if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' || 
592 ISSET(FTS_NOCHDIR)) 
593 return (sp->fts_child = fts_build(sp, instr)); 
594 
595 if ((fd = open(".", O_RDONLY, 0)) == -1) 
596 return (sp->fts_child = NULL); 
597 sp->fts_child = fts_build(sp, instr); 
598 if (fchdir(fd)) { 
599 (void)close(fd); 
600 return (NULL); 
601 } 
602 (void)close(fd); 
603 return (sp->fts_child); 
604} 
605 
606/* 
607 * This is the tricky part -- do not casually change *anything* in here. The 
608 * idea is to build the linked list of entries that are used by fts_children 
609 * and fts_read. There are lots of special cases. 
610 * 
611 * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is 
612 * set and it's a physical walk (so that symbolic links can't be directories), 
613 * we can do things quickly. First, if it's a 4.4BSD file system, the type 
614 * of the file is in the directory entry. Otherwise, we assume that the number 
615 * of subdirectories in a node is equal to the number of links to the parent. 
616 * The former skips all stat calls. The latter skips stat calls in any leaf 
617 * directories and for any files after the subdirectories in the directory have 
618 * been found, cutting the stat calls by about 2/3. 
619 */ 
620static FTSENT * 
621fts_build(FTS *sp, int type) 
622{ 
623 struct dirent *dp; 
624 FTSENT *p, *head; 
625 size_t nitems; 
626 FTSENT *cur, *tail; 
627 DIR *dirp; 
628 void *oldaddr; 
629 size_t dnamlen; 
630 int cderrno, descend, len, level, nlinks, saved_errno, nostat, doadjust; 
631 size_t maxlen; 
632#ifdef FTS_WHITEOUT 
633 int oflag; 
634#endif 
635 char *cp = NULL; /* pacify gcc */ 
636 
637 _DIAGASSERT(sp != NULL); 
638 
639 /* Set current node pointer. */ 
640 cur = sp->fts_cur; 
641 
642 /* 
643 * Open the directory for reading. If this fails, we're done. 
644 * If being called from fts_read, set the fts_info field. 
645 */ 
646#ifdef FTS_WHITEOUT 
647 if (ISSET(FTS_WHITEOUT)) 
648 oflag = DTF_NODUP|DTF_REWIND; 
649 else 
650 oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND; 
651#else 
652#define __opendir2(path, flag) opendir(path) 
653#endif 
654 if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) { 
655 if (type == BREAD) { 
656 cur->fts_info = FTS_DNR; 
657 cur->fts_errno = errno; 
658 } 
659 return (NULL); 
660 } 
661 
662 /* 
663 * Nlinks is the number of possible entries of type directory in the 
664 * directory if we're cheating on stat calls, 0 if we're not doing 
665 * any stat calls at all, -1 if we're doing stats on everything. 
666 */ 
667 if (type == BNAMES) { 
668 nlinks = 0; 
669 nostat = 1; 
670 } else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) { 
671 nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2); 
672 nostat = 1; 
673 } else { 
674 nlinks = -1; 
675 nostat = 0; 
676 } 
677 
678#ifdef notdef 
679 (void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink); 
680 (void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n", 
681 ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT)); 
682#endif 
683 /* 
684 * If we're going to need to stat anything or we want to descend 
685 * and stay in the directory, chdir. If this fails we keep going, 
686 * but set a flag so we don't chdir after the post-order visit. 
687 * We won't be able to stat anything, but we can still return the 
688 * names themselves. Note, that since fts_read won't be able to 
689 * chdir into the directory, it will have to return different path 
690 * names than before, i.e. "a/b" instead of "b". Since the node 
691 * has already been visited in pre-order, have to wait until the 
692 * post-order visit to return the error. There is a special case 
693 * here, if there was nothing to stat then it's not an error to 
694 * not be able to stat. This is all fairly nasty. If a program 
695 * needed sorted entries or stat information, they had better be 
696 * checking FTS_NS on the returned nodes. 
697 */ 
698 cderrno = 0; 
699 if (nlinks || type == BREAD) { 
700 if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) { 
701 if (nlinks && type == BREAD) 
702 cur->fts_errno = errno; 
703 cur->fts_flags |= FTS_DONTCHDIR; 
704 descend = 0; 
705 cderrno = errno; 
706 } else 
707 descend = 1; 
708 } else 
709 descend = 0; 
710 
711 /* 
712 * Figure out the max file name length that can be stored in the 
713 * current path -- the inner loop allocates more path as necessary. 
714 * We really wouldn't have to do the maxlen calculations here, we 
715 * could do them in fts_read before returning the path, but it's a 
716 * lot easier here since the length is part of the dirent structure. 
717 * 
718 * If not changing directories set a pointer so that can just append 
719 * each new name into the path. 
720 */ 
721 len = NAPPEND(cur); 
722 if (ISSET(FTS_NOCHDIR)) { 
723 cp = sp->fts_path + len; 
724 *cp++ = '/'; 
725 } 
726 len++; 
727 maxlen = sp->fts_pathlen - len; 
728 
729 level = cur->fts_level + 1; 
730 
731 /* Read the directory, attaching each entry to the `link' pointer. */ 
732 doadjust = 0; 
733 for (head = tail = NULL, nitems = 0; (dp = readdir(dirp)) != NULL;) { 
734 
735 if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) 
736 continue; 
737 
738#if defined(HAVE_STRUCT_DIRENT_D_NAMLEN) 
739 dnamlen = dp->d_namlen; 
740#else 
741 dnamlen = strlen(dp->d_name); 
742#endif 
743 if ((p = fts_alloc(sp, dp->d_name, dnamlen)) == NULL) 
744 goto mem1; 
745 if (dnamlen >= maxlen) { /* include space for NUL */ 
746 oldaddr = sp->fts_path; 
747 if (fts_palloc(sp, dnamlen + len + 1)) { 
748 /* 
749 * No more memory for path or structures. Save 
750 * errno, free up the current structure and the 
751 * structures already allocated. 
752 */ 
753mem1: saved_errno = errno; 
754 if (p) 
755 fts_free(p); 
756 fts_lfree(head); 
757 (void)closedir(dirp); 
758 errno = saved_errno; 
759 cur->fts_info = FTS_ERR; 
760 SET(FTS_STOP); 
761 return (NULL); 
762 } 
763 /* Did realloc() change the pointer? */ 
764 if (oldaddr != sp->fts_path) { 
765 doadjust = 1; 
766 if (ISSET(FTS_NOCHDIR)) 
767 cp = sp->fts_path + len; 
768 } 
769 maxlen = sp->fts_pathlen - len; 
770 } 
771 
772#if defined(__FTS_COMPAT_LENGTH) 
773 if (len + dnamlen >= USHRT_MAX) { 
774 /* 
775 * In an FTSENT, fts_pathlen is an unsigned short 
776 * so it is possible to wraparound here. 
777 * If we do, free up the current structure and the 
778 * structures already allocated, then error out 
779 * with ENAMETOOLONG. 
780 */ 
781 fts_free(p); 
782 fts_lfree(head); 
783 (void)closedir(dirp); 
784 cur->fts_info = FTS_ERR; 
785 SET(FTS_STOP); 
786 errno = ENAMETOOLONG; 
787 return (NULL); 
788 } 
789#endif 
790 p->fts_level = level; 
791 p->fts_pathlen = len + dnamlen; 
792 p->fts_parent = sp->fts_cur; 
793 
794#ifdef FTS_WHITEOUT 
795 if (dp->d_type == DT_WHT) 
796 p->fts_flags |= FTS_ISW; 
797#endif 
798 
799 if (cderrno) { 
800 if (nlinks) { 
801 p->fts_info = FTS_NS; 
802 p->fts_errno = cderrno; 
803 } else 
804 p->fts_info = FTS_NSOK; 
805 p->fts_accpath = cur->fts_accpath; 
806 } else if (nlinks == 0 
807#ifdef DT_DIR 
808 || (nostat && 
809 dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN) 
810#endif 
811 ) { 
812 p->fts_accpath = 
813 ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name; 
814 p->fts_info = FTS_NSOK; 
815 } else { 
816 /* Build a file name for fts_stat to stat. */ 
817 if (ISSET(FTS_NOCHDIR)) { 
818 p->fts_accpath = p->fts_path; 
819 memmove(cp, p->fts_name, 
820 (size_t)(p->fts_namelen + 1)); 
821 } else 
822 p->fts_accpath = p->fts_name; 
823 /* Stat it. */ 
824 p->fts_info = fts_stat(sp, p, 0); 
825 
826 /* Decrement link count if applicable. */ 
827 if (nlinks > 0 && (p->fts_info == FTS_D || 
828 p->fts_info == FTS_DC || p->fts_info == FTS_DOT)) 
829 --nlinks; 
830 } 
831 
832 /* We walk in directory order so "ls -f" doesn't get upset. */ 
833 p->fts_link = NULL; 
834 if (head == NULL) 
835 head = tail = p; 
836 else { 
837 tail->fts_link = p; 
838 tail = p; 
839 } 
840 ++nitems; 
841 } 
842 (void)closedir(dirp); 
843 
844 /* 
845 * If had to realloc the path, adjust the addresses for the rest 
846 * of the tree. 
847 */ 
848 if (doadjust) 
849 fts_padjust(sp, head); 
850 
851 /* 
852 * If not changing directories, reset the path back to original 
853 * state. 
854 */ 
855 if (ISSET(FTS_NOCHDIR)) { 
856 if (len == sp->fts_pathlen || nitems == 0) 
857 --cp; 
858 *cp = '\0'; 
859 } 
860 
861 /* 
862 * If descended after called from fts_children or after called from 
863 * fts_read and nothing found, get back. At the root level we use 
864 * the saved fd; if one of fts_open()'s arguments is a relative path 
865 * to an empty directory, we wind up here with no other way back. If 
866 * can't get back, we're done. 
867 */ 
868 if (descend && (type == BCHILD || !nitems) && 
869 (cur->fts_level == FTS_ROOTLEVEL ? 
870 FCHDIR(sp, sp->fts_rfd) : 
871 fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) { 
872 cur->fts_info = FTS_ERR; 
873 SET(FTS_STOP); 
874 return (NULL); 
875 } 
876 
877 /* If didn't find anything, return NULL. */ 
878 if (!nitems) { 
879 if (type == BREAD) 
880 cur->fts_info = FTS_DP; 
881 return (NULL); 
882 } 
883 
884 /* Sort the entries. */ 
885 if (sp->fts_compar && nitems > 1) 
886 head = fts_sort(sp, head, nitems); 
887 return (head); 
888} 
889 
890static unsigned short 
891fts_stat(FTS *sp, FTSENT *p, int follow) 
892{ 
893 FTSENT *t; 
894 dev_t dev; 
895 __fts_ino_t ino; 
896 __fts_stat_t *sbp, sb; 
897 int saved_errno; 
898 
899 _DIAGASSERT(sp != NULL); 
900 _DIAGASSERT(p != NULL); 
901 
902 /* If user needs stat info, stat buffer already allocated. */ 
903 sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp; 
904 
905#ifdef FTS_WHITEOUT 
906 /* check for whiteout */ 
907 if (p->fts_flags & FTS_ISW) { 
908 if (sbp != &sb) { 
909 memset(sbp, '\0', sizeof (*sbp)); 
910 sbp->st_mode = S_IFWHT; 
911 } 
912 return (FTS_W); 
913 } 
914#endif 
915 
916 /* 
917 * If doing a logical walk, or application requested FTS_FOLLOW, do 
918 * a stat(2). If that fails, check for a non-existent symlink. If 
919 * fail, set the errno from the stat call. 
920 */ 
921 if (ISSET(FTS_LOGICAL) || follow) { 
922 if (stat(p->fts_accpath, sbp)) { 
923 saved_errno = errno; 
924 if (!lstat(p->fts_accpath, sbp)) { 
925 errno = 0; 
926 return (FTS_SLNONE); 
927 } 
928 p->fts_errno = saved_errno; 
929 goto err; 
930 } 
931 } else if (lstat(p->fts_accpath, sbp)) { 
932 p->fts_errno = errno; 
933err: memset(sbp, 0, sizeof(*sbp)); 
934 return (FTS_NS); 
935 } 
936 
937 if (S_ISDIR(sbp->st_mode)) { 
938 /* 
939 * Set the device/inode. Used to find cycles and check for 
940 * crossing mount points. Also remember the link count, used 
941 * in fts_build to limit the number of stat calls. It is 
942 * understood that these fields are only referenced if fts_info 
943 * is set to FTS_D. 
944 */ 
945 dev = p->fts_dev = sbp->st_dev; 
946 ino = p->fts_ino = sbp->st_ino; 
947 p->fts_nlink = sbp->st_nlink; 
948 
949 if (ISDOT(p->fts_name)) 
950 return (FTS_DOT); 
951 
952 /* 
953 * Cycle detection is done by brute force when the directory 
954 * is first encountered. If the tree gets deep enough or the 
955 * number of symbolic links to directories is high enough, 
956 * something faster might be worthwhile. 
957 */ 
958 for (t = p->fts_parent; 
959 t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent) 
960 if (ino == t->fts_ino && dev == t->fts_dev) { 
961 p->fts_cycle = t; 
962 return (FTS_DC); 
963 } 
964 return (FTS_D); 
965 } 
966 if (S_ISLNK(sbp->st_mode)) 
967 return (FTS_SL); 
968 if (S_ISREG(sbp->st_mode)) 
969 return (FTS_F); 
970 return (FTS_DEFAULT); 
971} 
972 
973static FTSENT * 
974fts_sort(FTS *sp, FTSENT *head, size_t nitems) 
975{ 
976 FTSENT **ap, *p; 
977 
978 _DIAGASSERT(sp != NULL); 
979 _DIAGASSERT(head != NULL); 
980 
981 /* 
982 * Construct an array of pointers to the structures and call qsort(3). 
983 * Reassemble the array in the order returned by qsort. If unable to 
984 * sort for memory reasons, return the directory entries in their 
985 * current order. Allocate enough space for the current needs plus 
986 * 40 so don't realloc one entry at a time. 
987 */ 
988 if (nitems > sp->fts_nitems) { 
989 FTSENT **new; 
990 
991 new = realloc(sp->fts_array, sizeof(FTSENT *) * (nitems + 40)); 
992 if (new == 0) 
993 return (head); 
994 sp->fts_array = new; 
995 sp->fts_nitems = nitems + 40; 
996 } 
997 for (ap = sp->fts_array, p = head; p; p = p->fts_link) 
998 *ap++ = p; 
999 qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *), 
1000 (int (*)(const void *, const void *))sp->fts_compar); 
1001 for (head = *(ap = sp->fts_array); --nitems; ++ap) 
1002 ap[0]->fts_link = ap[1]; 
1003 ap[0]->fts_link = NULL; 
1004 return (head); 
1005} 
1006 
1007static FTSENT * 
1008fts_alloc(FTS *sp, const char *name, size_t namelen) 
1009{ 
1010 FTSENT *p; 
1011#if defined(FTS_ALLOC_ALIGNED) 
1012 size_t len; 
1013#endif 
1014 
1015 _DIAGASSERT(sp != NULL); 
1016 _DIAGASSERT(name != NULL); 
1017 
1018#if defined(FTS_ALLOC_ALIGNED) 
1019 /* 
1020 * The file name is a variable length array and no stat structure is 
1021 * necessary if the user has set the nostat bit. Allocate the FTSENT 
1022 * structure, the file name and the stat structure in one chunk, but 
1023 * be careful that the stat structure is reasonably aligned. Since the 
1024 * fts_name field is declared to be of size 1, the fts_name pointer is 
1025 * namelen + 2 before the first possible address of the stat structure. 
1026 */ 
1027 len = sizeof(FTSENT) + namelen; 
1028 if (!ISSET(FTS_NOSTAT)) 
1029 len += sizeof(*(p->fts_statp)) + ALIGNBYTES; 
1030 if ((p = malloc(len)) == NULL) 
1031 return (NULL); 
1032 
1033 if (!ISSET(FTS_NOSTAT)) 
1034 p->fts_statp = (__fts_stat_t *)ALIGN( 
1035 (unsigned long)(p->fts_name + namelen + 2)); 
1036#else 
1037 if ((p = malloc(sizeof(FTSENT) + namelen)) == NULL) 
1038 return (NULL); 
1039 
1040 if (!ISSET(FTS_NOSTAT)) 
1041 if ((p->fts_statp = malloc(sizeof(*(p->fts_statp)))) == NULL) { 
1042 free(p); 
1043 return (NULL); 
1044 } 
1045#endif 
1046 
1047 /* Copy the name plus the trailing NULL. */ 
1048 memmove(p->fts_name, name, namelen + 1); 
1049 
1050 p->fts_namelen = namelen; 
1051 p->fts_path = sp->fts_path; 
1052 p->fts_errno = 0; 
1053 p->fts_flags = 0; 
1054 p->fts_instr = FTS_NOINSTR; 
1055 p->fts_number = 0; 
1056 p->fts_pointer = NULL; 
1057 return (p); 
1058} 
1059 
1060static void 
1061fts_free(FTSENT *p) 
1062{ 
1063#if !defined(FTS_ALLOC_ALIGNED) 
1064 if (p->fts_statp) 
1065 free(p->fts_statp); 
1066#endif 
1067 free(p); 
1068} 
1069 
1070static void 
1071fts_lfree(FTSENT *head) 
1072{ 
1073 FTSENT *p; 
1074 
1075 /* XXX: head may be NULL ? */ 
1076 
1077 /* Free a linked list of structures. */ 
1078 while ((p = head) != NULL) { 
1079 head = head->fts_link; 
1080 fts_free(p); 
1081 } 
1082} 
1083 
1084static size_t 
1085fts_pow2(size_t x) 
1086{ 
1087 
1088 x--; 
1089 x |= x>>1; 
1090 x |= x>>2; 
1091 x |= x>>4; 
1092 x |= x>>8; 
1093 x |= x>>16; 
1094#if LONG_BIT > 32 
1095 x |= x>>32; 
1096#endif 
1097#if LONG_BIT > 64 
1098 x |= x>>64; 
1099#endif 
1100 x++; 
1101 return (x); 
1102} 
1103 
1104/* 
1105 * Allow essentially unlimited paths; find, rm, ls should all work on any tree. 
1106 * Most systems will allow creation of paths much longer than MAXPATHLEN, even 
1107 * though the kernel won't resolve them. Round up the new size to a power of 2, 
1108 * so we don't realloc the path 2 bytes at a time. 
1109 */ 
1110static int 
1111fts_palloc(FTS *sp, size_t size) 
1112{ 
1113 char *new; 
1114 
1115 _DIAGASSERT(sp != NULL); 
1116 
1117#ifdef __FTS_COMPAT_LENGTH 
1118 /* Protect against fts_pathlen overflow. */ 
1119 if (size > USHRT_MAX + 1) { 
1120 errno = ENAMETOOLONG; 
1121 return (1); 
1122 } 
1123#endif 
1124 size = fts_pow2(size); 
1125 new = realloc(sp->fts_path, size); 
1126 if (new == 0) 
1127 return (1); 
1128 sp->fts_path = new; 
1129 sp->fts_pathlen = size; 
1130 return (0); 
1131} 
1132 
1133/* 
1134 * When the path is realloc'd, have to fix all of the pointers in structures 
1135 * already returned. 
1136 */ 
1137static void 
1138fts_padjust(FTS *sp, FTSENT *head) 
1139{ 
1140 FTSENT *p; 
1141 char *addr; 
1142 
1143 _DIAGASSERT(sp != NULL); 
1144 
1145#define ADJUST(p) do { \ 
1146 if ((p)->fts_accpath != (p)->fts_name) \ 
1147 (p)->fts_accpath = \ 
1148 addr + ((p)->fts_accpath - (p)->fts_path); \ 
1149 (p)->fts_path = addr; \ 
1150} while (/*CONSTCOND*/0) 
1151 
1152 addr = sp->fts_path; 
1153 
1154 /* Adjust the current set of children. */ 
1155 for (p = sp->fts_child; p; p = p->fts_link) 
1156 ADJUST(p); 
1157 
1158 /* Adjust the rest of the tree, including the current level. */ 
1159 for (p = head; p->fts_level >= FTS_ROOTLEVEL;) { 
1160 ADJUST(p); 
1161 p = p->fts_link ? p->fts_link : p->fts_parent; 
1162 } 
1163} 
1164 
1165static size_t 
1166fts_maxarglen(char * const *argv) 
1167{ 
1168 size_t len, max; 
1169 
1170 _DIAGASSERT(argv != NULL); 
1171 
1172 for (max = 0; *argv; ++argv) 
1173 if ((len = strlen(*argv)) > max) 
1174 max = len; 
1175 return (max + 1); 
1176} 
1177 
1178/* 
1179 * Change to dir specified by fd or p->fts_accpath without getting 
1180 * tricked by someone changing the world out from underneath us. 
1181 * Assumes p->fts_dev and p->fts_ino are filled in. 
1182 */ 
1183static int 
1184fts_safe_changedir(const FTS *sp, const FTSENT *p, int fd, const char *path) 
1185{ 
1186 int oldfd = fd, ret = -1; 
1187 __fts_stat_t sb; 
1188 
1189 if (ISSET(FTS_NOCHDIR)) 
1190 return 0; 
1191 
1192 if (oldfd < 0 && (fd = open(path, O_RDONLY)) == -1) 
1193 return -1; 
1194 
1195 if (fstat(fd, &sb) == -1) 
1196 goto bail; 
1197 
1198 if (sb.st_ino != p->fts_ino || sb.st_dev != p->fts_dev) { 
1199 errno = ENOENT; 
1200 goto bail; 
1201 } 
1202 
1203 ret = fchdir(fd); 
1204 
1205bail: 
1206 if (oldfd < 0) { 
1207 int save_errno = errno; 
1208 (void)close(fd); 
1209 errno = save_errno; 
1210 } 
1211 return ret; 
1212} 

cvs diff -r1.16 -r1.16.40.1 src/lib/libc/gen/isctype.c (expand / switch to unified diff)

--- src/lib/libc/gen/isctype.c 2003/08/07 16:42:52 1.16
+++ src/lib/libc/gen/isctype.c 2009/01/04 17:02:19 1.16.40.1
@@ -1,159 +1,115 @@ @@ -1,159 +1,115 @@
1/* $NetBSD: isctype.c,v 1.16 2003/08/07 16:42:52 agc Exp $ */ 1/* $NetBSD: isctype.c,v 1.16.40.1 2009/01/04 17:02:19 christos Exp $ */
2 2
3/* 3/*-
4 * Copyright (c) 1989 The Regents of the University of California. 4 * Copyright (c)2008 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * (c) UNIX System Laboratories, Inc. 
7 * All or some portions of this file are derived from material licensed 
8 * to the University of California by American Telephone and Telegraph 
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 
10 * the permission of UNIX System Laboratories, Inc. 
11 * 6 *
12 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
14 * are met: 9 * are met:
15 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors 
21 * may be used to endorse or promote products derived from this software 
22 * without specific prior written permission. 
23 * 15 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE. 26 * SUCH DAMAGE.
35 */ 27 */
36 28
37#include <sys/cdefs.h> 29#include <sys/cdefs.h>
38#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
39#if 0 31__RCSID("$NetBSD: isctype.c,v 1.16.40.1 2009/01/04 17:02:19 christos Exp $");
40static char sccsid[] = "@(#)isctype.c 5.2 (Berkeley) 6/1/90"; 
41#else 
42__RCSID("$NetBSD: isctype.c,v 1.16 2003/08/07 16:42:52 agc Exp $"); 
43#endif 
44#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
45 33
46#define _ANSI_LIBRARY 34#include "namespace.h"
 35#include <sys/types.h>
47#include <ctype.h> 36#include <ctype.h>
 37#include <langinfo.h>
 38#define __SETLOCALE_SOURCE__
 39#include <locale.h>
 40#include <stdio.h>
 41#if EOF != -1
 42#error "EOF != -1"
 43#endif
48 44
49#undef isalnum 45#include "setlocale_local.h"
50int 
51isalnum(c) 
52 int c; 
53{ 
54 return((_ctype_ + 1)[c] & (_U|_L|_N)); 
55} 
56 
57#undef isalpha 
58int 
59isalpha(c) 
60 int c; 
61{ 
62 return((_ctype_ + 1)[c] & (_U|_L)); 
63} 
64 46
65#undef isblank 47#define _CTYPE_TAB(table, i) \
66int 48 (((*_current_locale())->cache.table + 1)[i])
67isblank(c) 
68 int c; 
69{ 
70 return(c == ' ' || c == '\t'); 
71} 
72 49
 50#undef isalnum
 51#undef isalpha
73#undef iscntrl 52#undef iscntrl
74int 
75iscntrl(c) 
76 int c; 
77{ 
78 return((_ctype_ + 1)[c] & _C); 
79} 
80 
81#undef isdigit 53#undef isdigit
82int 
83isdigit(c) 
84 int c; 
85{ 
86 return((_ctype_ + 1)[c] & _N); 
87} 
88 
89#undef isgraph 54#undef isgraph
90int 
91isgraph(c) 
92 int c; 
93{ 
94 return((_ctype_ + 1)[c] & (_P|_U|_L|_N)); 
95} 
96 
97#undef islower 55#undef islower
98int 
99islower(c) 
100 int c; 
101{ 
102 return((_ctype_ + 1)[c] & _L); 
103} 
104 
105#undef isprint 56#undef isprint
106int 
107isprint(c) 
108 int c; 
109{ 
110 return((_ctype_ + 1)[c] & (_P|_U|_L|_N|_B)); 
111} 
112 
113#undef ispunct 57#undef ispunct
114int 
115ispunct(c) 
116 int c; 
117{ 
118 return((_ctype_ + 1)[c] & _P); 
119} 
120 
121#undef isspace 58#undef isspace
 59#undef isupper
 60#undef isxdigit
 61
 62#define _ISCTYPE_FUNC(name, bit) \
 63int \
 64is##name(int c) \
 65{ \
 66 return (int)(_CTYPE_TAB(ctype_tab, c) & (bit)); \
 67}
 68
 69_ISCTYPE_FUNC(alnum, _U|_L|_N )
 70_ISCTYPE_FUNC(alpha, _U|_L )
 71_ISCTYPE_FUNC(cntrl, _C )
 72_ISCTYPE_FUNC(digit, _N )
 73_ISCTYPE_FUNC(graph, _P|_U|_L|_N )
 74_ISCTYPE_FUNC(lower, _L )
 75_ISCTYPE_FUNC(print, _P|_U|_L|_N|_B)
 76_ISCTYPE_FUNC(punct, _P )
 77_ISCTYPE_FUNC(space, _S )
 78_ISCTYPE_FUNC(upper, _U )
 79_ISCTYPE_FUNC(xdigit, _N|_X )
 80
 81#undef isblank
122int 82int
123isspace(c) 83isblank(int c)
124 int c; 
125{ 84{
126 return((_ctype_ + 1)[c] & _S); 85 /* XXX: FIXME */
 86 return c == ' ' || c == '\t';
127} 87}
128 88
129#undef isupper 89#undef toupper
130int 90int
131isupper(c) 91toupper(int c)
132 int c; 
133{ 92{
134 return((_ctype_ + 1)[c] & _U); 93 return (int)_CTYPE_TAB(toupper_tab, c);
135} 94}
136 95
137#undef isxdigit 96#undef tolower
138int 97int
139isxdigit(c) 98tolower(int c)
140 int c; 
141{ 99{
142 return((_ctype_ + 1)[c] & (_N|_X)); 100 return (int)_CTYPE_TAB(tolower_tab, c);
143} 101}
144 102
145#undef _toupper 103#undef _toupper
146int 104int
147_toupper(c) 105_toupper(int c)
148 int c; 
149{ 106{
150 return (c - 'a' + 'A'); 107 return (c - 'a' + 'A');
151} 108}
152 109
153#undef _tolower 110#undef _tolower
154int 111int
155_tolower(c) 112_tolower(int c)
156 int c; 
157{ 113{
158 return (c - 'A' + 'a'); 114 return (c - 'A' + 'a');
159} 115}

cvs diff -r1.33 -r1.33.12.1 src/lib/libc/gen/opendir.c (expand / switch to unified diff)

--- src/lib/libc/gen/opendir.c 2008/01/10 09:49:04 1.33
+++ src/lib/libc/gen/opendir.c 2009/01/04 17:02:19 1.33.12.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: opendir.c,v 1.33 2008/01/10 09:49:04 elad Exp $ */ 1/* $NetBSD: opendir.c,v 1.33.12.1 2009/01/04 17:02:19 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1983, 1993 4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,77 +24,99 @@ @@ -24,77 +24,99 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#if defined(LIBC_SCCS) && !defined(lint) 33#if defined(LIBC_SCCS) && !defined(lint)
34#if 0 34#if 0
35static char sccsid[] = "@(#)opendir.c 8.7 (Berkeley) 12/10/94"; 35static char sccsid[] = "@(#)opendir.c 8.7 (Berkeley) 12/10/94";
36#else 36#else
37__RCSID("$NetBSD: opendir.c,v 1.33 2008/01/10 09:49:04 elad Exp $"); 37__RCSID("$NetBSD: opendir.c,v 1.33.12.1 2009/01/04 17:02:19 christos Exp $");
38#endif 38#endif
39#endif /* LIBC_SCCS and not lint */ 39#endif /* LIBC_SCCS and not lint */
40 40
41#include "namespace.h" 41#include "namespace.h"
42#include "reentrant.h" 42#include "reentrant.h"
43#include "extern.h" 43#include "extern.h"
 44
44#include <sys/param.h> 45#include <sys/param.h>
45#include <sys/mount.h> 46#include <sys/mount.h>
46#include <sys/stat.h> 47#include <sys/stat.h>
47 48
48#include <assert.h> 49#include <assert.h>
49#include <dirent.h> 50#include <dirent.h>
50#include <errno.h> 51#include <errno.h>
51#include <fcntl.h> 52#include <fcntl.h>
52#include <stdlib.h> 53#include <stdlib.h>
53#include <string.h> 54#include <string.h>
54#include <unistd.h> 55#include <unistd.h>
55 56
56#include "dirent_private.h" 57#include "dirent_private.h"
57 58
58#define MAXITERATIONS 100 59#define MAXITERATIONS 100
59 60
 61static DIR *__opendir_common(int, const char *, int);
 62
 63__weak_alias(fdopendir,_fdopendir)
 64
60/* 65/*
61 * Open a directory. 66 * Open a directory.
62 */ 67 */
63DIR * 68DIR *
64opendir(const char *name) 69opendir(const char *name)
65{ 70{
66 71
67 _DIAGASSERT(name != NULL); 72 _DIAGASSERT(name != NULL);
68 73
69 return (__opendir2(name, DTF_HIDEW|DTF_NODUP)); 74 return (__opendir2(name, DTF_HIDEW|DTF_NODUP));
70} 75}
71 76
72DIR * 77DIR *
73__opendir2(const char *name, int flags) 78__opendir2(const char *name, int flags)
74{ 79{
75 DIR *dirp = NULL; 
76 int fd; 80 int fd;
 81
 82 if ((fd = open(name, O_RDONLY | O_NONBLOCK)) == -1)
 83 return NULL;
 84 return __opendir_common(fd, name, flags);
 85}
 86
 87#ifndef __LIBC12_SOURCE__
 88DIR *
 89_fdopendir(int fd)
 90{
 91
 92 return __opendir_common(fd, NULL, DTF_HIDEW|DTF_NODUP);
 93}
 94#endif
 95
 96static DIR *
 97__opendir_common(int fd, const char *name, int flags)
 98{
 99 DIR *dirp = NULL;
77 int serrno; 100 int serrno;
78 struct stat sb; 101 struct stat sb;
79 int pagesz; 102 int pagesz;
80 int incr; 103 int incr;
81 int unionstack, nfsdir; 104 int unionstack, nfsdir;
82 struct statvfs sfb; 105 struct statvfs sfb;
83 106
84 _DIAGASSERT(name != NULL); 107 _DIAGASSERT(name != NULL);
85 108
86 if ((fd = open(name, O_RDONLY | O_NONBLOCK)) == -1 || 109 if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
87 fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) 
88 goto error; 110 goto error;
89 if (fstat(fd, &sb) || !S_ISDIR(sb.st_mode)) { 111 if (fstat(fd, &sb) || !S_ISDIR(sb.st_mode)) {
90 errno = ENOTDIR; 112 errno = ENOTDIR;
91 goto error; 113 goto error;
92 } 114 }
93 if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) 115 if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL)
94 goto error; 116 goto error;
95 dirp->dd_buf = NULL; 117 dirp->dd_buf = NULL;
96 118
97 /* 119 /*
98 * If the machine's page size is an exact multiple of DIRBLKSIZ, 120 * If the machine's page size is an exact multiple of DIRBLKSIZ,
99 * use a buffer that is cluster boundary aligned. 121 * use a buffer that is cluster boundary aligned.
100 * Hopefully this can be a big win someday by allowing page trades 122 * Hopefully this can be a big win someday by allowing page trades

cvs diff -r1.18 -r1.18.28.1 src/lib/libc/gen/setmode.3 (expand / switch to unified diff)

--- src/lib/libc/gen/setmode.3 2005/10/01 20:08:01 1.18
+++ src/lib/libc/gen/setmode.3 2009/01/04 17:02:19 1.18.28.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: setmode.3,v 1.18 2005/10/01 20:08:01 christos Exp $ 1.\" $NetBSD: setmode.3,v 1.18.28.1 2009/01/04 17:02:19 christos Exp $
2.\" 2.\"
3.\" Copyright (c) 1989, 1991, 1993 3.\" Copyright (c) 1989, 1991, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
5.\" 5.\"
6.\" Redistribution and use in source and binary forms, with or without 6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions 7.\" modification, are permitted provided that the following conditions
8.\" are met: 8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright 9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer. 10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the 12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution. 13.\" documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors 14.\" 3. Neither the name of the University nor the names of its contributors
@@ -19,82 +19,101 @@ @@ -19,82 +19,101 @@
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE. 28.\" SUCH DAMAGE.
29.\" 29.\"
30.\" @(#)setmode.3 8.2 (Berkeley) 4/28/95 30.\" @(#)setmode.3 8.2 (Berkeley) 4/28/95
31.\" 31.\"
32.Dd October 1, 2005 32.Dd January 4, 2009
33.Dt SETMODE 3 33.Dt SETMODE 3
34.Os 34.Os
35.Sh NAME 35.Sh NAME
36.Nm getmode , 36.Nm getmode ,
37.Nm setmode 37.Nm setmode
38.Nd modify mode bits 38.Nd modify mode bits
39.Sh LIBRARY 39.Sh LIBRARY
40.Lb libc 40.Lb libc
41.Sh SYNOPSIS 41.Sh SYNOPSIS
42.In unistd.h 42.In unistd.h
43.Ft mode_t 
44.Fn getmode "const void *set" "mode_t mode" 
45.Ft void * 43.Ft void *
46.Fn setmode "const char *mode_str" 44.Fn setmode "const char *mode_str"
 45.Ft mode_t
 46.Fn getmode "const void *set" "mode_t mode"
47.Sh DESCRIPTION 47.Sh DESCRIPTION
48The 48The
 49.Fn setmode
 50function accepts a string representation of a file mode change,
 51compiles it to binary form, and returns an abstract representation
 52that may be passed to
 53.Fn getmode .
 54The string may be an numeric (octal) or symbolic string of the form
 55accepted by
 56.Xr chmod 1 ,
 57and may represent either an exact mode to set or a change to make to
 58the existing mode.
 59.Pp
 60The
49.Fn getmode 61.Fn getmode
50function 62function
51returns a copy of the file permission bits 63adjusts the file permission bits given by
52.Fa mode 64.Fa mode
53as altered by the values pointed to by 65according to the compiled change representation
54.Fa set . 66.Fa set ,
55While only the mode bits are altered, other parts of the file mode 67and returns the adjusted mode.
56may be examined. 68While only the permission bits are altered, other parts of the file
 69mode, particularly the type, may be examined.
57.Pp 70.Pp
58The 71Because some of the possible symbolic values are defined relative to
59.Fn setmode 72the file creation mask,
60function 
61takes an absolute (octal) or symbolic value, as described in 
62.Xr chmod 1 , 
63as an argument 
64and returns a pointer to mode values to be supplied to 
65.Fn getmode . 
66Because some of the symbolic values are relative to the file 
67creation mask, 
68.Fn setmode 73.Fn setmode
69may call 74may call
70.Xr umask 2 . 75.Xr umask 2 ,
 76temporarily changing the mask.
71If this occurs, the file creation mask will be restored before 77If this occurs, the file creation mask will be restored before
72.Fn setmode 78.Fn setmode
73returns. 79returns.
74If the calling program changes the value of its file creation mask 80If the calling program changes the value of its file creation mask
75after calling 81after calling
76.Fn setmode , 82.Fn setmode ,
77.Fn setmode 83.Fn setmode
78must be called again if 84must be called again to recompile the mode string if
79.Fn getmode 85.Fn getmode
80is to modify future file modes correctly. 86is to modify future file modes correctly.
81.Pp 87.Pp
82If the mode passed to 88If the mode passed to
83.Fn setmode 89.Fn setmode
84is invalid, 90is invalid,
85.Fn setmode 91.Fn setmode
86returns 92returns
87.Dv NULL . 93.Dv NULL .
 94.Sh EXAMPLES
 95The effects of the shell command
 96.Ql "chmod a+x myscript.sh"
 97can be duplicated as follows:
 98.Bd -literal -offset indent
 99const char *file = "myscript.sh";
 100struct stat st;
 101mode_t newmode;
 102
 103stat(file, \*[Am]st);
 104newmode = getmode(setmode("a+x"), st.st_mode);
 105chmod(file, newmode);
 106.Ed
88.Sh ERRORS 107.Sh ERRORS
89The 108The
90.Fn setmode 109.Fn setmode
91function 110function
92may fail and set 111may fail and set
93.Va errno 112.Va errno
94for any of the errors specified for the library routines 113for any of the errors specified for the library routines
95.Xr malloc 3 114.Xr malloc 3
96or 115or
97.Xr strtol 3 . 116.Xr strtol 3 .
98In addition, 117In addition,
99.Fn setmode 118.Fn setmode
100will fail and set 119will fail and set
@@ -108,13 +127,24 @@ argument does not represent a valid mode @@ -108,13 +127,24 @@ argument does not represent a valid mode
108.El 127.El
109.Sh SEE ALSO 128.Sh SEE ALSO
110.Xr chmod 1 , 129.Xr chmod 1 ,
111.Xr stat 2 , 130.Xr stat 2 ,
112.Xr umask 2 , 131.Xr umask 2 ,
113.Xr malloc 3 132.Xr malloc 3
114.Sh HISTORY 133.Sh HISTORY
115The 134The
116.Fn getmode 135.Fn getmode
117and 136and
118.Fn setmode 137.Fn setmode
119functions first appeared in 138functions first appeared in
120.Bx 4.4 . 139.Bx 4.4 .
 140.Sh BUGS
 141Each call to
 142.Nm setmode
 143allocates a small amount of memory that there is no correct way to
 144free.
 145.Pp
 146The type of
 147.Fa set
 148should really be some opaque struct type used only by these functions
 149rather than
 150.Ft void * .

cvs diff -r1.194 -r1.194.6.1 src/lib/libc/gen/sysctl.3 (expand / switch to unified diff)

--- src/lib/libc/gen/sysctl.3 2008/09/17 22:08:52 1.194
+++ src/lib/libc/gen/sysctl.3 2008/09/17 22:08:52 1.194.6.1
@@ -1,725 +0,0 @@ @@ -1,725 +0,0 @@
1.\" $NetBSD: sysctl.3,v 1.194 2008/09/17 22:08:52 christos Exp $ 
2.\" 
3.\" Copyright (c) 1993 
4.\" The Regents of the University of California. All rights reserved. 
5.\" 
6.\" Redistribution and use in source and binary forms, with or without 
7.\" modification, are permitted provided that the following conditions 
8.\" are met: 
9.\" 1. Redistributions of source code must retain the above copyright 
10.\" notice, this list of conditions and the following disclaimer. 
11.\" 2. Redistributions in binary form must reproduce the above copyright 
12.\" notice, this list of conditions and the following disclaimer in the 
13.\" documentation and/or other materials provided with the distribution. 
14.\" 3. Neither the name of the University nor the names of its contributors 
15.\" may be used to endorse or promote products derived from this software 
16.\" without specific prior written permission. 
17.\" 
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
28.\" SUCH DAMAGE. 
29.\" 
30.\" @(#)sysctl.3 8.4 (Berkeley) 5/9/95 
31.\" 
32.Dd September 17, 2008 
33.Dt SYSCTL 3 
34.Os 
35.Sh NAME 
36.Nm sysctl , 
37.Nm sysctlbyname , 
38.Nm sysctlgetmibinfo , 
39.Nm sysctlnametomib 
40.Nd get or set system information 
41.Sh LIBRARY 
42.Lb libc 
43.Sh SYNOPSIS 
44.In sys/param.h 
45.In sys/sysctl.h 
46.Ft int 
47.Fn sysctl "const int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" \ 
48"const void *newp" "size_t newlen" 
49.Ft int 
50.Fn sysctlbyname "const char *sname" "void *oldp" "size_t *oldlenp" \ 
51"void *newp" "size_t newlen" 
52.Ft int 
53.Fn sysctlgetmibinfo "const char *sname" "int *name" "u_int *namelenp" \ 
54"char *cname" "size_t *csz" "struct sysctlnode **rnode" "int v" 
55.Ft int 
56.Fn sysctlnametomib "const char *sname" "int *name" "size_t *namelenp" 
57.Sh DESCRIPTION 
58The 
59.Nm 
60function retrieves system information and allows processes with 
61appropriate privileges to set system information. 
62The information available from 
63.Nm 
64consists of integers, strings, and tables. 
65Information may be retrieved and set from the command interface 
66using the 
67.Xr sysctl 8 
68utility. 
69.Pp 
70Unless explicitly noted below, 
71.Nm 
72returns a consistent snapshot of the data requested. 
73Consistency is obtained by locking the destination 
74buffer into memory so that the data may be copied out without blocking. 
75Calls to 
76.Nm 
77are serialized to avoid deadlock. 
78.Pp 
79The state is described using a ``Management Information Base'' (MIB) 
80style name, listed in 
81.Fa name , 
82which is a 
83.Fa namelen 
84length array of integers. 
85.Pp 
86The 
87.Fn sysctlbyname 
88function accepts a string representation of a MIB entry and internally 
89maps it to the appropriate numeric MIB representation. 
90Its semantics are otherwise no different from 
91.Fn sysctl . 
92.Pp 
93The information is copied into the buffer specified by 
94.Fa oldp . 
95The size of the buffer is given by the location specified by 
96.Fa oldlenp 
97before the call, 
98and that location gives the amount of data copied after a successful call. 
99If the amount of data available is greater 
100than the size of the buffer supplied, 
101the call supplies as much data as fits in the buffer provided 
102and returns with the error code ENOMEM. 
103If the old value is not desired, 
104.Fa oldp 
105and 
106.Fa oldlenp 
107should be set to 
108.Dv NULL . 
109.Pp 
110The size of the available data can be determined by calling 
111.Nm 
112with a 
113.Dv NULL 
114parameter for 
115.Fa oldp . 
116The size of the available data will be returned in the location pointed to by 
117.Fa oldlenp . 
118For some operations, the amount of space may change often. 
119For these operations, 
120the system attempts to round up so that the returned size is 
121large enough for a call to return the data shortly thereafter. 
122.Pp 
123To set a new value, 
124.Fa newp 
125is set to point to a buffer of length 
126.Fa newlen 
127from which the requested value is to be taken. 
128If a new value is not to be set, 
129.Fa newp 
130should be set to 
131.Dv NULL 
132and 
133.Fa newlen 
134set to 0. 
135.Pp 
136The 
137.Fn sysctlnametomib 
138function can be used to map the string representation of a MIB entry 
139to the numeric version. 
140The 
141.Fa name 
142argument should point to an array of integers large enough to hold the 
143MIB, and 
144.Fa namelenp 
145should indicate the number of integer slots available. 
146Following a successful translation, the size_t indicated by 
147.Fa namelenp 
148will be changed to show the number of slots consumed. 
149.Pp 
150The 
151.Fn sysctlgetmibinfo 
152function performs name translation similar to 
153.Fn sysctlnametomib , 
154but also canonicalizes the name (or returns the first erroneous token 
155from the string being parsed) into the space indicated by 
156.Fa cname 
157and 
158.Fa csz . 
159.Fa csz 
160should indicate the size of the buffer pointed to by 
161.Fa cname 
162and on return, will indicate the size of the returned string including 
163the trailing 
164.Sq nul 
165character. 
166.Pp 
167The 
168.Fa rnode 
169and 
170.Fa v 
171arguments to 
172.Fn sysctlgetmibinfo 
173are used to provide a tree for it to parse into, and to get back 
174either a pointer to, or a copy of, the terminal node. 
175If 
176.Fa rnode 
177is 
178.Dv NULL , 
179.Fn sysctlgetmibinfo 
180uses its own internal tree for parsing, and checks it against the 
181kernel at each call, to make sure that the name-to-number mapping is 
182kept up to date. 
183The 
184.Fa v 
185argument is ignored in this case. 
186If 
187.Fa rnode 
188is not 
189.Dv NULL 
190but the pointer it references is, on a successful return, 
191.Fa rnode 
192will be adjusted to point to a copy of the terminal node. 
193The 
194.Fa v 
195argument indicates which version of the 
196.Nm 
197node structure the caller wants. 
198The application must later 
199.Fn free 
200this copy. 
201If neither 
202.Fa rnode 
203nor the pointer it references are 
204.Dv NULL , 
205the pointer is used as the address of a tree over which the parsing is 
206done. 
207In this last case, the tree is not checked against the kernel, no 
208refreshing of the mappings is performed, and the value given by 
209.Fa v 
210must agree with the version indicated by the tree. 
211It is recommended that applications always use 
212.Dv SYSCTL_VERSION 
213as the value for 
214.Fa v , 
215as defined in the include file 
216.Pa sys/sysctl.h . 
217.Pp 
218The numeric and text names of sysctl variables are described in 
219.Xr sysctl 7 . 
220The numeric names are defined as preprocessor macros. 
221The top level names are defined with a CTL_ prefix in 
222.Aq Pa sys/sysctl.h . 
223The next and subsequent levels down have different prefixes for each 
224subtree. 
225.Pp 
226For example, the following retrieves the maximum number of processes allowed 
227in the system - the 
228.Li kern.maxproc 
229variable: 
230.Bd -literal -offset indent -compact 
231int mib[2], maxproc; 
232size_t len; 
233.sp 
234mib[0] = CTL_KERN; 
235mib[1] = KERN_MAXPROC; 
236len = sizeof(maxproc); 
237sysctl(mib, 2, \*[Am]maxproc, \*[Am]len, NULL, 0); 
238.Ed 
239.sp 
240To retrieve the standard search path for the system utilities - 
241.Li user.cs_path : 
242.Bd -literal -offset indent -compact 
243int mib[2]; 
244size_t len; 
245char *p; 
246.sp 
247mib[0] = CTL_USER; 
248mib[1] = USER_CS_PATH; 
249sysctl(mib, 2, NULL, \*[Am]len, NULL, 0); 
250p = malloc(len); 
251sysctl(mib, 2, p, \*[Am]len, NULL, 0); 
252.Ed 
253.Sh DYNAMIC OPERATIONS 
254Several meta-identifiers are provided to perform operations on the 
255.Nm 
256tree itself, or support alternate means of accessing the data 
257instrumented by the 
258.Nm 
259tree. 
260.Bl -column CTLXCREATESYMXXX 
261.It Sy Name Description 
262.It CTL\_QUERY Retrieve a mapping of names to numbers below a given node 
263.It CTL\_CREATE Create a new node 
264.It CTL\_CREATESYM Create a new node by its kernel symbol 
265.It CTL\_DESTROY Destroy a node 
266.It CTL\_DESCRIBE Retrieve node descriptions 
267.El 
268.Pp 
269The core interface to all of these meta-functions is the structure 
270that the kernel uses to describe the tree internally, as defined in 
271.Aq Pa sys/sysctl.h 
272as: 
273.Pp 
274.Bd -literal 
275struct sysctlnode { 
276 uint32_t sysctl_flags; /* flags and type */ 
277 int32_t sysctl_num; /* mib number */ 
278 char sysctl_name[SYSCTL_NAMELEN]; /* node name */ 
279 uint32_t sysctl_ver; /* node's version vs. rest of tree */ 
280 uint32_t __rsvd; 
281 union { 
282 struct { 
283 uint32_t suc_csize; /* size of child node array */ 
284 uint32_t suc_clen; /* number of valid children */ 
285 struct sysctlnode* suc_child; /* array of child nodes */ 
286 } scu_child; 
287 struct { 
288 void *sud_data; /* pointer to external data */ 
289 size_t sud_offset; /* offset to data */ 
290 } scu_data; 
291 int32_t scu_alias; /* node this node refers to */ 
292 int32_t scu_idata; /* immediate "int" data */ 
293 u_quad_t scu_qdata; /* immediate "u_quad_t" data */ 
294 } sysctl_un; 
295 size_t _sysctl_size; /* size of instrumented data */ 
296 sysctlfn _sysctl_func; /* access helper function */ 
297 struct sysctlnode *sysctl_parent; /* parent of this node */ 
298 const char *sysctl_desc; /* description of node */ 
299}; 
300 
301#define sysctl_csize sysctl_un.scu_child.suc_csize 
302#define sysctl_clen sysctl_un.scu_child.suc_clen 
303#define sysctl_child sysctl_un.scu_child.suc_child 
304#define sysctl_data sysctl_un.scu_data.sud_data 
305#define sysctl_offset sysctl_un.scu_data.sud_offset 
306#define sysctl_alias sysctl_un.scu_alias 
307#define sysctl_idata sysctl_un.scu_idata 
308#define sysctl_qdata sysctl_un.scu_qdata 
309.Ed 
310.Pp 
311Querying the tree to discover the name to number mapping permits 
312dynamic discovery of all the data that the tree currently has 
313instrumented. 
314For example, to discover all the nodes below the 
315CTL_VFS node: 
316.Pp 
317.Bd -literal -offset indent -compact 
318struct sysctlnode query, vfs[128]; 
319int mib[2]; 
320size_t len; 
321.sp 
322mib[0] = CTL_VFS; 
323mib[1] = CTL_QUERY; 
324memset(\*[Am]query, 0, sizeof(query)); 
325query.sysctl_flags = SYSCTL_VERSION; 
326len = sizeof(vfs); 
327sysctl(mib, 2, \*[Am]vfs[0], \*[Am]len, \*[Am]query, sizeof(query)); 
328.Ed 
329.Pp 
330Note that a reference to an empty node with 
331.Fa sysctl_flags 
332set to 
333.Dv SYSCTL_VERSION 
334is passed to sysctl in order to indicate the version that the program 
335is using. 
336All dynamic operations passing nodes into sysctl require that the 
337version be explicitly specified. 
338.Pp 
339Creation and destruction of nodes works by constructing part of a new 
340node description (or a description of the existing node) and invoking 
341CTL_CREATE (or CTL_CREATESYM) or CTL_DESTROY at the parent of the new 
342node, with a pointer to the new node passed via the 
343.Fa new 
344and 
345.Fa newlen 
346arguments. 
347If valid values for 
348.Fa old 
349and 
350.Fa oldlenp 
351are passed, a copy of the new node once in the tree will be returned. 
352If the create operation fails because a node with the same name or MIB 
353number exists, a copy of the conflicting node will be returned. 
354.Pp 
355The minimum requirements for creating a node are setting the 
356.Fa sysctl_flags 
357to indicate the new node's type, 
358.Fa sysctl_num 
359to either the new node's number (or CTL_CREATE or CTL_CREATESYM if a 
360dynamically allocated MIB number is acceptable), 
361.Fa sysctl_size 
362to the size of the data to be instrumented (which must agree with the 
363given type), and 
364.Fa sysctl_name 
365must be set to the new node's name. 
366Nodes that are not of type 
367.Dq node 
368must also have some description of the data to be instrumented, which 
369will vary depending on what is to be instrumented. 
370.Pp 
371If existing kernel data is to be covered by this new node, its address 
372should be given in 
373.Fa sysctl_data 
374or, if CTL_CREATESYM is used, 
375.Fa sysctl_data 
376should be set to a string containing its name from the kernel's symbol 
377table. 
378If new data is to be instrumented and an initial value is available, 
379the new integer or quad type data should be placed into either 
380.Fa sysctl_idata 
381or 
382.Fa sysctl_qdata , 
383respectively, along with the SYSCTL_IMMEDIATE flag being set, or 
384.Fa sysctl_data 
385should be set to point to a copy of the new data, and the 
386SYSCTL_OWNDATA flag must be set. 
387This latter method is the only way that new string and struct type 
388nodes can be initialized. 
389Invalid kernel addresses are accepted, but any attempt to access those 
390nodes will return an error. 
391.Pp 
392The 
393.Fa sysctl_csize , 
394.Fa sysctl_clen , 
395.Fa sysctl_child , 
396.Fa sysctl_parent , 
397and 
398.Fa sysctl_alias 
399members are used by the kernel to link the tree together and must be 
400.Dv NULL 
401or 0. 
402Nodes created in this manner cannot have helper functions, so 
403.Fa sysctl_func 
404must also be 
405.Dv NULL . 
406If the 
407.Fa sysctl_ver 
408member is non-zero, it must match either the version of the parent or 
409the version at the root of the MIB or an error is returned. 
410This can be used to ensure that nodes are only added or removed from a 
411known state of the tree. 
412Note: It may not be possible to determine the version at the root 
413of the tree. 
414.Pp 
415This example creates a new subtree and adds a node to it that controls the 
416.Fa audiodebug 
417kernel variable, thereby making it tunable at at any time, without 
418needing to use 
419.Xr ddb 4 
420or 
421.Xr kvm 3 
422to alter the kernel's memory directly. 
423.Pp 
424.Bd -literal -offset indent -compact 
425struct sysctlnode node; 
426int mib[2]; 
427size_t len; 
428.sp 
429mib[0] = CTL_CREATE; /* create at top-level */ 
430len = sizeof(node); 
431memset(\*[Am]node, 0, len); 
432node.sysctl_flags = SYSCTL_VERSION|CTLFLAG_READWRITE|CTLTYPE_NODE; 
433snprintf(node.sysctl_name, sizeof(node.sysctl_name), "local"); 
434node.sysctl_num = CTL_CREATE; /* request dynamic MIB number */ 
435sysctl(\*[Am]mib[0], 1, \*[Am]node, \*[Am]len, \*[Am]node, len); 
436.sp 
437mib[0] = node.sysctl_num; /* use new MIB number */ 
438mib[1] = CTL_CREATESYM; /* create at second level */ 
439len = sizeof(node); 
440memset(\*[Am]node, 0, len); 
441node.sysctl_flags = SYSCTL_VERSION|CTLFLAG_READWRITE|CTLTYPE_INT; 
442snprintf(node.sysctl_name, sizeof(node.sysctl_name), "audiodebug"); 
443node.sysctl_num = CTL_CREATE; 
444node.sysctl_data = "audiodebug"; /* kernel symbol to be used */ 
445sysctl(\*[Am]mib[0], 2, NULL, NULL, \*[Am]node, len); 
446.Ed 
447.Pp 
448The process for deleting nodes is similar, but less data needs to 
449be supplied. 
450Only the 
451.Fa sysctl_num 
452field 
453needs to be filled in; almost all other fields must be left blank. 
454The 
455.Fa sysctl_name 
456and/or 
457.Fa sysctl_ver 
458fields can be filled in with the name and version of the existing node 
459as additional checks on what will be deleted. 
460If all the given data fail to match any node, nothing will be deleted. 
461If valid values for 
462.Fa old 
463and 
464.Fa oldlenp 
465are supplied and a node is deleted, a copy of what was in the MIB tree 
466will be returned. 
467.Pp 
468This sample code shows the deletion of the two nodes created in the 
469above example: 
470.Pp 
471.Bd -literal -offset indent -compact 
472int mib[2]; 
473.sp 
474len = sizeof(node); 
475memset(\*[Am]node, 0, len); 
476node.sysctl_flags = SYSCTL_VERSION; 
477.sp 
478mib[0] = 3214; /* assumed number for "local" */ 
479mib[1] = CTL_DESTROY; 
480node.sysctl_num = 3215; /* assumed number for "audiodebug" */ 
481sysctl(\*[Am]mib[0], 2, NULL, NULL, \*[Am]node, len); 
482.sp 
483mib[0] = CTL_DESTROY; 
484node.sysctl_num = 3214; /* now deleting "local" */ 
485sysctl(\*[Am]mib[0], 1, NULL, NULL, \*[Am]node, len); 
486.Ed 
487.Pp 
488Descriptions of each of the nodes can also be retrieved, if they are 
489available. 
490Descriptions can be retrieved in bulk at each level or on a per-node 
491basis. 
492The layout of the buffer into which the descriptions are returned is a 
493series of variable length structures, each of which describes its own 
494size. 
495The length indicated includes the terminating 
496.Sq nul 
497character. 
498Nodes that have no description or where the description is not 
499available are indicated by an empty string. 
500The 
501.Fa descr_ver 
502will match the 
503.Fa sysctl_ver 
504value for a given node, so that descriptions for nodes whose number 
505have been recycled can be detected and ignored or discarded. 
506.Pp 
507.Bd -literal 
508struct sysctldesc { 
509 int32_t descr_num; /* mib number of node */ 
510 uint32_t descr_ver; /* version of node */ 
511 uint32_t descr_len; /* length of description string */ 
512 char descr_str[1]; /* not really 1...see above */ 
513}; 
514.Ed 
515.Pp 
516The 
517.Fn NEXT_DESCR 
518macro can be used to skip to the next description in the retrieved 
519list. 
520.Pp 
521.Bd -literal -offset indent -compact 
522struct sysctlnode desc; 
523struct sysctldesc *d; 
524char buf[1024]; 
525int mib[2]; 
526size_t len; 
527.sp 
528/* retrieve kern-level descriptions */ 
529mib[0] = CTL_KERN; 
530mib[1] = CTL_DESCRIBE; 
531d = (struct sysctldesc *)\*[Am]buf[0]; 
532len = sizeof(buf); 
533sysctl(mib, 2, d, \*[Am]len, NULL, 0); 
534while ((caddr_t)d \*[Lt] (caddr_t)\*[Am]buf[len]) { 
535 printf("node %d: %.*s\\n", d-\*[Gt]descr_num, d-\*[Gt]descr_len, 
536 d-\*[Gt]descr_str); 
537 d = NEXT_DESCR(d); 
538} 
539.sp 
540/* retrieve description for kern.securelevel */ 
541memset(\*[Am]desc, 0, sizeof(desc)); 
542desc.sysctl_flags = SYSCTL_VERSION; 
543desc.sysctl_num = KERN_SECURELEVEL; 
544d = (struct sysctldesc *)\*[Am]buf[0]; 
545len = sizeof(buf); 
546sysctl(mib, 2, d, \*[Am]len, \*[Am]desc, sizeof(desc)); 
547printf("kern.securelevel: %.*s\\n", d-\*[Gt]descr_len, d-\*[Gt]descr_str); 
548.Ed 
549.Pp 
550Descriptions can also be set as follows, subject to the following rules: 
551.Pp 
552.Bl -bullet -compact 
553.It 
554The kernel securelevel is at zero or lower 
555.It 
556The caller has super-user privileges 
557.It 
558The node does not currently have a description 
559.It 
560The node is not marked as 
561.Dq permanent 
562.El 
563.Pp 
564.Bd -literal -offset indent -compact 
565struct sysctlnode desc; 
566int mib[2]; 
567.sp 
568/* presuming the given top-level node was just added... */ 
569mib[0] = 3214; /* mib numbers taken from previous examples */ 
570mib[1] = CTL_DESCRIBE; 
571memset(\*[Am]desc, 0, sizeof(desc)); 
572desc.sysctl_flags = SYSCTL_VERSION; 
573desc.sysctl_num = 3215; 
574desc.sysctl_desc = "audio debug control knob"; 
575sysctl(mib, 2, NULL, NULL, \*[Am]desc, sizeof(desc)); 
576.Ed 
577.Pp 
578Upon successfully setting a description, the new description will be 
579returned in the space indicated by the 
580.Fa oldp 
581and 
582.Fa oldlenp 
583arguments. 
584.Pp 
585The 
586.Fa sysctl_flags 
587field in the struct sysctlnode contains the sysctl version, node type 
588information, and a number of flags. 
589The macros 
590.Fn SYSCTL_VERS , 
591.Fn SYSCTL_TYPE , 
592and 
593.Fn SYSCTL_FLAGS 
594can be used to access the different fields. 
595Valid flags are: 
596.Bl -column CTLFLAGXPERMANENTXXX 
597.It Sy Name Description 
598.It CTLFLAG\_READONLY Node is read-only 
599.It CTLFLAG\_READONLY1 Node becomes read-only at securelevel 1 
600.It CTLFLAG\_READONLY2 Node becomes read-only at securelevel 2 
601.It CTLFLAG\_READWRITE Node is writable by the superuser 
602.It CTLFLAG\_ANYWRITE Node is writable by anyone 
603.It CTLFLAG\_PRIVATE Node is readable only by the superuser 
604.It CTLFLAG\_PERMANENT Node cannot be removed (cannot be set by 
605processes) 
606.It CTLFLAG\_OWNDATA Node owns data and does not instrument 
607existing data 
608.It CTLFLAG\_IMMEDIATE Node contains instrumented data and does not 
609instrument existing data 
610.It CTLFLAG\_HEX Node's contents should be displayed in a hexadecimal 
611form 
612.It CTLFLAG\_ROOT Node is the root of a tree (cannot be set at 
613any time) 
614.It CTLFLAG\_ANYNUMBER Node matches any MIB number (cannot be set by 
615processes) 
616.It CTLFLAG\_HIDDEN Node not displayed by default 
617.It CTLFLAG\_ALIAS Node refers to a sibling node (cannot be set 
618by processes) 
619.It CTLFLAG\_OWNDESC Node owns its own description string space 
620.El 
621.Sh RETURN VALUES 
622If the call to 
623.Nm 
624is successful, 0 is returned. 
625Otherwise \-1 is returned and 
626.Va errno 
627is set appropriately. 
628.Sh FILES 
629.Bl -tag -width \*[Lt]netinet6/udp6Xvar.h\*[Gt] -compact 
630.It Aq Pa sys/sysctl.h 
631definitions for top level identifiers, second level kernel and hardware 
632identifiers, and user level identifiers 
633.It Aq Pa sys/socket.h 
634definitions for second level network identifiers 
635.It Aq Pa sys/gmon.h 
636definitions for third level profiling identifiers 
637.It Aq Pa uvm/uvm_param.h 
638definitions for second level virtual memory identifiers 
639.It Aq Pa netinet/in.h 
640definitions for third level IPv4/v6 identifiers and 
641fourth level IPv4/v6 identifiers 
642.It Aq Pa netinet/icmp_var.h 
643definitions for fourth level ICMP identifiers 
644.It Aq Pa netinet/icmp6.h 
645definitions for fourth level ICMPv6 identifiers 
646.It Aq Pa netinet/tcp_var.h 
647definitions for fourth level TCP identifiers 
648.It Aq Pa netinet/udp_var.h 
649definitions for fourth level UDP identifiers 
650.It Aq Pa netinet6/udp6_var.h 
651definitions for fourth level IPv6 UDP identifiers 
652.It Aq Pa netinet6/ipsec.h 
653definitions for fourth level IPsec identifiers 
654.It Aq Pa netkey/key_var.h 
655definitions for third level PF_KEY identifiers 
656.It Aq Pa machine/cpu.h 
657definitions for second level machdep identifiers 
658.El 
659.Sh ERRORS 
660The following errors may be reported: 
661.Bl -tag -width Er 
662.It Bq Er EFAULT 
663The buffer 
664.Fa name , 
665.Fa oldp , 
666.Fa newp , 
667or length pointer 
668.Fa oldlenp 
669contains an invalid address, or the requested value is temporarily 
670unavailable. 
671.It Bq Er EINVAL 
672The 
673.Fa name 
674array is zero or greater than CTL_MAXNAME. 
675.It Bq Er EINVAL 
676A non-null 
677.Fa newp 
678is given and its specified length in 
679.Fa newlen 
680is too large or too small, or the given value is not acceptable for 
681the given node. 
682.It Bq Er EISDIR 
683The 
684.Fa name 
685array specifies an intermediate rather than terminal name. 
686.It Bq Er ENOENT 
687The 
688.Fa name 
689array specifies a node that does not exist in the tree. 
690.It Bq Er ENOENT 
691An attempt was made to destroy a node that does not exist, or to 
692create or destroy a node below a node that does not exist. 
693.It Bq Er ENOMEM 
694The length pointed to by 
695.Fa oldlenp 
696is too short to hold the requested value. 
697.It Bq Er ENOTDIR 
698The 
699.Fa name 
700array specifies a node below a node that addresses data. 
701.It Bq Er ENOTEMPTY 
702An attempt was made to destroy a node that still has children. 
703.It Bq Er EOPNOTSUPP 
704The 
705.Fa name 
706array specifies a value that is unknown or a meta-operation was 
707attempted that the requested node does not support. 
708.It Bq Er EPERM 
709An attempt is made to set a read-only value. 
710.It Bq Er EPERM 
711A process without appropriate privilege attempts to set a value or to 
712create or destroy a node. 
713.It Bq Er EPERM 
714An attempt to change a value protected by the current kernel security 
715level is made. 
716.El 
717.Sh SEE ALSO 
718.Xr sysctl 7 , 
719.Xr sysctl 8 
720.\" .Xr sysctl 9 
721.Sh HISTORY 
722The 
723.Nm 
724function first appeared in 
725.Bx 4.4 . 

cvs diff -r1.45.2.1 -r1.45.2.2 src/lib/libc/gen/syslog.c (expand / switch to unified diff)

--- src/lib/libc/gen/syslog.c 2008/11/03 23:21:19 1.45.2.1
+++ src/lib/libc/gen/syslog.c 2008/11/08 21:45:38 1.45.2.2
@@ -0,0 +1,569 @@ @@ -0,0 +1,569 @@
 1/* $NetBSD: syslog.c,v 1.45.2.2 2008/11/08 21:45:38 christos Exp $ */
 2
 3/*
 4 * Copyright (c) 1983, 1988, 1993
 5 * The Regents of the University of California. All rights reserved.
 6 *
 7 * Redistribution and use in source and binary forms, with or without
 8 * modification, are permitted provided that the following conditions
 9 * are met:
 10 * 1. Redistributions of source code must retain the above copyright
 11 * notice, this list of conditions and the following disclaimer.
 12 * 2. Redistributions in binary form must reproduce the above copyright
 13 * notice, this list of conditions and the following disclaimer in the
 14 * documentation and/or other materials provided with the distribution.
 15 * 3. Neither the name of the University nor the names of its contributors
 16 * may be used to endorse or promote products derived from this software
 17 * without specific prior written permission.
 18 *
 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 29 * SUCH DAMAGE.
 30 */
 31
 32#include <sys/cdefs.h>
 33#if defined(LIBC_SCCS) && !defined(lint)
 34#if 0
 35static char sccsid[] = "@(#)syslog.c 8.5 (Berkeley) 4/29/95";
 36#else
 37__RCSID("$NetBSD: syslog.c,v 1.45.2.2 2008/11/08 21:45:38 christos Exp $");
 38#endif
 39#endif /* LIBC_SCCS and not lint */
 40
 41#include "namespace.h"
 42#include <sys/types.h>
 43#include <sys/param.h>
 44#include <sys/socket.h>
 45#include <sys/syslog.h>
 46#include <sys/uio.h>
 47#include <sys/un.h>
 48#include <netdb.h>
 49
 50#include <errno.h>
 51#include <fcntl.h>
 52#include <paths.h>
 53#include <stdarg.h>
 54#include <stdio.h>
 55#include <stdlib.h>
 56#include <string.h>
 57#include <time.h>
 58#include <unistd.h>
 59#include "reentrant.h"
 60#include "extern.h"
 61
 62#ifdef __weak_alias
 63__weak_alias(closelog,_closelog)
 64__weak_alias(openlog,_openlog)
 65__weak_alias(setlogmask,_setlogmask)
 66__weak_alias(syslog,_syslog)
 67__weak_alias(vsyslog,_vsyslog)
 68__weak_alias(syslogp,_syslogp)
 69__weak_alias(vsyslogp,_vsyslogp)
 70
 71__weak_alias(closelog_r,_closelog_r)
 72__weak_alias(openlog_r,_openlog_r)
 73__weak_alias(setlogmask_r,_setlogmask_r)
 74__weak_alias(syslog_r,_syslog_r)
 75__weak_alias(vsyslog_r,_vsyslog_r)
 76__weak_alias(syslog_ss,_syslog_ss)
 77__weak_alias(vsyslog_ss,_vsyslog_ss)
 78__weak_alias(syslogp_r,_syslogp_r)
 79__weak_alias(vsyslogp_r,_vsyslogp_r)
 80__weak_alias(syslogp_ss,_syslogp_ss)
 81__weak_alias(vsyslogp_ss,_vsyslogp_ss)
 82#endif
 83
 84static struct syslog_data sdata = SYSLOG_DATA_INIT;
 85
 86static void openlog_unlocked_r(const char *, int, int,
 87 struct syslog_data *);
 88static void disconnectlog_r(struct syslog_data *);
 89static void connectlog_r(struct syslog_data *);
 90
 91#define LOG_SIGNAL_SAFE (int)0x80000000
 92
 93
 94#ifdef _REENTRANT
 95static mutex_t syslog_mutex = MUTEX_INITIALIZER;
 96#endif
 97
 98static char hostname[MAXHOSTNAMELEN];
 99
 100/*
 101 * syslog, vsyslog --
 102 * print message on log file; output is intended for syslogd(8).
 103 */
 104void
 105syslog(int pri, const char *fmt, ...)
 106{
 107 va_list ap;
 108
 109 va_start(ap, fmt);
 110 vsyslog(pri, fmt, ap);
 111 va_end(ap);
 112}
 113
 114void
 115vsyslog(int pri, const char *fmt, va_list ap)
 116{
 117 vsyslog_r(pri, &sdata, fmt, ap);
 118}
 119
 120/*
 121 * syslogp, vsyslogp --
 122 * like syslog but take additional arguments for MSGID and SD
 123 */
 124void
 125syslogp(int pri, const char *msgid, const char *sdfmt, const char *msgfmt, ...)
 126{
 127 va_list ap;
 128
 129 va_start(ap, msgfmt);
 130 vsyslogp(pri, msgid, sdfmt, msgfmt, ap);
 131 va_end(ap);
 132}
 133
 134void
 135vsyslogp(int pri, const char *msgid, const char *sdfmt, const char *msgfmt, va_list ap)
 136{
 137 vsyslogp_r(pri, &sdata, msgid, sdfmt, msgfmt, ap);
 138}
 139
 140void
 141openlog(const char *ident, int logstat, int logfac)
 142{
 143 openlog_r(ident, logstat, logfac, &sdata);
 144}
 145
 146void
 147closelog(void)
 148{
 149 closelog_r(&sdata);
 150}
 151
 152/* setlogmask -- set the log mask level */
 153int
 154setlogmask(int pmask)
 155{
 156 return setlogmask_r(pmask, &sdata);
 157}
 158
 159/* Reentrant version of syslog, i.e. syslog_r() */
 160
 161void
 162syslog_r(int pri, struct syslog_data *data, const char *fmt, ...)
 163{
 164 va_list ap;
 165
 166 va_start(ap, fmt);
 167 vsyslog_r(pri, data, fmt, ap);
 168 va_end(ap);
 169}
 170
 171void
 172syslogp_r(int pri, struct syslog_data *data, const char *msgid,
 173 const char *sdfmt, const char *msgfmt, ...)
 174{
 175 va_list ap;
 176
 177 va_start(ap, msgfmt);
 178 vsyslogp_r(pri, data, msgid, sdfmt, msgfmt, ap);
 179 va_end(ap);
 180}
 181
 182void
 183syslog_ss(int pri, struct syslog_data *data, const char *fmt, ...)
 184{
 185 va_list ap;
 186
 187 va_start(ap, fmt);
 188 vsyslog_r(pri | LOG_SIGNAL_SAFE, data, fmt, ap);
 189 va_end(ap);
 190}
 191
 192void
 193syslogp_ss(int pri, struct syslog_data *data, const char *msgid,
 194 const char *sdfmt, const char *msgfmt, ...)
 195{
 196 va_list ap;
 197
 198 va_start(ap, msgfmt);
 199 vsyslogp_r(pri | LOG_SIGNAL_SAFE, data, msgid, sdfmt, msgfmt, ap);
 200 va_end(ap);
 201}
 202
 203void
 204vsyslog_ss(int pri, struct syslog_data *data, const char *fmt, va_list ap)
 205{
 206 vsyslog_r(pri | LOG_SIGNAL_SAFE, data, fmt, ap);
 207}
 208
 209void
 210vsyslogp_ss(int pri, struct syslog_data *data, const char *msgid,
 211 const char *sdfmt, const char *msgfmt, va_list ap)
 212{
 213 vsyslogp_r(pri | LOG_SIGNAL_SAFE, data, msgid, sdfmt, msgfmt, ap);
 214}
 215
 216
 217void
 218vsyslog_r(int pri, struct syslog_data *data, const char *fmt, va_list ap)
 219{
 220 vsyslogp_r(pri, data, NULL, NULL, fmt, ap);
 221}
 222
 223void
 224vsyslogp_r(int pri, struct syslog_data *data, const char *msgid,
 225 const char *sdfmt, const char *msgfmt, va_list ap)
 226{
 227 size_t cnt, prlen, tries;
 228 char ch, *p, *t;
 229 struct timeval tv;
 230 struct tm tmnow;
 231 time_t now;
 232 int fd, saved_errno;
 233#define TBUF_LEN 2048
 234#define FMT_LEN 1024
 235#define MAXTRIES 10
 236 char *stdp = NULL; /* pacify gcc */
 237 char tbuf[TBUF_LEN], fmt_cpy[FMT_LEN], fmt_cat[FMT_LEN] = "";
 238 size_t tbuf_left, fmt_left;
 239 char *fmt = fmt_cat;
 240 int signal_safe = pri & LOG_SIGNAL_SAFE;
 241 int opened;
 242
 243 pri &= ~LOG_SIGNAL_SAFE;
 244
 245#define INTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID
 246 /* Check for invalid bits. */
 247 if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) {
 248 syslog_r(INTERNALLOG | signal_safe, data,
 249 "syslog_r: unknown facility/priority: %x", pri);
 250 pri &= LOG_PRIMASK|LOG_FACMASK;
 251 }
 252
 253 /* Check priority against setlogmask values. */
 254 if (!(LOG_MASK(LOG_PRI(pri)) & data->log_mask))
 255 return;
 256
 257 saved_errno = errno;
 258
 259 /* Set default facility if none specified. */
 260 if ((pri & LOG_FACMASK) == 0)
 261 pri |= data->log_fac;
 262
 263 /* Build the message. */
 264 p = tbuf;
 265 tbuf_left = TBUF_LEN;
 266
 267#define DEC() \
 268 do { \
 269 if (prlen >= tbuf_left) \
 270 prlen = tbuf_left - 1; \
 271 p += prlen; \
 272 tbuf_left -= prlen; \
 273 } while (/*CONSTCOND*/0)
 274
 275 prlen = snprintf_ss(p, tbuf_left, "<%d>1 ", pri);
 276 DEC();
 277
 278 if (!signal_safe && (gettimeofday(&tv, NULL) != -1)) {
 279 /* strftime() implies tzset(), localtime_r() doesn't. */
 280 tzset();
 281 now = (time_t) tv.tv_sec;
 282 localtime_r(&now, &tmnow);
 283
 284 prlen = strftime(p, tbuf_left, "%FT%T", &tmnow);
 285 DEC();
 286 prlen = snprintf(p, tbuf_left, ".%06ld", (long)tv.tv_usec);
 287 DEC();
 288 prlen = strftime(p, tbuf_left-1, "%z", &tmnow);
 289 /* strftime gives eg. "+0200", but we need "+02:00" */
 290 if (prlen == 5) {
 291 p[prlen+1] = p[prlen];
 292 p[prlen] = p[prlen-1];
 293 p[prlen-1] = p[prlen-2];
 294 p[prlen-2] = ':';
 295 prlen += 1;
 296 }
 297 } else {
 298 prlen = snprintf_ss(p, tbuf_left, "-");
 299
 300 /* if gmtime_r() was signal-safe we could output the UTC-time:
 301 gmtime_r(&now, &tmnow);
 302 prlen = strftime(p, tbuf_left, "%FT%TZ", &tmnow);
 303 */
 304 }
 305 DEC();
 306 prlen = snprintf_ss(p, tbuf_left, " %s ", hostname);
 307 DEC();
 308
 309 if (data->log_stat & LOG_PERROR)
 310 stdp = p;
 311 if (data->log_tag == NULL)
 312 data->log_tag = getprogname();
 313
 314 prlen = snprintf_ss(p, tbuf_left, "%s ",
 315 data->log_tag ? data->log_tag : "-");
 316 DEC();
 317
 318 if (data->log_stat & LOG_PID)
 319 prlen = snprintf_ss(p, tbuf_left, "%d ", getpid());
 320 else
 321 prlen = snprintf_ss(p, tbuf_left, "- ");
 322 DEC();
 323
 324 /*
 325 * concat the format strings, then use one vsnprintf()
 326 */
 327 if (msgid != NULL && *msgid != '\0') {
 328 strlcat(fmt_cat, msgid, FMT_LEN);
 329 strlcat(fmt_cat, " ", FMT_LEN);
 330 } else
 331 strlcat(fmt_cat, "- ", FMT_LEN);
 332
 333 if (sdfmt != NULL && *sdfmt != '\0') {
 334 strlcat(fmt_cat, sdfmt, FMT_LEN);
 335 } else
 336 strlcat(fmt_cat, "-", FMT_LEN);
 337
 338 if (msgfmt != NULL && *msgfmt != '\0') {
 339 strlcat(fmt_cat, " ", FMT_LEN);
 340 strlcat(fmt_cat, msgfmt, FMT_LEN);
 341 }
 342
 343 /*
 344 * We wouldn't need this mess if printf handled %m, or if
 345 * strerror() had been invented before syslog().
 346 */
 347 for (t = fmt_cpy, fmt_left = FMT_LEN; (ch = *fmt) != '\0'; ++fmt) {
 348 if (ch == '%' && fmt[1] == 'm') {
 349 char ebuf[128];
 350 ++fmt;
 351 if (signal_safe ||
 352 strerror_r(saved_errno, ebuf, sizeof(ebuf)))
 353 prlen = snprintf_ss(t, fmt_left, "Error %d",
 354 saved_errno);
 355 else
 356 prlen = snprintf_ss(t, fmt_left, "%s", ebuf);
 357 if (prlen >= fmt_left)
 358 prlen = fmt_left - 1;
 359 t += prlen;
 360 fmt_left -= prlen;
 361 } else if (ch == '%' && fmt[1] == '%' && fmt_left > 2) {
 362 *t++ = '%';
 363 *t++ = '%';
 364 fmt++;
 365 fmt_left -= 2;
 366 } else {
 367 if (fmt_left > 1) {
 368 *t++ = ch;
 369 fmt_left--;
 370 }
 371 }
 372 }
 373 *t = '\0';
 374
 375 if (signal_safe)
 376 prlen = vsnprintf_ss(p, tbuf_left, fmt_cpy, ap);
 377 else
 378 prlen = vsnprintf(p, tbuf_left, fmt_cpy, ap);
 379 DEC();
 380 cnt = p - tbuf;
 381
 382 /* Output to stderr if requested. */
 383 if (data->log_stat & LOG_PERROR) {
 384 struct iovec iov[2];
 385
 386 iov[0].iov_base = stdp;
 387 iov[0].iov_len = cnt - (stdp - tbuf);
 388 iov[1].iov_base = __UNCONST("\n");
 389 iov[1].iov_len = 1;
 390 (void)writev(STDERR_FILENO, iov, 2);
 391 }
 392
 393 /* Get connected, output the message to the local logger. */
 394 if (data == &sdata)
 395 mutex_lock(&syslog_mutex);
 396 opened = !data->opened;
 397 if (opened)
 398 openlog_unlocked_r(data->log_tag, data->log_stat, 0, data);
 399 connectlog_r(data);
 400
 401 /*
 402 * If the send() failed, there are two likely scenarios:
 403 * 1) syslogd was restarted
 404 * 2) /dev/log is out of socket buffer space
 405 * We attempt to reconnect to /dev/log to take care of
 406 * case #1 and keep send()ing data to cover case #2
 407 * to give syslogd a chance to empty its socket buffer.
 408 */
 409 for (tries = 0; tries < MAXTRIES; tries++) {
 410 if (send(data->log_file, tbuf, cnt, 0) != -1)
 411 break;
 412 if (errno != ENOBUFS) {
 413 disconnectlog_r(data);
 414 connectlog_r(data);
 415 } else
 416 (void)usleep(1);
 417 }
 418
 419 /*
 420 * Output the message to the console; try not to block
 421 * as a blocking console should not stop other processes.
 422 * Make sure the error reported is the one from the syslogd failure.
 423 */
 424 if (tries == MAXTRIES && (data->log_stat & LOG_CONS) &&
 425 (fd = open(_PATH_CONSOLE, O_WRONLY|O_NONBLOCK, 0)) >= 0 &&
 426 (p = strchr(tbuf, '>')) != NULL) {
 427 struct iovec iov[2];
 428 iov[0].iov_base = ++p;
 429 iov[0].iov_len = cnt - (p - tbuf);
 430 iov[1].iov_base = __UNCONST("\r\n");
 431 iov[1].iov_len = 2;
 432 (void)writev(fd, iov, 2);
 433 (void)close(fd);
 434 }
 435
 436 if (data == &sdata)
 437 mutex_unlock(&syslog_mutex);
 438
 439 if (data != &sdata && opened) {
 440 /* preserve log tag */
 441 const char *ident = data->log_tag;
 442 closelog_r(data);
 443 data->log_tag = ident;
 444 }
 445}
 446
 447static void
 448disconnectlog_r(struct syslog_data *data)
 449{
 450 /*
 451 * If the user closed the FD and opened another in the same slot,
 452 * that's their problem. They should close it before calling on
 453 * system services.
 454 */
 455 if (data->log_file != -1) {
 456 (void)close(data->log_file);
 457 data->log_file = -1;
 458 }
 459 data->connected = 0; /* retry connect */
 460}
 461
 462static void
 463connectlog_r(struct syslog_data *data)
 464{
 465 /* AF_UNIX address of local logger */
 466 static const struct sockaddr_un sun = {
 467 .sun_family = AF_LOCAL,
 468 .sun_len = sizeof(sun),
 469 .sun_path = _PATH_LOG,
 470 };
 471
 472 if (data->log_file == -1 || fcntl(data->log_file, F_GETFL, 0) == -1) {
 473 if ((data->log_file = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1)
 474 return;
 475 (void)fcntl(data->log_file, F_SETFD, FD_CLOEXEC);
 476 data->connected = 0;
 477 }
 478 if (!data->connected) {
 479 if (connect(data->log_file,
 480 (const struct sockaddr *)(const void *)&sun,
 481 sizeof(sun)) == -1) {
 482 (void)close(data->log_file);
 483 data->log_file = -1;
 484 } else
 485 data->connected = 1;
 486 }
 487}
 488
 489static void
 490init_hostname(void)
 491{
 492 struct addrinfo *res;
 493 struct addrinfo hints = {
 494 .ai_family = PF_UNSPEC,
 495 .ai_socktype = 0,
 496 .ai_protocol = 0,
 497 .ai_flags = AI_CANONNAME,
 498 };
 499
 500 if (gethostname(hostname, sizeof(hostname)) == -1
 501 || hostname[0] == '\0') {
 502 /* can this really happen? */
 503 hostname[0] = '-';
 504 hostname[1] = '\0';
 505 return;
 506 }
 507
 508 if (strchr(hostname, '.') != NULL) /* FQDN */
 509 return;
 510
 511 if (getaddrinfo(hostname, NULL, &hints, &res) != 0)
 512 return;
 513 /* try to resolve back to hostname */
 514 (void)getnameinfo(res->ai_addr, (socklen_t)res->ai_addr->sa_len,
 515 hostname, sizeof(hostname), NULL, 0, 0);
 516 freeaddrinfo(res);
 517}
 518
 519static void
 520openlog_unlocked_r(const char *ident, int logstat, int logfac,
 521 struct syslog_data *data)
 522{
 523 if (ident != NULL)
 524 data->log_tag = ident;
 525 data->log_stat = logstat;
 526 if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0)
 527 data->log_fac = logfac;
 528
 529 if (data->log_stat & LOG_NDELAY) /* open immediately */
 530 connectlog_r(data);
 531
 532 /* We could cache this, but then it might change */
 533 init_hostname();
 534 data->opened = 1;
 535}
 536
 537void
 538openlog_r(const char *ident, int logstat, int logfac, struct syslog_data *data)
 539{
 540 if (data == &sdata)
 541 mutex_lock(&syslog_mutex);
 542 openlog_unlocked_r(ident, logstat, logfac, data);
 543 if (data == &sdata)
 544 mutex_unlock(&syslog_mutex);
 545}
 546
 547void
 548closelog_r(struct syslog_data *data)
 549{
 550 if (data == &sdata)
 551 mutex_lock(&syslog_mutex);
 552 (void)close(data->log_file);
 553 data->log_file = -1;
 554 data->connected = 0;
 555 data->log_tag = NULL;
 556 if (data == &sdata)
 557 mutex_unlock(&syslog_mutex);
 558}
 559
 560int
 561setlogmask_r(int pmask, struct syslog_data *data)
 562{
 563 int omask;
 564
 565 omask = data->log_mask;
 566 if (pmask != 0)
 567 data->log_mask = pmask;
 568 return omask;
 569}

cvs diff -r1.9 -r1.9.40.1 src/lib/libc/gen/tolower_.c (expand / switch to unified diff)

--- src/lib/libc/gen/tolower_.c 2003/07/26 19:24:45 1.9
+++ src/lib/libc/gen/tolower_.c 2009/01/04 17:02:19 1.9.40.1
@@ -1,23 +1,23 @@ @@ -1,23 +1,23 @@
1/* $NetBSD: tolower_.c,v 1.9 2003/07/26 19:24:45 salo Exp $ */ 1/* $NetBSD: tolower_.c,v 1.9.40.1 2009/01/04 17:02:19 christos Exp $ */
2 2
3/* 3/*
4 * Written by J.T. Conklin <jtc@NetBSD.org>. 4 * Written by J.T. Conklin <jtc@NetBSD.org>.
5 * Public domain. 5 * Public domain.
6 */ 6 */
7 7
8#include <sys/cdefs.h> 8#include <sys/cdefs.h>
9#if defined(LIBC_RCS) && !defined(lint) 9#if defined(LIBC_RCS) && !defined(lint)
10__RCSID("$NetBSD: tolower_.c,v 1.9 2003/07/26 19:24:45 salo Exp $"); 10__RCSID("$NetBSD: tolower_.c,v 1.9.40.1 2009/01/04 17:02:19 christos Exp $");
11#endif /* LIBC_RCS and not lint */ 11#endif /* LIBC_RCS and not lint */
12 12
13#include <stdio.h> 13#include <stdio.h>
14#include <ctype.h> 14#include <ctype.h>
15 15
16#if EOF != -1 16#if EOF != -1
17#error "EOF != -1" 17#error "EOF != -1"
18#endif 18#endif
19 19
20const short _C_tolower_[1 + 256] = { 20const short _C_tolower_[1 + 256] = {
21 EOF, 21 EOF,
22 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 22 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
23 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 23 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
@@ -44,21 +44,13 @@ const short _C_tolower_[1 + 256] = { @@ -44,21 +44,13 @@ const short _C_tolower_[1 + 256] = {
44 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 44 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
45 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 45 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
46 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 46 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
47 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 47 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
48 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 48 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
49 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 49 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
50 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 50 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
51 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 51 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
52 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 52 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
53 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 53 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
54}; 54};
55 55
56const short *_tolower_tab_ = _C_tolower_; 56const short *_tolower_tab_ = _C_tolower_;
57 
58#undef tolower 
59int 
60tolower(c) 
61 int c; 
62{ 
63 return((_tolower_tab_ + 1)[c]); 
64} 

cvs diff -r1.9 -r1.9.40.1 src/lib/libc/gen/toupper_.c (expand / switch to unified diff)

--- src/lib/libc/gen/toupper_.c 2003/07/26 19:24:45 1.9
+++ src/lib/libc/gen/toupper_.c 2009/01/04 17:02:19 1.9.40.1
@@ -1,23 +1,23 @@ @@ -1,23 +1,23 @@
1/* $NetBSD: toupper_.c,v 1.9 2003/07/26 19:24:45 salo Exp $ */ 1/* $NetBSD: toupper_.c,v 1.9.40.1 2009/01/04 17:02:19 christos Exp $ */
2 2
3/* 3/*
4 * Written by J.T. Conklin <jtc@NetBSD.org>. 4 * Written by J.T. Conklin <jtc@NetBSD.org>.
5 * Public domain. 5 * Public domain.
6 */ 6 */
7 7
8#include <sys/cdefs.h> 8#include <sys/cdefs.h>
9#if defined(LIBC_RCS) && !defined(lint) 9#if defined(LIBC_RCS) && !defined(lint)
10__RCSID("$NetBSD: toupper_.c,v 1.9 2003/07/26 19:24:45 salo Exp $"); 10__RCSID("$NetBSD: toupper_.c,v 1.9.40.1 2009/01/04 17:02:19 christos Exp $");
11#endif /* LIBC_RCS and not lint */ 11#endif /* LIBC_RCS and not lint */
12 12
13#include <stdio.h> 13#include <stdio.h>
14#include <ctype.h> 14#include <ctype.h>
15 15
16#if EOF != -1 16#if EOF != -1
17#error "EOF != -1" 17#error "EOF != -1"
18#endif 18#endif
19 19
20const short _C_toupper_[1 + 256] = { 20const short _C_toupper_[1 + 256] = {
21 EOF, 21 EOF,
22 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 22 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
23 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 23 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
@@ -44,21 +44,13 @@ const short _C_toupper_[1 + 256] = { @@ -44,21 +44,13 @@ const short _C_toupper_[1 + 256] = {
44 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 44 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
45 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 45 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
46 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 46 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
47 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 47 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
48 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 48 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
49 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 49 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
50 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 50 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
51 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 51 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
52 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 52 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
53 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 53 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
54}; 54};
55 55
56const short *_toupper_tab_ = _C_toupper_; 56const short *_toupper_tab_ = _C_toupper_;
57 
58#undef toupper 
59int 
60toupper(c) 
61 int c; 
62{ 
63 return((_toupper_tab_ + 1)[c]); 
64} 

cvs diff -r1.2 -r1.2.40.1 src/lib/libc/iconv/Makefile.inc (expand / switch to unified diff)

--- src/lib/libc/iconv/Makefile.inc 2003/07/04 06:05:30 1.2
+++ src/lib/libc/iconv/Makefile.inc 2009/01/04 17:02:19 1.2.40.1
@@ -1,11 +1,13 @@ @@ -1,11 +1,13 @@
1# $NetBSD: Makefile.inc,v 1.2 2003/07/04 06:05:30 tshiozak Exp $ 1# $NetBSD: Makefile.inc,v 1.2.40.1 2009/01/04 17:02:19 christos Exp $
2 2
3.PATH: ${ARCHDIR}/iconv ${.CURDIR}/iconv 3.PATH: ${ARCHDIR}/iconv ${.CURDIR}/iconv
4 4
5SRCS+= iconv.c 5SRCS+= iconv.c
6MAN+= iconv.3 6MAN+= iconv.3
7MLINKS+=iconv.3 iconv_open.3 iconv.3 iconv_close.3 7MLINKS+=iconv.3 iconv_open.3 iconv.3 iconv_close.3
8 8
9.if ${CITRUS} == "yes" 9.if ${CITRUS} == "yes"
10CPPFLAGS+= -DCITRUS_ICONV 10CPPFLAGS.iconv.c+= -DHAVE_CITRUS -I${LIBCDIR}/citrus
 11.else
 12CPPFLAGS.iconv.c+= -UHAVE_CITRUS
11.endif 13.endif

cvs diff -r1.6 -r1.6.26.1 src/lib/libc/iconv/iconv.c (expand / switch to unified diff)

--- src/lib/libc/iconv/iconv.c 2006/11/03 20:16:28 1.6
+++ src/lib/libc/iconv/iconv.c 2009/01/04 17:02:19 1.6.26.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: iconv.c,v 1.6 2006/11/03 20:16:28 christos Exp $ */ 1/* $NetBSD: iconv.c,v 1.6.26.1 2009/01/04 17:02:19 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2003 Citrus Project, 4 * Copyright (c)2003 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -18,50 +18,50 @@ @@ -18,50 +18,50 @@
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31__RCSID("$NetBSD: iconv.c,v 1.6 2006/11/03 20:16:28 christos Exp $"); 31__RCSID("$NetBSD: iconv.c,v 1.6.26.1 2009/01/04 17:02:19 christos Exp $");
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
34#include "namespace.h" 34#include "namespace.h"
35#include <assert.h> 35#include <assert.h>
36#include <errno.h> 36#include <errno.h>
37#include <paths.h> 37#include <paths.h>
38#include <sys/queue.h> 38#include <sys/queue.h>
39 39
40#include <iconv.h> 40#include <iconv.h>
41 41
42#ifdef __weak_alias 42#ifdef __weak_alias
43__weak_alias(iconv, _iconv) 43__weak_alias(iconv, _iconv)
44__weak_alias(iconv_open, _iconv_open) 44__weak_alias(iconv_open, _iconv_open)
45__weak_alias(iconv_close, _iconv_close) 45__weak_alias(iconv_close, _iconv_close)
46#endif 46#endif
47 47
48#ifdef CITRUS_ICONV 48#ifdef HAVE_CITRUS
49#include <sys/types.h> 49#include <sys/types.h>
50#include <citrus/citrus_types.h> 50#include "citrus_types.h"
51#include <citrus/citrus_module.h> 51#include "citrus_module.h"
52#include <citrus/citrus_esdb.h> 52#include "citrus_esdb.h"
53#include <citrus/citrus_hash.h> 53#include "citrus_hash.h"
54#include <citrus/citrus_iconv.h> 54#include "citrus_iconv.h"
55 55
56#define ISBADF(_h_) (!(_h_) || (_h_) == (iconv_t)-1) 56#define ISBADF(_h_) (!(_h_) || (_h_) == (iconv_t)-1)
57 57
58 58
59iconv_t 59iconv_t
60iconv_open(const char *out, const char *in) 60iconv_open(const char *out, const char *in)
61{ 61{
62 int ret; 62 int ret;
63 struct _citrus_iconv *handle; 63 struct _citrus_iconv *handle;
64 64
65 ret = _citrus_iconv_open(&handle, _PATH_ICONV, in, out); 65 ret = _citrus_iconv_open(&handle, _PATH_ICONV, in, out);
66 if (ret) { 66 if (ret) {
67 errno = ret == ENOENT? EINVAL : ret; 67 errno = ret == ENOENT? EINVAL : ret;

cvs diff -r1.134.2.4 -r1.134.2.5 src/lib/libc/include/namespace.h (expand / switch to unified diff)

--- src/lib/libc/include/namespace.h 2008/11/10 00:13:02 1.134.2.4
+++ src/lib/libc/include/namespace.h 2008/11/10 01:16:34 1.134.2.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: namespace.h,v 1.134.2.4 2008/11/10 00:13:02 christos Exp $ */ 1/* $NetBSD: namespace.h,v 1.134.2.5 2008/11/10 01:16:34 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997-2004 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -28,26 +28,27 @@ @@ -28,26 +28,27 @@
28 28
29#ifndef _NAMESPACE_H_ 29#ifndef _NAMESPACE_H_
30#define _NAMESPACE_H_ 30#define _NAMESPACE_H_
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33 33
34#ifndef __lint__ 34#ifndef __lint__
35#define aio_suspend _aio_suspend 35#define aio_suspend _aio_suspend
36#define brk _brk 36#define brk _brk
37#define catclose _catclose 37#define catclose _catclose
38#define catgets _catgets 38#define catgets _catgets
39#define catopen _catopen 39#define catopen _catopen
40#define daylight _daylight 40#define daylight _daylight
 41#define difftime _difftime
41#define err _err 42#define err _err
42#define errx _errx 43#define errx _errx
43#ifdef _REENTRANT 44#ifdef _REENTRANT
44#define fileno _fileno 45#define fileno _fileno
45#endif /* _REENTRANT */ 46#endif /* _REENTRANT */
46#define fork _fork 47#define fork _fork
47#define fseeko _fseeko 48#define fseeko _fseeko
48#define ftello _ftello 49#define ftello _ftello
49#define getcontext _getcontext 50#define getcontext _getcontext
50#define getenv_r _getenv_r 51#define getenv_r _getenv_r
51#define imaxabs _imaxabs 52#define imaxabs _imaxabs
52#define imaxdiv _imaxdiv 53#define imaxdiv _imaxdiv
53#define inet_aton _inet_aton 54#define inet_aton _inet_aton
@@ -195,26 +196,27 @@ @@ -195,26 +196,27 @@
195#define clock_gettime _clock_gettime 196#define clock_gettime _clock_gettime
196#define clock_getres _clock_getres 197#define clock_getres _clock_getres
197#define clock_settime _clock_settime 198#define clock_settime _clock_settime
198#define closedir _closedir 199#define closedir _closedir
199#define closelog _closelog 200#define closelog _closelog
200#define closelog_r _closelog_r 201#define closelog_r _closelog_r
201#define confstr _confstr 202#define confstr _confstr
202#define csetexpandtc _csetexpandtc 203#define csetexpandtc _csetexpandtc
203#define ctermid _ctermid 204#define ctermid _ctermid
204#define ctime_r _ctime_r 205#define ctime_r _ctime_r
205#define daemon _daemon 206#define daemon _daemon
206#define dbopen _dbopen 207#define dbopen _dbopen
207#define devname _devname 208#define devname _devname
 209#define difftime _difftime
208#define dirname _dirname 210#define dirname _dirname
209#define dn_expand _dn_expand 211#define dn_expand _dn_expand
210#define drand48 _drand48 212#define drand48 _drand48
211#define endfsent _endfsent 213#define endfsent _endfsent
212#define endgrent _endgrent 214#define endgrent _endgrent
213#define endhostent _endhostent 215#define endhostent _endhostent
214#define endnetconfig _endnetconfig 216#define endnetconfig _endnetconfig
215#define endnetent _endnetent 217#define endnetent _endnetent
216#define endnetgrent _endnetgrent 218#define endnetgrent _endnetgrent
217#define endnetpath _endnetpath 219#define endnetpath _endnetpath
218#define endprotoent _endprotoent 220#define endprotoent _endprotoent
219#define endprotoent_r _endprotoent_r 221#define endprotoent_r _endprotoent_r
220#define endpwent _endpwent 222#define endpwent _endpwent

cvs diff -r1.52 -r1.52.6.1 src/lib/libc/locale/Makefile.inc (expand / switch to unified diff)

--- src/lib/libc/locale/Makefile.inc 2008/05/17 03:49:54 1.52
+++ src/lib/libc/locale/Makefile.inc 2008/05/17 03:49:54 1.52.6.1
@@ -1,51 +0,0 @@ @@ -1,51 +0,0 @@
1# from: @(#)Makefile.inc 5.1 (Berkeley) 2/18/91 
2# $NetBSD: Makefile.inc,v 1.52 2008/05/17 03:49:54 ginsbach Exp $ 
3 
4# locale sources 
5.PATH: ${ARCHDIR}/locale ${.CURDIR}/locale 
6 
7SRCS+= _def_messages.c _def_monetary.c _def_numeric.c _def_time.c \ 
8 ctypeio.c lcmessages.c lcmonetary.c lcnumeric.c lctime.c \ 
9 localeconv.c localeio.c nl_langinfo.c setlocale.c setlocale1.c \ 
10 setlocale32.c __mb_cur_max.c wcscoll.c wcsftime.c \ 
11 wcstol.c wcstoll.c wcstoimax.c wcstoul.c wcstoull.c wcstoumax.c \ 
12 wcsxfrm.c aliasname.c 
13MAN+= nl_langinfo.3 setlocale.3 wcstol.3 wcscoll.3 wcsxfrm.3 
14 
15SRCS+= wcstod.c wcstof.c wcstold.c 
16MAN+= wcstod.3 
17 
18MLINKS+=setlocale.3 localeconv.3 
19 
20.if ${CITRUS} == "no" 
21RUNE= no 
22.endif 
23 
24RUNE?= yes 
25 
26.if ${RUNE} == "no" 
27# singlebyte locale - dummy 
28SRCS+= multibyte_sb.c iswctype_sb.c 
29CPPFLAGS+=-UWITH_RUNE 
30.else 
31# citrus multibyte locale support 
32# we have quirk for libc.a - see the last part of lib/libc/Makefile 
33CPPFLAGS+=-DWITH_RUNE -I${.CURDIR} 
34SRCS+= ___runetype_mb.c _wctrans.c iswctype.c multibyte_c90.c \ 
35 multibyte_amd1.c rune.c runeglue.c runetable.c setrunelocale.c 
36.endif 
37MAN+= btowc.3 iswalnum.3 iswctype.3 towlower.3 towctrans.3 mblen.3 mbrlen.3 \ 
38 mbrtowc.3 mbsinit.3 mbsrtowcs.3 mbstowcs.3 mbtowc.3 wcrtomb.3 wcwidth.3 \ 
39 wcsftime.3 wcsrtombs.3 wcstombs.3 wctob.3 wctomb.3 wctrans.3 wctype.3 
40 
41 
42MLINKS+=iswalnum.3 iswalpha.3 iswalnum.3 iswblank.3 \ 
43 iswalnum.3 iswcntrl.3 iswalnum.3 iswdigit.3 \ 
44 iswalnum.3 iswgraph.3 iswalnum.3 iswlower.3 \ 
45 iswalnum.3 iswprint.3 iswalnum.3 iswpunct.3 \ 
46 iswalnum.3 iswspace.3 iswalnum.3 iswupper.3 \ 
47 iswalnum.3 iswxdigit.3 
48MLINKS+=towlower.3 towupper.3 
49MLINKS+=wcstod.3 wcstof.3 wcstod.3 wcstold.3 
50MLINKS+=wcstol.3 wcstoll.3 wcstol.3 wcstoimax.3 \ 
51 wcstol.3 wcstoul.3 wcstol.3 wcstoull.3 wcstol.3 wcstoumax.3 

File Deleted: src/lib/libc/locale/Attic/___runetype_mb.c

cvs diff -r1.6 -r1.6.34.1 src/lib/libc/locale/_wctrans.c (expand / switch to unified diff)

--- src/lib/libc/locale/_wctrans.c 2005/02/10 19:19:57 1.6
+++ src/lib/libc/locale/_wctrans.c 2009/01/04 17:02:19 1.6.34.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: _wctrans.c,v 1.6 2005/02/10 19:19:57 tnozaki Exp $ */ 1/* $NetBSD: _wctrans.c,v 1.6.34.1 2009/01/04 17:02:19 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2003 Citrus Project, 4 * Copyright (c)2003 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -50,27 +50,27 @@ @@ -50,27 +50,27 @@
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE. 58 * SUCH DAMAGE.
59 */ 59 */
60 60
61#include <sys/cdefs.h> 61#include <sys/cdefs.h>
62#if defined(LIBC_SCCS) && !defined(lint) 62#if defined(LIBC_SCCS) && !defined(lint)
63__RCSID("$NetBSD: _wctrans.c,v 1.6 2005/02/10 19:19:57 tnozaki Exp $"); 63__RCSID("$NetBSD: _wctrans.c,v 1.6.34.1 2009/01/04 17:02:19 christos Exp $");
64#endif /* LIBC_SCCS and not lint */ 64#endif /* LIBC_SCCS and not lint */
65 65
66#include "namespace.h" 66#include "namespace.h"
67 67
68#include <wctype.h> 68#include <wctype.h>
69#include <stdlib.h> 69#include <stdlib.h>
70#include <string.h> 70#include <string.h>
71#include "rune.h" 71#include "rune.h"
72#include "rune_local.h" 72#include "rune_local.h"
73#include "_wctrans_local.h" 73#include "_wctrans_local.h"
74 74
75/* 75/*
76 * _wctrans_init: 76 * _wctrans_init:
@@ -78,27 +78,27 @@ __RCSID("$NetBSD: _wctrans.c,v 1.6 2005/ @@ -78,27 +78,27 @@ __RCSID("$NetBSD: _wctrans.c,v 1.6 2005/
78 78
79void 79void
80_wctrans_init(_RuneLocale *rl) 80_wctrans_init(_RuneLocale *rl)
81{ 81{
82 rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_name = "tolower"; 82 rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_name = "tolower";
83 rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_cached = rl->rl_maplower; 83 rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_cached = rl->rl_maplower;
84 rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_extmap = &rl->rl_maplower_ext; 84 rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_extmap = &rl->rl_maplower_ext;
85 rl->rl_wctrans[_WCTRANS_INDEX_UPPER].te_name = "toupper"; 85 rl->rl_wctrans[_WCTRANS_INDEX_UPPER].te_name = "toupper";
86 rl->rl_wctrans[_WCTRANS_INDEX_UPPER].te_cached = rl->rl_mapupper; 86 rl->rl_wctrans[_WCTRANS_INDEX_UPPER].te_cached = rl->rl_mapupper;
87 rl->rl_wctrans[_WCTRANS_INDEX_UPPER].te_extmap = &rl->rl_mapupper_ext; 87 rl->rl_wctrans[_WCTRANS_INDEX_UPPER].te_extmap = &rl->rl_mapupper_ext;
88} 88}
89 89
90/* 90/*
91 * _wctrans_ext: 91 * _towctrans_ext:
92 * translate a character (extended part) 92 * translate a character (extended part)
93 */ 93 */
94wint_t 94wint_t
95_towctrans_ext(wint_t c, struct _WCTransEntry *te) 95_towctrans_ext(wint_t c, struct _WCTransEntry *te)
96{ 96{
97 __nbrune_t c0; 97 __nbrune_t c0;
98 uint32_t x; 98 uint32_t x;
99 _RuneRange *rr; 99 _RuneRange *rr;
100 _RuneEntry *base, *re; 100 _RuneEntry *base, *re;
101 101
102 if (c == WEOF) 102 if (c == WEOF)
103 return (c); 103 return (c);
104 104

cvs diff -r1.2 -r1.2.40.1 src/lib/libc/locale/_wctrans_local.h (expand / switch to unified diff)

--- src/lib/libc/locale/_wctrans_local.h 2003/04/06 18:33:23 1.2
+++ src/lib/libc/locale/_wctrans_local.h 2009/01/04 17:02:19 1.2.40.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: _wctrans_local.h,v 1.2 2003/04/06 18:33:23 tshiozak Exp $ */ 1/* $NetBSD: _wctrans_local.h,v 1.2.40.1 2009/01/04 17:02:19 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2003 Citrus Project, 4 * Copyright (c)2003 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -19,40 +19,42 @@ @@ -19,40 +19,42 @@
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#ifndef _WCTRANS_LOCAL_H_ 29#ifndef _WCTRANS_LOCAL_H_
30#define _WCTRANS_LOCAL_H_ 30#define _WCTRANS_LOCAL_H_
31 31
 32__BEGIN_DECLS
32wint_t _towctrans_ext(wint_t, _WCTransEntry *); 33wint_t _towctrans_ext(wint_t, _WCTransEntry *);
33void _wctrans_init(_RuneLocale *); 34void _wctrans_init(_RuneLocale *);
 35__END_DECLS
34 36
35static __inline wint_t 37static __inline wint_t
36_towctrans(wint_t c, _WCTransEntry *te) 38_towctrans(wint_t c, _WCTransEntry *te)
37{ 39{
38 return (_RUNE_ISCACHED(c) ? 40 return (_RUNE_ISCACHED(c) ?
39 te->te_cached[(__nbrune_t)c]:_towctrans_ext(c, te)); 41 te->te_cached[(__nbrune_t)c]:_towctrans_ext(c, te));
40} 42}
41 43
42static __inline struct _WCTransEntry * 44static __inline struct _WCTransEntry *
43_wctrans_lower(_RuneLocale *rl) 45_wctrans_lower(_RuneLocale *rl)
44{ 46{
45 if (rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_name==NULL) 47 if (rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_name==NULL)
46 _wctrans_init(rl); 48 _wctrans_init(rl);
47 return (&rl->rl_wctrans[_WCTRANS_INDEX_LOWER]); 49 return (&rl->rl_wctrans[_WCTRANS_INDEX_LOWER]);
48} 50}
49 51
50static __inline struct _WCTransEntry * 52static __inline struct _WCTransEntry *
51_wctrans_upper(_RuneLocale *rl) 53_wctrans_upper(_RuneLocale *rl)
52{ 54{
53 if (rl->rl_wctrans[_WCTRANS_INDEX_UPPER].te_name==NULL) 55 if (rl->rl_wctrans[_WCTRANS_INDEX_UPPER].te_name==NULL)
54 _wctrans_init(rl); 56 _wctrans_init(rl);
55 return (&rl->rl_wctrans[_WCTRANS_INDEX_UPPER]); 57 return (&rl->rl_wctrans[_WCTRANS_INDEX_UPPER]);
56} 58}
57 59
58#endif 60#endif /*_WCTRANS_LOCAL_H_*/

File Added: src/lib/libc/locale/_wctype.c
/* $NetBSD: _wctype.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

/*-
 * Copyright (c) 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * Paul Borman at Krystal Technologies.
 *
 * 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)
__RCSID("$NetBSD: _wctype.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>

#include "rune.h"
#include "_wctrans_local.h"
#include "_wctype_local.h"

_RuneType
_runetype_priv(_RuneLocale const *rl, wint_t wc)
{
	__nbrune_t wc0;
	_RuneRange const *rr;
	_RuneEntry *base, *re;
	uint32_t x;

	_DIAGASSERT(rl != NULL);

	if (wc == WEOF)
		return 0U;
	if (_RUNE_ISCACHED(wc))
		return rl->rl_runetype[(size_t)wc];
	wc0 = (__nbrune_t)wc;
	rr = &rl->rl_runetype_ext;
	_DIAGASSERT(rr != NULL);
	base = rr->rr_rune_ranges;
	for (x = rr->rr_nranges; x != (uint32_t)0; x >>= 1) {
		re = base + (x >> 1);
		if (re->re_min <= wc0 && re->re_max >= wc0) {
			if (re->re_rune_types)
				return re->re_rune_types[wc0 - re->re_min];
			else
				return re->re_map;
		} else if (wc0 > re->re_max) {
			base = re + 1;
			--x;
		}
	}
	return (_RuneType)0U;
}

int
_iswctype_priv(_RuneLocale const *rl,
    wint_t wc, _WCTypeEntry const *te)
{
	return !!(_runetype_priv(rl, wc) & te->te_mask);
}

wint_t
_towctrans_priv(_RuneLocale const *rl,
    wint_t wc, _WCTransEntry const *te)
{
	__nbrune_t wc0;
	_RuneRange *rr;
	_RuneEntry *base, *re;
	uint32_t x;

	_DIAGASSERT(rl != NULL);
	_DIAGASSERT(te != NULL);

	if (wc == WEOF)
		return wc;
	if (te->te_name == NULL)
		_wctrans_init(__UNCONST(rl));
	if (_RUNE_ISCACHED(wc))
		return te->te_cached[(size_t)wc];
	wc0 = (__nbrune_t)wc;
	rr = te->te_extmap;
	_DIAGASSERT(rr != NULL);
	base = rr->rr_rune_ranges;
	for (x = rr->rr_nranges; x != (uint32_t)0; x >>= 1) {
		re = base + (x >> 1);
		if (re->re_min <= wc0 && re->re_max >= wc0) {
			return re->re_map + wc0 - re->re_min;
		} else if (wc0 >= re->re_max) {
			base = re + 1;
			--x;
		}
	}
	return wc;
}

File Added: src/lib/libc/locale/_wctype_local.h
/* $NetBSD: _wctype_local.h,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*-
 * Copyright (c) 2008 Citrus Project,
 * 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.
 */

#ifndef _WCTYPE_LOCAL_H_
#define _WCTYPE_LOCAL_H_

__BEGIN_DECLS
_RuneType	_runetype_priv(_RuneLocale const *, wint_t);
int		_iswctype_priv(_RuneLocale const *, wint_t, _WCTypeEntry const *);
wint_t		_towctrans_priv(_RuneLocale const *, wint_t, _WCTransEntry const *);
__END_DECLS

#endif /*_WCTYPE_LOCAL_H_*/

File Added: src/lib/libc/locale/Attic/bsdctype.c
/* $NetBSD: bsdctype.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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 <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: bsdctype.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include <sys/types.h>
#define _CTYPE_PRIVATE
#include <ctype.h>

#include "bsdctype.h"

const _BSDCTypeLocale _DefaultBSDCTypeLocale = {
    _C_ctype_,
    _C_tolower_,
    _C_toupper_
};

const _BSDCTypeLocale *_CurrentBSDCTypeLocale = &_DefaultBSDCTypeLocale;

File Added: src/lib/libc/locale/Attic/bsdctype.h
/* $NetBSD: bsdctype.h,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _BSDCTYPE_H_
#define _BSDCTYPE_H_

typedef struct _BSDCTypeLocale {
	const unsigned char	*ctype_tab;
	const short		*tolower_tab;
	const short		*toupper_tab;
} _BSDCTypeLocale;

extern const _BSDCTypeLocale _DefaultBSDCTypeLocale;
extern const _BSDCTypeLocale *_CurrentBSDCTypeLocale;

#endif /*_BSDCTYPE_H_*/

File Added: src/lib/libc/locale/Attic/current_locale.c
/* $NetBSD: current_locale.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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 <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: current_locale.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include <sys/cdefs.h>
#include <sys/types.h>
#include <langinfo.h>
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include <stdlib.h>

#include "setlocale_local.h"

static struct _locale_impl_t *__current_locale = &_global_locale;

struct _locale_impl_t **
_current_locale()
{
	return &__current_locale;
}

File Added: src/lib/libc/locale/dummy_lc_collate.c
/* $NetBSD: dummy_lc_collate.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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 <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: dummy_lc_collate.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include <sys/types.h>
#include <assert.h>
#include <langinfo.h>
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "setlocale_local.h"

/*
 * macro required by dummy_lc_template.h
 */
#define _PREFIX(name)		__CONCAT(_dummy_LC_COLLATE_,name)

#define _CATEGORY_ID		LC_COLLATE
#define _CATEGORY_NAME		"LC_COLLATE"

#include "dummy_lc_template.h"
_LOCALE_CATEGORY_ENTRY(_dummy_LC_COLLATE_);

File Added: src/lib/libc/locale/dummy_lc_template.h
/* $NetBSD: dummy_lc_template.h,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _DUMMY_LC_TEMPLATE_H_
#define _DUMMY_LC_TEMPLATE_H_

#include "generic_lc_template_decl.h"

static const char *
_PREFIX(setlocale)(const char * __restrict name,
    struct _locale_impl_t * __restrict locale)
{
	if (name != NULL) {
		if (*name == '\0')
			name = _get_locale_env(_CATEGORY_NAME);
		if (strcmp(name, locale->part_name[(size_t)_CATEGORY_ID])) {
			if (!strcmp(_C_LOCALE, name))
				name = _C_LOCALE;
			else if (!strcmp(_POSIX_LOCALE, name))
				name = _POSIX_LOCALE;
			else
				return NULL;
			locale->part_name[(size_t)_CATEGORY_ID] = name;
		}
	}
	return locale->part_name[(size_t)_CATEGORY_ID];
}

#include "generic_lc_template.h"

#endif /*_DUMMY_LC_TEMPLATE_H_*/

File Added: src/lib/libc/locale/fix_grouping.c
/* $NetBSD: fix_grouping.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*
 * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
 * 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.
 *
 * Original version ID:
 *     FreeBSD: fix_grouping.c,v 1.8 2003/06/26 10:46:16 phantom Exp
 */

#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: fix_grouping.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include <ctype.h>
#include <limits.h>
#include <stddef.h>

#include "fix_grouping.h"

#ifndef NBCHAR_MAX
#define NBCHAR_MAX	CHAR_MAX
#endif

static const char nogrouping[] = { NBCHAR_MAX, '\0' };

/* don't use libc's isdigit, it owes locale. */
#undef isdigit
#define isdigit(c)	(c >= '0' && c <= '9')

/*
 * Internal helper used to convert grouping sequences from string
 * representation into POSIX specified form, i.e.
 *
 * "3;3;-1" -> "\003\003\177\000"
 */

const char *
__fix_locale_grouping_str(const char *str)
{
	char *src, *dst;
	char n;

	if (str == NULL || *str == '\0') {
		return nogrouping;
	}

	for (src = __UNCONST(str), dst = __UNCONST(str); *src != '\0'; src++) {

		/* input string examples: "3;3", "3;2;-1" */
		if (*src == ';')
			continue;
	
		if (*src == '-' && *(src+1) == '1') {
			*dst++ = NBCHAR_MAX;
			src++;
			continue;
		}

		if (!isdigit((unsigned char)*src)) {
			/* broken grouping string */
			return nogrouping;
		}

		/* assume all numbers <= 99 */
		n = *src - '0';
		if (isdigit((unsigned char)*(src+1))) {
			src++;
			n *= 10;
			n += *src - '0';
		}

		*dst = n;
		/* NOTE: assume all input started with "0" as 'no grouping' */
		if (*dst == '\0')
			return (dst == __UNCONST(str)) ? nogrouping : str;
		dst++;
	}
	*dst = '\0';
	return str;
}

File Added: src/lib/libc/locale/fix_grouping.h
/* $NetBSD: fix_grouping.h,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*-
 * Copyright (c) 2008 Citrus Project,
 * 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.
 */

#ifndef _FIX_GROUPING_H_
#define _FIX_GROUPING_H_

__BEGIN_DECLS
const char *__fix_locale_grouping_str(const char *);
__END_DECLS

#endif /*_FIX_GROUPING_H_*/

File Added: src/lib/libc/locale/generic_lc_all.c
/* $NetBSD: generic_lc_all.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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 <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: generic_lc_all.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include <sys/types.h>
#include <assert.h>
#include <langinfo.h>
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "setlocale_local.h"

/*
 * macro required by all template headers
 */
#define _PREFIX(name)	__CONCAT(_generic_LC_ALL_, name)

#include "generic_lc_template_decl.h"

const char *
_generic_LC_ALL_setlocale(const char * __restrict name,
    struct _locale_impl_t * __restrict locale)
{
	_locale_category_t *l;
	char head[_LOCALENAME_LEN_MAX * (_LC_LAST - 1)], *tail;
	const char *tokens[_LC_LAST], *s, *t;
	int i, j;

	l = _find_category(1);
	_DIAGASSERT(l != NULL);
	if (name != NULL) {
		strlcpy(&head[0], name, sizeof(head));
		tokens[1] = &head[0];
		tail = strchr(tokens[1], '/');
		if (tail == NULL) {
			for (i = 2; i < _LC_LAST; ++i)
				tokens[i] = tokens[1];
		} else {
			*tail++ = '\0';
			for (i = 2; i < _LC_LAST - 1; ++i) {
				tokens[i] = (const char *)tail;
				tail = strchr(tokens[i], '/');
				if (tail == NULL)
					return NULL;
				*tail++ = '\0';
			}
			tokens[_LC_LAST - 1] = (const char *)tail;
			tail = strchr(tokens[i], '/');
			if (tail == NULL)
				return NULL;
		}
		(*l->setlocale)(tokens[1], locale);
	}
	s = (*l->setlocale)(NULL, locale);
	_DIAGASSERT(s != NULL);
	strlcpy(&locale->query[0], s, sizeof(locale->query));
	for (i = 2, j = 0; i < _LC_LAST; ++i) {
		l = _find_category(i);
		_DIAGASSERT(l != NULL);
		if (name != NULL)
			(*l->setlocale)(tokens[1], locale);
		t = (*l->setlocale)(NULL, locale);
		_DIAGASSERT(t != NULL);
		if (j == 0) {
			if (!strcmp(s, t))
				continue;
			for (j = 2; j < i; ++j) {
				strlcat(&locale->query[0], "/",
				    sizeof(locale->query));
				strlcat(&locale->query[0], s,
				    sizeof(locale->query));
			}
		}
		strlcat(&locale->query[0], "/", sizeof(locale->query));
		strlcat(&locale->query[0], t, sizeof(locale->query));
	}
	return (const char *)&locale->query[0];
}

/*
 * macro requrired by generic_lc_template.h
 */
#define _CATEGORY_ID	LC_ALL

#include "generic_lc_template.h"
_LOCALE_CATEGORY_ENTRY(_generic_LC_ALL_);

File Added: src/lib/libc/locale/Attic/generic_lc_template.h
/* $NetBSD: generic_lc_template.h,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _GENERIC_LC_TEMPLATE_H_
#define _GENERIC_LC_TEMPLATE_H_

#ifdef __lint__
#define STATIC	/**/
#else
#define STATIC	static
#endif

#define _LOCALE_CATEGORY_ENTRY(name)			\
STATIC const _locale_category_t name##desc = {		\
    .category = _CATEGORY_ID,				\
    .setlocale = &name##setlocale,			\
};							\
__link_set_add_data(all_categories, name##desc)

#endif /*_GENERIC_LC_TEMPLATE_H_*/

File Added: src/lib/libc/locale/generic_lc_template_decl.h
/* $NetBSD: generic_lc_template_decl.h,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _GENERIC_LC_TEMPLATE_DECL_H_
#define _GENERIC_LC_TEMPLATE_DECL_H_

static const char * _PREFIX(setlocale)(const char * __restrict,
    struct _locale_impl_t * __restrict);

#endif /*_GENERIC_LC_TEMPLATE_DECL_H_*/

File Added: src/lib/libc/locale/global_locale.c
/* $NetBSD: global_locale.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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 <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: global_locale.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include <sys/types.h>
#include <sys/localedef.h>
#define _CTYPE_PRIVATE
#include <ctype.h>
#include <langinfo.h>
#include <limits.h>
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include <stdlib.h>
#ifdef WITH_RUNE
#include "rune.h"
#else
#include "bsdctype.h"
#endif

#include "setlocale_local.h"

struct _locale_impl_t _global_locale =
{
    .cache = {
        .ctype_tab   = (const unsigned char *)&_C_ctype_[0],
        .tolower_tab = (const short *)&_C_tolower_[0],
        .toupper_tab = (const short *)&_C_toupper_[0],
        .mb_cur_max = (size_t)1,
        .ldata = {
	    .decimal_point	= __UNCONST("."),
	    .thousands_sep	= __UNCONST(""),
	    .grouping		= __UNCONST(""),
	    .int_curr_symbol	= __UNCONST(""),
	    .currency_symbol	= __UNCONST(""),
	    .mon_decimal_point	= __UNCONST(""),
	    .mon_thousands_sep	= __UNCONST(""),
	    .mon_grouping	= __UNCONST(""),
	    .positive_sign	= __UNCONST(""),
	    .negative_sign	= __UNCONST(""),
	    .int_frac_digits	= CHAR_MAX,
	    .frac_digits	= CHAR_MAX,
	    .p_cs_precedes	= CHAR_MAX,
	    .p_sep_by_space	= CHAR_MAX,
	    .n_cs_precedes	= CHAR_MAX,
	    .n_sep_by_space	= CHAR_MAX,
	    .p_sign_posn	= CHAR_MAX,
	    .n_sign_posn	= CHAR_MAX,
	    .int_p_cs_precedes	= CHAR_MAX,
	    .int_n_cs_precedes	= CHAR_MAX,
	    .int_p_sep_by_space	= CHAR_MAX,
	    .int_n_sep_by_space	= CHAR_MAX,
	    .int_p_sign_posn	= CHAR_MAX,
	    .int_n_sign_posn	= CHAR_MAX,
        },
        .items = {
	    [(size_t)D_T_FMT    ] = "%a %b %e %H:%M:%S %Y",
	    [(size_t)D_FMT      ] = "%m/%d/%y",
	    [(size_t)T_FMT      ] = "%H:%M:%S",
	    [(size_t)T_FMT_AMPM ] = "%I:%M:%S %p",
	    [(size_t)AM_STR     ] = "AM",
	    [(size_t)PM_STR     ] = "PM",
	    [(size_t)DAY_1      ] = "Sun",
	    [(size_t)DAY_2      ] = "Mon",
	    [(size_t)DAY_3      ] = "Tue",
	    [(size_t)DAY_4      ] = "Wed",
	    [(size_t)DAY_5      ] = "Thu",
	    [(size_t)DAY_6      ] = "Fri",
	    [(size_t)DAY_7      ] = "Sat",
	    [(size_t)ABDAY_1    ] = "Sunday",
	    [(size_t)ABDAY_2    ] = "Monday",
	    [(size_t)ABDAY_3    ] = "Tuesday",
	    [(size_t)ABDAY_4    ] = "Wednesday",
	    [(size_t)ABDAY_5    ] = "Thursday",
	    [(size_t)ABDAY_6    ] = "Friday",
	    [(size_t)ABDAY_7    ] = "Saturday",
	    [(size_t)MON_1      ] = "Jan",
	    [(size_t)MON_2      ] = "Feb",
	    [(size_t)MON_3      ] = "Mar",
	    [(size_t)MON_4      ] = "Apr",
	    [(size_t)MON_5      ] = "May",
	    [(size_t)MON_6      ] = "Jun",
	    [(size_t)MON_7      ] = "Jul",
	    [(size_t)MON_8      ] = "Aug",
	    [(size_t)MON_9      ] = "Sep",
	    [(size_t)MON_10     ] = "Oct",
	    [(size_t)MON_11     ] = "Nov",
	    [(size_t)MON_12     ] = "Dec",
	    [(size_t)ABMON_1    ] = "January",
	    [(size_t)ABMON_2    ] = "February",
	    [(size_t)ABMON_3    ] = "March",
	    [(size_t)ABMON_4    ] = "April",
	    [(size_t)ABMON_5    ] = "May",
	    [(size_t)ABMON_6    ] = "June",
	    [(size_t)ABMON_7    ] = "July",
	    [(size_t)ABMON_8    ] = "Augst",
	    [(size_t)ABMON_9    ] = "September",
	    [(size_t)ABMON_10   ] = "October",
	    [(size_t)ABMON_11   ] = "November",
	    [(size_t)ABMON_12   ] = "December",
	    [(size_t)RADIXCHAR  ] = ".",
	    [(size_t)THOUSEP    ] = "",
	    [(size_t)YESSTR     ] = "yes",
	    [(size_t)YESEXPR    ] = "^[Yy]",
	    [(size_t)NOSTR      ] = "no",
	    [(size_t)NOEXPR     ] = "^[Nn]",
	    [(size_t)CRNCYSTR   ] = NULL,
	    [(size_t)CODESET    ] = "646",
	    [(size_t)ERA        ] = NULL,
	    [(size_t)ERA_D_FMT  ] = NULL,
	    [(size_t)ERA_D_T_FMT] = NULL,
	    [(size_t)ERA_T_FMT  ] = NULL,
	    [(size_t)ALT_DIGITS ] = NULL,
        },
    },
    .query = /*_C_LOCALE*/ { 'C', '\0' },
    .part_name = {
	[(size_t)LC_ALL     ] = _C_LOCALE,
	[(size_t)LC_COLLATE ] = _C_LOCALE,
	[(size_t)LC_CTYPE   ] = _C_LOCALE,
	[(size_t)LC_MONETARY] = _C_LOCALE,
	[(size_t)LC_NUMERIC ] = _C_LOCALE,
	[(size_t)LC_TIME    ] = _C_LOCALE,
	[(size_t)LC_MESSAGES] = _C_LOCALE,
    },
    .part_impl = {
	[(size_t)LC_ALL     ] = (_locale_part_t)NULL,
	[(size_t)LC_COLLATE ] = (_locale_part_t)NULL,
	[(size_t)LC_CTYPE   ] = (_locale_part_t)
#ifdef WITH_RUNE
	    __UNCONST(&_DefaultRuneLocale),
#else
	    __UNCONST(&_DefaultBSDCTypeLocale),
#endif
	[(size_t)LC_MONETARY] = (_locale_part_t)
	    __UNCONST(&_DefaultMonetaryLocale),
	[(size_t)LC_NUMERIC ] = (_locale_part_t)
	    __UNCONST(&_DefaultNumericLocale),
	[(size_t)LC_MESSAGES] = (_locale_part_t)
	    __UNCONST(&_DefaultMessagesLocale),
    },
};

File Added: src/lib/libc/locale/iswctype_mb.c
/* $NetBSD: iswctype_mb.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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 <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: iswctype_mb.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include "namespace.h"
#include <sys/types.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <langinfo.h>
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <wctype.h>

#include "setlocale_local.h"

#include "rune.h"
#include "_wctype_local.h"
#include "_wctrans_local.h"

#define _RUNE_LOCALE() ((_RuneLocale const *) \
    (*_current_locale())->part_impl[(size_t)LC_CTYPE])

#define _ISWCTYPE_FUNC(name, index)			\
int							\
isw##name(wint_t wc)					\
{							\
	_RuneLocale const *rl;				\
	_WCTypeEntry const *te;				\
							\
	rl = _RUNE_LOCALE();				\
	te = &rl->rl_wctype[index];			\
	return _iswctype_priv(rl, wc, te);		\
}
_ISWCTYPE_FUNC(alnum,  _WCTYPE_INDEX_ALNUM)
_ISWCTYPE_FUNC(alpha,  _WCTYPE_INDEX_ALPHA)
_ISWCTYPE_FUNC(blank,  _WCTYPE_INDEX_BLANK)
_ISWCTYPE_FUNC(cntrl,  _WCTYPE_INDEX_CNTRL)
_ISWCTYPE_FUNC(digit,  _WCTYPE_INDEX_DIGIT)
_ISWCTYPE_FUNC(graph,  _WCTYPE_INDEX_GRAPH)
_ISWCTYPE_FUNC(lower,  _WCTYPE_INDEX_LOWER)
_ISWCTYPE_FUNC(print,  _WCTYPE_INDEX_PRINT)
_ISWCTYPE_FUNC(punct,  _WCTYPE_INDEX_PUNCT)
_ISWCTYPE_FUNC(space,  _WCTYPE_INDEX_SPACE)
_ISWCTYPE_FUNC(upper,  _WCTYPE_INDEX_UPPER)
_ISWCTYPE_FUNC(xdigit, _WCTYPE_INDEX_XDIGIT)

#define _TOWCTRANS_FUNC(name, index)			\
wint_t							\
tow##name(wint_t wc)					\
{							\
	_RuneLocale const *rl;				\
	_WCTransEntry const *te;			\
							\
	rl = _RUNE_LOCALE();				\
	te = &rl->rl_wctrans[index];			\
	return _towctrans_priv(rl, wc, te);		\
}
_TOWCTRANS_FUNC(upper, _WCTRANS_INDEX_UPPER)
_TOWCTRANS_FUNC(lower, _WCTRANS_INDEX_LOWER)

wctype_t
wctype(const char *charclass)
{
	_RuneLocale const *rl;
	size_t i;

	rl = _RUNE_LOCALE();
	for (i = 0; i < _WCTYPE_NINDEXES; ++i) {
		if (!strcmp(rl->rl_wctype[i].te_name, charclass))
			return (wctype_t)__UNCONST(&rl->rl_wctype[i]);
	}
	return (wctype_t)NULL;
}

wctrans_t
wctrans(const char *charmap)
{
	_RuneLocale const *rl;
	size_t i;

	rl = _RUNE_LOCALE();
	if (rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_name == NULL)
		_wctrans_init(__UNCONST(rl));
	for (i = 0; i < _WCTRANS_NINDEXES; ++i) {
		if (!strcmp(rl->rl_wctrans[i].te_name, charmap))
			return (wctrans_t)__UNCONST(&rl->rl_wctype[i]);
	}
	return (wctrans_t)NULL;
}

int
iswctype(wint_t wc, wctype_t charclass)
{
	_RuneLocale const *rl;
	_WCTypeEntry const *te;

	if (charclass == NULL) {
		errno = EINVAL;
		return 0;
	}
	rl = _RUNE_LOCALE();
	te = (_WCTypeEntry const *)charclass;
	return _iswctype_priv(rl, wc, te);
}

wint_t
towctrans(wint_t wc, wctrans_t charmap)
{
	_RuneLocale const *rl;
	_WCTransEntry const *te;

	if (charmap == NULL) {
		errno = EINVAL;
		return wc;
	}
	rl = _RUNE_LOCALE();
	te = (_WCTransEntry const *)charmap;
	return _towctrans_priv(rl, wc, te);
}

__weak_alias(wcwidth,_wcwidth)

int
wcwidth(wchar_t wc)
{
	_RuneLocale const *rl;
	_RuneType x;

	if (wc == L'\0')
		return 0;
	rl = _RUNE_LOCALE();
	x = _runetype_priv(rl, wc);
	if (x & _CTYPE_R)
		return ((unsigned)x & _CTYPE_SWM) >> _CTYPE_SWS;
	return -1;
}

int
wcswidth(const wchar_t * __restrict ws, size_t wn)
{
	_RuneLocale const *rl;
	_RuneType x;
	int width;

	_DIAGASSERT(ws != NULL);

	rl = _RUNE_LOCALE();
	width = 0;
	while (wn > 0 && *ws != L'\0') {
		x = _runetype_priv(rl, *ws);
		if ((x & _CTYPE_R) == 0)
			return -1;
		width += ((unsigned)x & _CTYPE_SWM) >> _CTYPE_SWS;
		++ws, --wn;
	}
	return width;
}

File Added: src/lib/libc/locale/Attic/localeio_lc_ctype.c
/* $NetBSD: localeio_lc_ctype.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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 <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: localeio_lc_ctype.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include "reentrant.h"
#include <sys/types.h>
#include <sys/queue.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <langinfo.h>
#include <limits.h>
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "setlocale_local.h"

#include "aliasname_local.h"
#include "bsdctype.h"
#include "ctypeio.h"

/*
 * macro required by all template headers
 */
#define _PREFIX(name)		__CONCAT(_localeio_LC_CTYPE_, name)

/*
 * macro required by nb_lc_template(_decl).h
 */
#define _CATEGORY_TYPE		_BSDCTypeLocale

#include "nb_lc_template_decl.h"

static int
/*ARGSUSED*/
_localeio_LC_CTYPE_create_impl(const char * __restrict root,
    const char * __restrict name, _BSDCTypeLocale ** __restrict pdata)
{
	char path[PATH_MAX + 1];

	_DIAGASSERT(root != NULL);
	_DIAGASSERT(name != NULL);
	_DIAGASSERT(pdata != NULL);

	snprintf(path, sizeof(path),
	    "%s/%s/LC_CTYPE", root, name);
	return __loadctype(path, pdata);
}

static __inline void
_PREFIX(build_cache)(struct _locale_cache_t * __restrict cache,
    _BSDCTypeLocale * __restrict data)
{
	_DIAGASSERT(cache != NULL);
	_DIAGASSERT(data != NULL);

	cache->ctype_tab = data->ctype_tab;
	cache->tolower_tab = data->tolower_tab;
	cache->toupper_tab = data->toupper_tab;
	cache->mb_cur_max = (size_t)1;
}

static __inline void
_PREFIX(fixup)(_BSDCTypeLocale *data)
{
	_DIAGASSERT(data != NULL);

	_ctype_ = data->ctype_tab;
	_tolower_tab_ = data->tolower_tab;
	_toupper_tab_ = data->toupper_tab;
}

/*
 * macro required by nb_lc_template.h
 */
#define _CATEGORY_ID		LC_CTYPE
#define _CATEGORY_NAME		"LC_CTYPE"
#define _CATEGORY_DEFAULT	_DefaultBSDCTypeLocale

#include "nb_lc_template.h"
#include "generic_lc_template.h"
_LOCALE_CATEGORY_ENTRY(_localeio_LC_CTYPE_);

File Added: src/lib/libc/locale/Attic/localeio_lc_messages.c
/* $NetBSD: localeio_lc_messages.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*
 * Copyright (c) 2008, The NetBSD Foundation, Inc.
 * All rights reserved.
 * 
 * This code is derived from software contributed to The NetBSD Foundation
 * by Brian Ginsbach.
 *
 * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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)
__RCSID("$NetBSD: localeio_lc_messages.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include "reentrant.h"
#include <sys/types.h>
#include <sys/localedef.h>
#include <sys/queue.h>
#include <assert.h>
#include <errno.h>
#include <langinfo.h>
#include <limits.h>
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "setlocale_local.h"

#include "aliasname_local.h"
#include "localeio.h"

/*
 * macro required by all template headers
 */
#define _PREFIX(name)		__CONCAT(_localeio_LC_MESSAGES_, name)

#include "nb_lc_messages_misc.h"
#include "nb_lc_template_decl.h"

#define NSTRINGS (sizeof(_MessagesLocale)/sizeof(const char **))

static int
_localeio_LC_MESSAGES_create_impl(const char * __restrict root,
    const char * __restrict name, _MessagesLocale ** __restrict pdata)
{
	char path[PATH_MAX + 1];

	_DIAGASSERT(root != NULL);
	_DIAGASSERT(name != NULL);
	_DIAGASSERT(pdata != NULL);

	snprintf(path, sizeof(path),
	    "%s/%s/LC_MESSAGES/SYS_LC_MESSAGES", root, name);
	return __loadlocale(path, NSTRINGS, 0, sizeof(_MessagesLocale),
	    (void *)pdata);
}

#include "nb_lc_template.h"
_LOCALE_CATEGORY_ENTRY(_localeio_LC_MESSAGES_);

File Added: src/lib/libc/locale/Attic/localeio_lc_monetary.c
/* $NetBSD: localeio_lc_monetary.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $ */

/*
 * Copyright (c) 2008, The NetBSD Foundation, Inc.
 * All rights reserved.
 * 
 * This code is derived from software contributed to The NetBSD Foundation
 * by Brian Ginsbach.
 *
 * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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)
__RCSID("$NetBSD: localeio_lc_monetary.c,v 1.1.2.2 2009/01/04 17:02:19 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include "reentrant.h"
#include <sys/types.h>
#include <sys/localedef.h>
#include <sys/queue.h>
#include <assert.h>
#include <errno.h>
#include <langinfo.h>
#include <limits.h>
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "setlocale_local.h"

#include "aliasname_local.h"
#include "fix_grouping.h"
#include "localeio.h"

/*
 * macro required by all template headers
 */
#define _PREFIX(name)		__CONCAT(_localeio_LC_MONETARY_, name)

#include "nb_lc_monetary_misc.h"
#include "nb_lc_template_decl.h"

#define NSTRINGS \
	(offsetof(_MonetaryLocale, int_frac_digits)/sizeof(const char **))
#define NCHARS \
	(offsetof(_MonetaryLocale, int_n_sign_posn) - \
	 offsetof(_MonetaryLocale, int_frac_digits) + 1)

static int
_localeio_LC_MONETARY_create_impl(const char * __restrict root,
    const char * __restrict name, _MonetaryLocale ** __restrict pdata)
{
	char path[PATH_MAX + 1];
	int ret;

        _DIAGASSERT(root != NULL);
        _DIAGASSERT(name != NULL);
        _DIAGASSERT(pdata != NULL);

	snprintf(path, sizeof(path),
            "%s/%s/LC_MONETARY", root, name);
	ret = __loadlocale(path, NSTRINGS, NCHARS, sizeof(_MonetaryLocale),
	    (void *)pdata);
	if (!ret) {
		(*pdata)->mon_grouping =
		   __fix_locale_grouping_str((*pdata)->mon_grouping);
	}
	return ret;
}

#include "nb_lc_template.h"
_LOCALE_CATEGORY_ENTRY(_localeio_LC_MONETARY_);

File Added: src/lib/libc/locale/Attic/localeio_lc_numeric.c
/* $NetBSD: localeio_lc_numeric.c,v 1.1.2.2 2009/01/04 17:02:20 christos Exp $ */

/*
 * Copyright (c) 2008, The NetBSD Foundation, Inc.
 * All rights reserved.
 * 
 * This code is derived from software contributed to The NetBSD Foundation
 * by Brian Ginsbach.
 *
 * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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)
__RCSID("$NetBSD: localeio_lc_numeric.c,v 1.1.2.2 2009/01/04 17:02:20 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include "reentrant.h"
#include <sys/types.h>
#include <sys/localedef.h>
#include <sys/queue.h>
#include <assert.h>
#include <errno.h>
#include <langinfo.h>
#include <limits.h>
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "setlocale_local.h"

#include "aliasname_local.h"
#include "fix_grouping.h"
#include "localeio.h"

/*
 * macro required by all template headers
 */
#define _PREFIX(name)		__CONCAT(_localeio_LC_NUMERIC_, name)

#include "nb_lc_numeric_misc.h"
#include "nb_lc_template_decl.h"

#define NSTRINGS (sizeof(_NumericLocale)/sizeof(const char **))

static int
_localeio_LC_NUMERIC_create_impl(const char * __restrict root,
    const char * __restrict name, _NumericLocale ** __restrict pdata)
{
	char path[PATH_MAX + 1];
	int ret;

	_DIAGASSERT(root != NULL);
	_DIAGASSERT(name != NULL);
	_DIAGASSERT(pdata != NULL);

	snprintf(path, sizeof(path),
	    "%s/%s/LC_NUMERIC", root, name);
	ret = __loadlocale(path, NSTRINGS, 0, sizeof(_NumericLocale),
	    (void *)pdata);
	if (!ret) {
		(*pdata)->grouping =
                   __fix_locale_grouping_str((*pdata)->grouping);
	}
	return ret;
}

#include "nb_lc_template.h"
_LOCALE_CATEGORY_ENTRY(_localeio_LC_NUMERIC_);

File Added: src/lib/libc/locale/Attic/localeio_lc_time.c
/* $NetBSD: localeio_lc_time.c,v 1.1.2.2 2009/01/04 17:02:20 christos Exp $ */

/*
 * Copyright (c) 2008, The NetBSD Foundation, Inc.
 * All rights reserved.
 * 
 * This code is derived from software contributed to The NetBSD Foundation
 * by Brian Ginsbach.
 *
 * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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)
__RCSID("$NetBSD: localeio_lc_time.c,v 1.1.2.2 2009/01/04 17:02:20 christos Exp $");
#endif /* LIBC_SCCS and not lint */

#include "reentrant.h"
#include <sys/types.h>
#include <sys/localedef.h>
#include <sys/queue.h>
#include <assert.h>
#include <errno.h>
#include <langinfo.h>
#include <limits.h>
#define __SETLOCALE_SOURCE__
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "setlocale_local.h"

#include "aliasname_local.h"
#include "fix_grouping.h"
#include "localeio.h"

/*
 * macro required by all template headers
 */
#define _PREFIX(name)		__CONCAT(_localeio_LC_TIME_, name)

#include "nb_lc_time_misc.h"
#include "nb_lc_template_decl.h"

#define NSTRINGS (sizeof(_TimeLocale)/sizeof(const char **))

static int
_localeio_LC_TIME_create_impl(const char * __restrict root,
    const char * __restrict name, _TimeLocale ** __restrict pdata)
{
	char path[PATH_MAX + 1];

	_DIAGASSERT(root != NULL);
	_DIAGASSERT(name != NULL);
	_DIAGASSERT(pdata != NULL);

	snprintf(path, sizeof(path),
	    "%s/%s/LC_TIME", root, name);
	return __loadlocale(path, NSTRINGS, 0, sizeof(_TimeLocale),
	    (void *)pdata);
}

#include "nb_lc_template.h"
_LOCALE_CATEGORY_ENTRY(_localeio_LC_TIME_);

File Added: src/lib/libc/locale/nb_lc_messages_misc.h
/* $NetBSD: nb_lc_messages_misc.h,v 1.1.2.2 2009/01/04 17:02:20 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _NB_LC_MESSAGES_MISC_H_
#define _NB_LC_MESSAGES_MISC_H_

/*
 * macro required by nb_lc_template(_decl).h
 */
#define _CATEGORY_TYPE		_MessagesLocale

static __inline void
_PREFIX(build_cache)(struct _locale_cache_t * __restrict cache,
    _MessagesLocale * __restrict data)
{
	_DIAGASSERT(cache != NULL);
	_DIAGASSERT(data != NULL);

	cache->items[(size_t)YESSTR ] = data->yesstr;
	cache->items[(size_t)YESEXPR] = data->yesexpr;
	cache->items[(size_t)NOSTR  ] = data->nostr;
	cache->items[(size_t)NOEXPR ] = data->noexpr;
}

static __inline void
_PREFIX(fixup)(_MessagesLocale *data)
{
	_DIAGASSERT(data != NULL);

	_CurrentMessagesLocale = data;
}

/*
 * macro required by nb_lc_template.h
 */
#define _CATEGORY_ID		LC_MESSAGES
#define _CATEGORY_NAME		"LC_MESSAGES"
#define _CATEGORY_DEFAULT	_DefaultMessagesLocale

#endif /*_NB_LC_MESSAGES_MISC_H_*/

File Added: src/lib/libc/locale/nb_lc_monetary_misc.h
/* $NetBSD: nb_lc_monetary_misc.h,v 1.1.2.2 2009/01/04 17:02:20 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _NB_LC_MONETARY_MISC_H_
#define _NB_LC_MONETARY_MISC_H_

/*
 * macro required by nb_lc_template(_decl).h
 */
#define _CATEGORY_TYPE		_MonetaryLocale

static __inline void
_PREFIX(build_cache)(struct _locale_cache_t * __restrict cache,
    _MonetaryLocale * __restrict data)
{
	_DIAGASSERT(cache != NULL);
	_DIAGASSERT(data != NULL);

	cache->ldata.int_curr_symbol   = __UNCONST(data->int_curr_symbol);
	cache->ldata.currency_symbol   = __UNCONST(data->currency_symbol);
	cache->ldata.mon_decimal_point = __UNCONST(data->mon_decimal_point);
	cache->ldata.mon_thousands_sep = __UNCONST(data->mon_thousands_sep);
	cache->ldata.mon_grouping      = __UNCONST(data->mon_grouping);
	cache->ldata.positive_sign     = __UNCONST(data->positive_sign);
	cache->ldata.negative_sign     = __UNCONST(data->negative_sign);

	cache->ldata.int_frac_digits    = data->int_frac_digits;
	cache->ldata.frac_digits        = data->frac_digits;
	cache->ldata.p_cs_precedes      = data->p_cs_precedes;
	cache->ldata.p_sep_by_space     = data->p_sep_by_space;
	cache->ldata.n_cs_precedes      = data->n_cs_precedes;
	cache->ldata.n_sep_by_space     = data->n_sep_by_space;
	cache->ldata.p_sign_posn        = data->p_sign_posn;
	cache->ldata.n_sign_posn        = data->n_sign_posn;
	cache->ldata.int_p_cs_precedes  = data->int_p_cs_precedes;
	cache->ldata.int_n_cs_precedes  = data->int_n_cs_precedes;
	cache->ldata.int_p_sep_by_space = data-> int_p_sep_by_space;
	cache->ldata.int_n_sep_by_space = data->int_n_sep_by_space;
	cache->ldata.int_p_sign_posn    = data->int_p_sign_posn;
	cache->ldata.int_n_sign_posn    = data->int_n_sign_posn;

	cache->items[(size_t)CRNCYSTR] = NULL; /* NOT IMPLEMENTED YET */
}

static __inline void
_PREFIX(fixup)(_MonetaryLocale *data)
{
	_DIAGASSERT(data != NULL);

	_CurrentMonetaryLocale = data;
}

/*
 * macro required by nb_lc_template.h
 */
#define _CATEGORY_ID		LC_MONETARY
#define _CATEGORY_NAME		"LC_MONETARY"
#define _CATEGORY_DEFAULT	_DefaultMonetaryLocale

#endif /*_RUNE_LC_MONETARY_MISC_H_*/

File Added: src/lib/libc/locale/nb_lc_numeric_misc.h
/* $NetBSD: nb_lc_numeric_misc.h,v 1.1.2.2 2009/01/04 17:02:20 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _NB_LC_NUMERIC_MISC_H_
#define _NB_LC_NUMERIC_MISC_H_

/*
 * macro required by nb_lc_template(_decl).h
 */
#define _CATEGORY_TYPE		_NumericLocale

static __inline void
_PREFIX(build_cache)(struct _locale_cache_t * __restrict cache,
    _NumericLocale * __restrict data)
{
	_DIAGASSERT(cache != NULL);
	_DIAGASSERT(data != NULL);

	cache->ldata.decimal_point = __UNCONST(data->decimal_point);
	cache->ldata.thousands_sep = __UNCONST(data->thousands_sep);
	cache->ldata.grouping      = __UNCONST(data->grouping);

	cache->items[(size_t)RADIXCHAR] = data->decimal_point;
	cache->items[(size_t)THOUSEP  ] = data->thousands_sep;
}

static __inline void
_PREFIX(fixup)(_NumericLocale *data)
{
	_DIAGASSERT(data != NULL);

	_CurrentNumericLocale = data;
}

/*
 * macro required by nb_lc_template.h
 */
#define _CATEGORY_ID		LC_NUMERIC
#define _CATEGORY_NAME		"LC_NUMERIC"
#define _CATEGORY_DEFAULT	_DefaultNumericLocale

#endif /*_NB_LC_NUMERIC_MISC_H_*/

File Added: src/lib/libc/locale/nb_lc_template.h
/* $NetBSD: nb_lc_template.h,v 1.1.2.2 2009/01/04 17:02:20 christos Exp $ */

/*-
 * Copyright (c)1999, 2008 Citrus Project,
 * 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.
 */

/*-
 * Copyright (c) 1998 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Paul Kranenburg.
 *
 * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
 */

/*-
 * Copyright (c) 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * Paul Borman at Krystal Technologies.
 *
 * 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.
 */

#ifndef _NB_LC_TEMPLATE_H_
#define _NB_LC_TEMPLATE_H_

#define _nb_part_t		_PREFIX(part_t)
#define _nb_part_cache		_PREFIX(part_cache)
#define _nb_default_c		_PREFIX(default_c)
#define _nb_default_posix	_PREFIX(default_posix)
#define _nb_mutex		_PREFIX(mutex)

typedef struct _nb_part_t {
	char name[_LOCALENAME_LEN_MAX];
	_CATEGORY_TYPE *impl;
	SIMPLEQ_ENTRY(_nb_part_t) entry;
} _nb_part_t;

static SIMPLEQ_HEAD(, _nb_part_t) _nb_part_cache =
    SIMPLEQ_HEAD_INITIALIZER(_nb_part_cache);

static const _nb_part_t _nb_default_c = {
    _C_LOCALE,
    __UNCONST(&_CATEGORY_DEFAULT),
    { NULL },
};

static const _nb_part_t _nb_default_posix = {
    _POSIX_LOCALE,
    __UNCONST(&_CATEGORY_DEFAULT),
    { NULL },
};

#ifdef _REENTRANT
static mutex_t _nb_mutex = MUTEX_INITIALIZER;
#endif

static int
_PREFIX(load_sub)(const char * __restrict name, const char * __restrict real,
    _nb_part_t ** __restrict part, int force)
{
	_nb_part_t *p, *q;
	int ret;

	_DIAGASSERT(name != NULL);
	_DIAGASSERT(part != NULL);

	if (!strcmp(_C_LOCALE, name)) {
		p = __UNCONST(&_nb_default_c);
	} else if (!strcmp(_POSIX_LOCALE, name)) {
		p = __UNCONST(&_nb_default_posix);
	} else {
		SIMPLEQ_FOREACH(p, &_nb_part_cache, entry) {
			if (!strcmp((const char *)&p->name[0], name))
				goto found;
		}
		p = malloc(sizeof(*p));
		if (p == NULL)
			return ENOMEM;
		if (force) {
			p->impl = __UNCONST(&_CATEGORY_DEFAULT);
		} else {
			_DIAGASSERT(_PathLocale != NULL);
			ret = _PREFIX(create_impl)((const char *)_PathLocale,
			    name, &p->impl);
			if (ret) {
				free(p);
				return ret;
			}
		}
		strlcpy(&p->name[0], name, sizeof(p->name));
		SIMPLEQ_INSERT_TAIL(&_nb_part_cache, p, entry);
	}
found:
	if (real != NULL) {
		q = malloc(sizeof(*q));
		if (q == NULL)
			return ENOMEM;
		strlcpy(&q->name[0], real, sizeof(p->name));
		q->impl = p->impl;
		SIMPLEQ_INSERT_TAIL(&_nb_part_cache, q, entry);
		p = q;
	}
	*part = p;
	return 0;
}

static __inline int
_PREFIX(load)(const char * __restrict name,
    _nb_part_t ** __restrict part)
{
	int ret, force;
	char path[PATH_MAX + 1], loccat[PATH_MAX + 1], buf[PATH_MAX + 1];
	const char *aliaspath, *alias;

#define _LOAD_SUB_ALIAS(key)						\
do {									\
	alias = __unaliasname(aliaspath, key, &buf[0], sizeof(buf));	\
	if (alias != NULL) {						\
		ret = (force = !__isforcemapping(alias))		\
		    ? _PREFIX(load_sub)(name, NULL, part, force)	\
		    : _PREFIX(load_sub)(alias, name, part, force);	\
		_DIAGASSERT(!ret || !force);				\
		goto done;						\
	}								\
} while (/*CONSTCOND*/0)

	/* (1) non-aliased file */
	mutex_lock(&_nb_mutex);
	ret = _PREFIX(load_sub)(name, NULL, part, 0);
	if (ret != ENOENT)
		goto done;

	/* (2) lookup locname/catname type alias */
	_DIAGASSERT(_PathLocale != NULL);
	snprintf(&path[0], sizeof(path),
	    "%s/" _LOCALE_ALIAS_NAME, _PathLocale);
	aliaspath = (const char *)&path[0];
	snprintf(&loccat[0], sizeof(loccat),
	    "%s/" _CATEGORY_NAME, name);
	_LOAD_SUB_ALIAS((const char *)&loccat[0]);

	/* (3) lookup locname type alias */
	_LOAD_SUB_ALIAS(name);

done:
	mutex_unlock(&_nb_mutex);
	return ret;
}

static const char *
_PREFIX(setlocale)(const char * __restrict name,
    struct _locale_impl_t * __restrict locale)
{
	_nb_part_t *part;

	/* name may be NULL */
	_DIAGASSERT(locale != NULL);

	if (name != NULL) {
		if (*name == '\0')
			name = _get_locale_env(_CATEGORY_NAME);
		_DIAGASSERT(name != NULL);
		_DIAGASSERT(locale->part_name[(size_t)_CATEGORY_ID] != NULL);
		if (strcmp(name, locale->part_name[(size_t)_CATEGORY_ID])) {
			if (_PREFIX(load)(name, &part))
				return NULL;
			locale->part_name[(size_t)_CATEGORY_ID]
			    = &part->name[0];
			locale->part_impl[(size_t)_CATEGORY_ID]
			    = part->impl;
			_PREFIX(build_cache)(&locale->cache, part->impl);
			if (locale == &_global_locale)
				_PREFIX(fixup)(part->impl);
		}
	}
	return locale->part_name[(size_t)_CATEGORY_ID];
}

#include "generic_lc_template.h"

#endif /*_NB_LC_TEMPLATE_H_*/

File Added: src/lib/libc/locale/nb_lc_template_decl.h
/* $NetBSD: nb_lc_template_decl.h,v 1.1.2.2 2009/01/04 17:02:20 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _NB_LC_TEMPLATE_DECL_H_
#define _NB_LC_TEMPLATE_DECL_H_

#include "generic_lc_template_decl.h"

static __inline int
_PREFIX(create_impl)(const char * __restrict,
    const char * __restrict, _CATEGORY_TYPE ** __restrict);

static __inline void
_PREFIX(build_cache)(struct _locale_cache_t * __restrict,
    _CATEGORY_TYPE * __restrict);

static __inline void
_PREFIX(fixup)(_CATEGORY_TYPE *);

#endif /*_NB_LC_TEMPLATE_DECL_H_*/

File Added: src/lib/libc/locale/nb_lc_time_misc.h
/* $NetBSD: nb_lc_time_misc.h,v 1.1.2.2 2009/01/04 17:02:20 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _NB_LC_TIME_MISC_H_
#define _NB_LC_TIME_MISC_H_

/*
 * macro required by nb_lc_template(_decl).h
 */
#define _CATEGORY_TYPE		_TimeLocale

#define ABDAY_IDX(idx)	((size_t)idx - (size_t)ABDAY_1)
#define DAY_IDX(idx)	((size_t)idx - (size_t)DAY_1)
#define ABMON_IDX(idx)	((size_t)idx - (size_t)ABMON_1)
#define MON_IDX(idx)	((size_t)idx - (size_t)MON_1)
#define AM_PM_IDX(idx)	((size_t)idx - (size_t)AM_STR)

static __inline void
/*ARGSUSED*/
_PREFIX(build_cache)(struct _locale_cache_t * __restrict cache,
    _TimeLocale * __restrict data)
{
	size_t i;

	_DIAGASSERT(cache != NULL);
	_DIAGASSERT(data != NULL);

        for (i = (size_t)ABDAY_1; i <= ABDAY_7;  ++i)
		cache->items[i] = data->abday[ABDAY_IDX(i)];
        for (i = (size_t)DAY_1;   i <= DAY_7;    ++i)
		cache->items[i] = data->day[DAY_IDX(i)];
        for (i = (size_t)ABMON_1; i <= ABMON_12; ++i)
		cache->items[i] = data->abmon[ABMON_IDX(i)];
        for (i = (size_t)MON_1;   i <= MON_12;   ++i)
		cache->items[i] = data->mon[MON_IDX(i)];
        for (i = (size_t)AM_STR;  i <= PM_STR;   ++i)
		cache->items[i] = data->am_pm[AM_PM_IDX(i)];
	cache->items[(size_t)D_T_FMT    ] = data->d_t_fmt;
	cache->items[(size_t)D_FMT      ] = data->d_fmt;
	cache->items[(size_t)T_FMT      ] = data->t_fmt;
	cache->items[(size_t)T_FMT_AMPM ] = data->t_fmt_ampm;

	/* NOT IMPLEMENTED YET */
	cache->items[(size_t)ERA        ] = NULL;
	cache->items[(size_t)ERA_D_FMT  ] = NULL;
	cache->items[(size_t)ERA_D_T_FMT] = NULL;
	cache->items[(size_t)ERA_T_FMT  ] = NULL;
	cache->items[(size_t)ALT_DIGITS ] = NULL;
}

static __inline void
_PREFIX(fixup)(_TimeLocale *data)
{
	_DIAGASSERT(data != NULL);

	_CurrentTimeLocale = data;
}

/*
 * macro required by nb_lc_template.h
 */
#define _CATEGORY_ID		LC_TIME
#define _CATEGORY_NAME		"LC_TIME"
#define _CATEGORY_DEFAULT	_DefaultTimeLocale

#endif /*_NB_LC_TIME_MISC_H_*/

File Added: src/lib/libc/locale/setlocale_local.h
/* $NetBSD: setlocale_local.h,v 1.1.2.2 2009/01/04 17:02:20 christos Exp $ */

/*-
 * Copyright (c)2008 Citrus Project,
 * 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.
 */

#ifndef _SETLOCALE_LOCAL_H_
#define _SETLOCALE_LOCAL_H_

#define _LOCALENAME_LEN_MAX 33

#define _C_LOCALE		"C"
#define _POSIX_LOCALE		"POSIX"

extern const char		*_PathLocale;
#define _LOCALE_ALIAS_NAME	"locale.alias"

typedef void *_locale_part_t;

struct _locale_cache_t {
	const unsigned char *ctype_tab;
	const short *tolower_tab;
	const short *toupper_tab;
	size_t mb_cur_max;
	struct lconv ldata;
	const char *items[ALT_DIGITS + 1];
};

struct _locale_impl_t {
	struct _locale_cache_t cache;
	char query[_LOCALENAME_LEN_MAX * (_LC_LAST - 1)];
	const char *part_name[_LC_LAST];
	_locale_part_t part_impl[_LC_LAST];
};

typedef const char *(*_locale_set_t)(const char * __restrict,
    struct _locale_impl_t * __restrict);

typedef struct {
	const char* name;
	int category;
	_locale_set_t setlocale;
} _locale_category_t;

__BEGIN_DECLS
_locale_category_t	*_find_category(int);
const char		*_get_locale_env(const char *);
struct _locale_impl_t	_global_locale;
struct _locale_impl_t	**_current_locale(void);
__END_DECLS

#endif /*_SETLOCALE_LOCAL_H_*/

cvs diff -r1.2 -r1.2.34.1 src/lib/libc/locale/Attic/aliasname.c (expand / switch to unified diff)

--- src/lib/libc/locale/Attic/aliasname.c 2005/02/09 21:35:46 1.2
+++ src/lib/libc/locale/Attic/aliasname.c 2009/01/04 17:02:19 1.2.34.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: aliasname.c,v 1.2 2005/02/09 21:35:46 kleink Exp $ */ 1/* $NetBSD: aliasname.c,v 1.2.34.1 2009/01/04 17:02:19 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2002 YAMAMOTO Takashi, 4 * Copyright (c)2002 YAMAMOTO Takashi,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -18,49 +18,49 @@ @@ -18,49 +18,49 @@
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31__RCSID("$NetBSD: aliasname.c,v 1.2 2005/02/09 21:35:46 kleink Exp $"); 31__RCSID("$NetBSD: aliasname.c,v 1.2.34.1 2009/01/04 17:02:19 christos Exp $");
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
34#include "namespace.h" 34#include "namespace.h"
35#include <assert.h> 35#include <assert.h>
36#include <stdio.h> 36#include <stdio.h>
37#include <string.h> 37#include <string.h>
38 38
39#include "aliasname_local.h" 39#include "aliasname_local.h"
40 40
41__inline int __is_ws(char); 41__inline int __is_ws(char);
42 42
43__inline int __is_ws(char ch) 43__inline int __is_ws(char ch)
44{ 44{
45 45
46 return (ch == ' ' || ch == '\t'); 46 return (ch == ' ' || ch == '\t');
47} 47}
48 48
49const char * 49const char *
50__unaliasname(const char *dbname, const char *alias, void *buf, size_t bufsize) 50__unaliasname(const char *dbname, const char *alias, void *buf, size_t bufsize)
51{ 51{
52 FILE *fp = NULL; 52 FILE *fp = NULL;
53 const char *result = alias; 53 const char *result = NULL;
54 size_t resultlen; 54 size_t resultlen;
55 size_t aliaslen; 55 size_t aliaslen;
56 const char *p; 56 const char *p;
57 size_t len; 57 size_t len;
58 58
59 _DIAGASSERT(dbname != NULL); 59 _DIAGASSERT(dbname != NULL);
60 _DIAGASSERT(alias != NULL); 60 _DIAGASSERT(alias != NULL);
61 _DIAGASSERT(buf != NULL); 61 _DIAGASSERT(buf != NULL);
62 62
63 fp = fopen(dbname, "r"); 63 fp = fopen(dbname, "r");
64 if (fp == NULL) 64 if (fp == NULL)
65 goto quit; 65 goto quit;
66 66

cvs diff -r1.1 -r1.1.44.1 src/lib/libc/locale/aliasname_local.h (expand / switch to unified diff)

--- src/lib/libc/locale/aliasname_local.h 2002/02/13 07:45:52 1.1
+++ src/lib/libc/locale/aliasname_local.h 2009/01/04 17:02:19 1.1.44.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: aliasname_local.h,v 1.1 2002/02/13 07:45:52 yamt Exp $ */ 1/* $NetBSD: aliasname_local.h,v 1.1.44.1 2009/01/04 17:02:19 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2002 YAMAMOTO Takashi, 4 * Copyright (c)2002 YAMAMOTO Takashi,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -16,14 +16,59 @@ @@ -16,14 +16,59 @@
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
 29/*-
 30 * Copyright (c)2008 Citrus Project,
 31 * All rights reserved.
 32 *
 33 * Redistribution and use in source and binary forms, with or without
 34 * modification, are permitted provided that the following conditions
 35 * are met:
 36 * 1. Redistributions of source code must retain the above copyright
 37 * notice, this list of conditions and the following disclaimer.
 38 * 2. Redistributions in binary form must reproduce the above copyright
 39 * notice, this list of conditions and the following disclaimer in the
 40 * documentation and/or other materials provided with the distribution.
 41 *
 42 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 45 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 52 * SUCH DAMAGE.
 53 */
 54
 55#ifndef _ALIASNAME_LOCAL_H_
 56#define _ALIASNAME_LOCAL_H_
 57
29const char *__unaliasname(const char *, const char *, void *, size_t); 58const char *__unaliasname(const char *, const char *, void *, size_t);
 59
 60static __inline int
 61__isforcemapping(const char *name)
 62{
 63 /* don't use strcasecmp, it owes locale. */
 64 return
 65 name[0] == '/' &&
 66 (name[1] == 'F' || name[1] == 'f') &&
 67 (name[2] == 'O' || name[2] == 'o') &&
 68 (name[3] == 'R' || name[3] == 'r') &&
 69 (name[4] == 'C' || name[4] == 'c') &&
 70 (name[5] == 'E' || name[5] == 'e') &&
 71 name[6] == '\0';
 72}
 73
 74#endif /*_ALIASNAME_LOCAL_H_*/

cvs diff -r1.7 -r1.7.28.1 src/lib/libc/locale/Attic/ctypeio.c (expand / switch to unified diff)

--- src/lib/libc/locale/Attic/ctypeio.c 2005/11/29 03:11:59 1.7
+++ src/lib/libc/locale/Attic/ctypeio.c 2009/01/04 17:02:19 1.7.28.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ctypeio.c,v 1.7 2005/11/29 03:11:59 christos Exp $ */ 1/* $NetBSD: ctypeio.c,v 1.7.28.1 2009/01/04 17:02:19 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1997 Christos Zoulas. All rights reserved. 4 * Copyright (c) 1997 Christos Zoulas. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software 14 * 3. All advertising materials mentioning features or use of this software
@@ -21,157 +21,106 @@ @@ -21,157 +21,106 @@
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#if defined(LIBC_SCCS) && !defined(lint) 33#if defined(LIBC_SCCS) && !defined(lint)
34__RCSID("$NetBSD: ctypeio.c,v 1.7 2005/11/29 03:11:59 christos Exp $"); 34__RCSID("$NetBSD: ctypeio.c,v 1.7.28.1 2009/01/04 17:02:19 christos Exp $");
35#endif /* LIBC_SCCS and not lint */ 35#endif /* LIBC_SCCS and not lint */
36 36
37#include <sys/types.h> 37#include <sys/types.h>
38 
39#include <assert.h> 38#include <assert.h>
 39#define _CTYPE_PRIVATE
 40#include <ctype.h>
 41#include <errno.h>
40#include <stdio.h> 42#include <stdio.h>
41#include <stdlib.h> 43#include <stdlib.h>
42#include <string.h> 44#include <string.h>
43#define _CTYPE_PRIVATE 45#include <unistd.h>
44#include <ctype.h> 46
 47#include "bsdctype.h"
45#include "ctypeio.h" 48#include "ctypeio.h"
46 49
47int 50int
48__loadctype(name) 51__loadctype(const char * __restrict path, _BSDCTypeLocale ** __restrict pdata)
49 const char *name; 
50{ 52{
51 FILE *fp; 53 FILE *fp;
52 char id[sizeof(_CTYPE_ID) - 1]; 54 char id[sizeof(_CTYPE_ID) - 1];
53 u_int32_t i, len; 55 uint32_t i, len;
54 unsigned char *new_ctype = NULL; 56 char *ptr;
55 short *new_toupper = NULL, *new_tolower = NULL; 57 uint8_t *new_ctype;
56 58 int16_t *new_tolower, *new_toupper;
57 _DIAGASSERT(name != NULL); 59 _BSDCTypeLocale *data;
58 60
59 if ((fp = fopen(name, "r")) == NULL) 61 _DIAGASSERT(path != NULL);
60 return 0; 62 _DIAGASSERT(pdata != NULL);
61 63
62 if (fread(id, sizeof(id), 1, fp) != 1) 64 fp = fopen(path, "r");
63 goto bad; 65 if (fp == NULL)
64 66 return ENOENT;
65 if (memcmp(id, _CTYPE_ID, sizeof(id)) != 0) 67
66 goto bad; 68 if (fread(id, sizeof(id), 1, fp) != 1 ||
67 69 memcmp(id, _CTYPE_ID, sizeof(id)) != 0)
68 if (fread(&i, sizeof(u_int32_t), 1, fp) != 1)  70 goto bad0;
69 goto bad; 71
70 72 if (fread(&i, sizeof(uint32_t), 1, fp) != 1 ||
71 if ((i = ntohl(i)) != _CTYPE_REV) 73 (i = ntohl(i)) != _CTYPE_REV)
72 goto bad; 74 goto bad0;
73 75
74 if (fread(&len, sizeof(u_int32_t), 1, fp) != 1) 76 if (fread(&len, sizeof(uint32_t), 1, fp) != 1 ||
75 goto bad; 77 (len = ntohl(len)) != _CTYPE_NUM_CHARS)
76 78 goto bad0;
77 if ((len = ntohl(len)) != _CTYPE_NUM_CHARS) 79
78 goto bad; 80 ptr = malloc(sizeof(*data) + ((sizeof(uint8_t) +
79 81 sizeof(int16_t) + sizeof(int16_t)) * (len + 1)));
80 if ((new_ctype = malloc(sizeof(u_int8_t) * (1 + len))) == NULL) 82 if (ptr == NULL)
81 goto bad; 83 return ENOMEM;
82 84
83 new_ctype[0] = 0; 85 data = (_BSDCTypeLocale *)(void *)ptr;
84 if (fread(&new_ctype[1], sizeof(u_int8_t), len, fp) != len) 86 ptr += sizeof(*data);
85 goto bad; 87
86 88 (new_ctype = (void *)ptr)[0] = (uint8_t)0;
87 if ((new_toupper = malloc(sizeof(int16_t) * (1 + len))) == NULL) 89 ptr += sizeof(uint8_t);
88 goto bad; 90 if (fread((void *)ptr, sizeof(uint8_t), len, fp) != len)
89 91 goto bad1;
90 new_toupper[0] = EOF; 92 ptr += sizeof(uint8_t) * len;
91 if (fread(&new_toupper[1], sizeof(int16_t), len, fp) != len) 93
92 goto bad; 94 (new_toupper = (void *)ptr)[0] = (int16_t)EOF;
93 95 ptr += sizeof(int16_t);
94 if ((new_tolower = malloc(sizeof(int16_t) * (1 + len))) == NULL) 96 if (fread((void *)ptr, sizeof(int16_t), len, fp) != len)
95 goto bad; 97 goto bad1;
96 98 ptr += sizeof(int16_t) * len;
97 new_tolower[0] = EOF; 99
98 if (fread(&new_tolower[1], sizeof(int16_t), len, fp) != len) 100 (new_tolower = (void *)ptr)[0] = (int16_t)EOF;
99 goto bad; 101 ptr += sizeof(int16_t);
 102 if (fread((void *)ptr, sizeof(int16_t), len, fp) != len)
 103 goto bad1;
100 104
101#if BYTE_ORDER == LITTLE_ENDIAN 105#if BYTE_ORDER == LITTLE_ENDIAN
102 for (i = 1; i <= len; i++) { 106 for (i = 1; i <= len; i++) {
103 new_toupper[i] = ntohs(new_toupper[i]); 107 new_toupper[i] = ntohs(new_toupper[i]);
104 new_tolower[i] = ntohs(new_tolower[i]); 108 new_tolower[i] = ntohs(new_tolower[i]);
105 } 109 }
106#endif 110#endif
107 111
108 (void) fclose(fp); 112 fclose(fp);
109 if (_ctype_ != _C_ctype_) 
110 free(__UNCONST(_ctype_)); 
111 _ctype_ = new_ctype; 
112 if (_toupper_tab_ != _C_toupper_) 
113 free(__UNCONST(_toupper_tab_)); 
114 _toupper_tab_ = new_toupper; 
115 if (_tolower_tab_ != _C_tolower_) 
116 free(__UNCONST(_tolower_tab_)); 
117 _tolower_tab_ = new_tolower; 
118 
119 return 1; 
120bad: 
121 free(new_tolower); 
122 free(new_toupper); 
123 free(new_ctype); 
124 (void) fclose(fp); 
125 return 0; 
126} 
127 113
128int 114 data->ctype_tab = (const unsigned char *)new_ctype;
129__savectype(name, new_ctype, new_toupper, new_tolower) 115 data->toupper_tab = (const short *)new_toupper;
130 const char *name; 116 data->tolower_tab = (const short *)new_tolower;
131 unsigned char *new_ctype; 
132 short *new_toupper, *new_tolower; 
133{ 
134 FILE *fp; 
135 u_int32_t i, len = _CTYPE_NUM_CHARS; 
136 117
137 _DIAGASSERT(name != NULL); 118 *pdata = data;
138 _DIAGASSERT(new_ctype != NULL); 
139 _DIAGASSERT(new_toupper != NULL); 
140 _DIAGASSERT(new_tolower != NULL); 
141 119
142 if ((fp = fopen(name, "w")) == NULL) 
143 return 0; 120 return 0;
144 121
145 if (fwrite(_CTYPE_ID, sizeof(_CTYPE_ID) - 1, 1, fp) != 1) 122bad1:
146 goto bad; 123 free(data);
147 124bad0:
148 i = htonl(_CTYPE_REV); 125 return EFTYPE;
149 if (fwrite(&i, sizeof(u_int32_t), 1, fp) != 1)  
150 goto bad; 
151 
152 i = htonl(len); 
153 if (fwrite(&i, sizeof(u_int32_t), 1, fp) != 1) 
154 goto bad; 
155 
156 if (fwrite(&new_ctype[1], sizeof(u_int8_t), len, fp) != len) 
157 goto bad; 
158 
159#if BYTE_ORDER == LITTLE_ENDIAN 
160 for (i = 1; i <= len; i++) { 
161 new_toupper[i] = htons(new_toupper[i]); 
162 new_tolower[i] = htons(new_tolower[i]); 
163 } 
164#endif 
165 if (fwrite(&new_toupper[1], sizeof(int16_t), len, fp) != len) 
166 goto bad; 
167 
168 if (fwrite(&new_tolower[1], sizeof(int16_t), len, fp) != len) 
169 goto bad; 
170 
171 
172 (void) fclose(fp); 
173 return 1; 
174bad: 
175 (void) fclose(fp); 
176 return 0; 
177} 126}

cvs diff -r1.1 -r1.1.56.1 src/lib/libc/locale/Attic/ctypeio.h (expand / switch to unified diff)

--- src/lib/libc/locale/Attic/ctypeio.h 1997/06/02 09:52:48 1.1
+++ src/lib/libc/locale/Attic/ctypeio.h 2009/01/04 17:02:19 1.1.56.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ctypeio.h,v 1.1 1997/06/02 09:52:48 kleink Exp $ */ 1/* $NetBSD: ctypeio.h,v 1.1.56.1 2009/01/04 17:02:19 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1997 Christos Zoulas. All rights reserved. 4 * Copyright (c) 1997 Christos Zoulas. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software 14 * 3. All advertising materials mentioning features or use of this software
@@ -20,16 +20,15 @@ @@ -20,16 +20,15 @@
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32__BEGIN_DECLS 32__BEGIN_DECLS
33int __loadctype __P((const char *)); 33int __loadctype(const char * __restrict, _BSDCTypeLocale ** __restrict pdata);
34int __savectype __P((const char *, unsigned char *, short *, short *)); 
35__END_DECLS 34__END_DECLS

File Deleted: src/lib/libc/locale/Attic/iswctype.c

cvs diff -r1.5 -r1.5.6.1 src/lib/libc/locale/Attic/iswctype_sb.c (expand / switch to unified diff)

--- src/lib/libc/locale/Attic/iswctype_sb.c 2008/08/12 20:51:25 1.5
+++ src/lib/libc/locale/Attic/iswctype_sb.c 2008/08/12 20:51:25 1.5.6.1
@@ -1,169 +0,0 @@ @@ -1,169 +0,0 @@
1/* $NetBSD: iswctype_sb.c,v 1.5 2008/08/12 20:51:25 tnozaki Exp $ */ 
2 
3/* 
4 * Copyright (c) 1989 The Regents of the University of California. 
5 * All rights reserved. 
6 * (c) UNIX System Laboratories, Inc. 
7 * All or some portions of this file are derived from material licensed 
8 * to the University of California by American Telephone and Telegraph 
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 
10 * the permission of UNIX System Laboratories, Inc. 
11 * 
12 * Redistribution and use in source and binary forms, with or without 
13 * modification, are permitted provided that the following conditions 
14 * are met: 
15 * 1. Redistributions of source code must retain the above copyright 
16 * notice, this list of conditions and the following disclaimer. 
17 * 2. Redistributions in binary form must reproduce the above copyright 
18 * notice, this list of conditions and the following disclaimer in the 
19 * documentation and/or other materials provided with the distribution. 
20 * 3. Neither the name of the University nor the names of its contributors 
21 * may be used to endorse or promote products derived from this software 
22 * without specific prior written permission. 
23 * 
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
34 * SUCH DAMAGE. 
35 */ 
36 
37#include <sys/cdefs.h> 
38#if defined(LIBC_SCCS) && !defined(lint) 
39__RCSID("$NetBSD: iswctype_sb.c,v 1.5 2008/08/12 20:51:25 tnozaki Exp $"); 
40#endif /* LIBC_SCCS and not lint */ 
41 
42#include <wchar.h> 
43#include <wctype.h> 
44#include <ctype.h> 
45 
46#undef iswalnum 
47int 
48iswalnum(c) 
49 wint_t c; 
50{ 
51 return isalnum((int)c); 
52} 
53 
54#undef iswalpha 
55int 
56iswalpha(c) 
57 wint_t c; 
58{ 
59 return isalpha((int)c); 
60} 
61 
62#undef iswblank 
63int 
64iswblank(c) 
65 wint_t c; 
66{ 
67 return isblank((int)c); 
68} 
69 
70#undef iswcntrl 
71int 
72iswcntrl(c) 
73 wint_t c; 
74{ 
75 return iscntrl((int)c); 
76} 
77 
78#undef iswdigit 
79int 
80iswdigit(c) 
81 wint_t c; 
82{ 
83 return isdigit((int)c); 
84} 
85 
86#undef iswgraph 
87int 
88iswgraph(c) 
89 wint_t c; 
90{ 
91 return isgraph((int)c); 
92} 
93 
94#undef iswlower 
95int 
96iswlower(c) 
97 wint_t c; 
98{ 
99 return islower((int)c); 
100} 
101 
102#undef iswprint 
103int 
104iswprint(c) 
105 wint_t c; 
106{ 
107 return isprint((int)c); 
108} 
109 
110#undef iswpunct 
111int 
112iswpunct(c) 
113 wint_t c; 
114{ 
115 return ispunct((int)c); 
116} 
117 
118#undef iswspace 
119int 
120iswspace(c) 
121 wint_t c; 
122{ 
123 return isspace((int)c); 
124} 
125 
126#undef iswupper 
127int 
128iswupper(c) 
129 wint_t c; 
130{ 
131 return isupper((int)c); 
132} 
133 
134#undef iswxdigit 
135int 
136iswxdigit(c) 
137 wint_t c; 
138{ 
139 return isxdigit((int)c); 
140} 
141 
142#undef towupper 
143wint_t 
144towupper(c) 
145 wint_t c; 
146{ 
147 return toupper((int)c); 
148} 
149 
150#undef towlower 
151wint_t 
152towlower(c) 
153 wint_t c; 
154{ 
155 return tolower((int)c); 
156} 
157 
158#undef wcwidth 
159int 
160/*ARGSUSED*/ 
161wcwidth(c) 
162 wchar_t c; 
163{ 
164 if (c == L'\0') 
165 return 0; 
166 if (isprint((int)c)) 
167 return 1; 
168 return -1; 
169} 

File Deleted: src/lib/libc/locale/Attic/lcmessages.c

File Deleted: src/lib/libc/locale/Attic/lcmessages.h

File Deleted: src/lib/libc/locale/Attic/lcmonetary.c

File Deleted: src/lib/libc/locale/Attic/lcmonetary.h

File Deleted: src/lib/libc/locale/Attic/lcnumeric.c

File Deleted: src/lib/libc/locale/Attic/lcnumeric.h

File Deleted: src/lib/libc/locale/Attic/lctime.c

File Deleted: src/lib/libc/locale/Attic/lctime.h

cvs diff -r1.14 -r1.14.20.1 src/lib/libc/locale/localeconv.c (expand / switch to unified diff)

--- src/lib/libc/locale/localeconv.c 2007/05/26 13:14:13 1.14
+++ src/lib/libc/locale/localeconv.c 2009/01/04 17:02:19 1.14.20.1
@@ -1,85 +1,48 @@ @@ -1,85 +1,48 @@
1/* $NetBSD: localeconv.c,v 1.14 2007/05/26 13:14:13 tnozaki Exp $ */ 1/* $NetBSD: localeconv.c,v 1.14.20.1 2009/01/04 17:02:19 christos Exp $ */
2 2
3/* 3/*-
4 * Written by J.T. Conklin <jtc@NetBSD.org>. 4 * Copyright (c)2008 Citrus Project,
5 * Public domain. 5 * All rights reserved.
 6 *
 7 * Redistribution and use in source and binary forms, with or without
 8 * modification, are permitted provided that the following conditions
 9 * are met:
 10 * 1. Redistributions of source code must retain the above copyright
 11 * notice, this list of conditions and the following disclaimer.
 12 * 2. Redistributions in binary form must reproduce the above copyright
 13 * notice, this list of conditions and the following disclaimer in the
 14 * documentation and/or other materials provided with the distribution.
 15 *
 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 26 * SUCH DAMAGE.
6 */ 27 */
7 28
8#include <sys/cdefs.h> 29#include <sys/cdefs.h>
9#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
10__RCSID("$NetBSD: localeconv.c,v 1.14 2007/05/26 13:14:13 tnozaki Exp $"); 31__RCSID("$NetBSD: localeconv.c,v 1.14.20.1 2009/01/04 17:02:19 christos Exp $");
11#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
12 33
13#include <sys/localedef.h> 34#include <sys/types.h>
 35#include <langinfo.h>
 36#define __SETLOCALE_SOURCE__
14#include <locale.h> 37#include <locale.h>
15 38
16/*  39#include "setlocale_local.h"
17 * The localeconv() function constructs a struct lconv from the current 
18 * monetary and numeric locales. 
19 * 
20 * Because localeconv() may be called many times (especially by library 
21 * routines like printf() & strtod()), the appropriate members of the  
22 * lconv structure are computed only when the monetary or numeric  
23 * locale has been changed. 
24 */ 
25int __mlocale_changed = 1; 
26int __nlocale_changed = 1; 
27 40
28/* 
29 * Return the current locale conversion. 
30 */ 
31struct lconv * 41struct lconv *
32localeconv() 42localeconv()
33{ 43{
34 static struct lconv ret; 44 struct _locale_impl_t *impl;
35 
36 if (__mlocale_changed) { 
37 /* LC_MONETARY */ 
38 ret.int_curr_symbol = 
39 __UNCONST(_CurrentMonetaryLocale->int_curr_symbol); 
40 ret.currency_symbol =  
41 __UNCONST(_CurrentMonetaryLocale->currency_symbol); 
42 ret.mon_decimal_point = 
43 __UNCONST(_CurrentMonetaryLocale->mon_decimal_point); 
44 ret.mon_thousands_sep = 
45 __UNCONST(_CurrentMonetaryLocale->mon_thousands_sep); 
46 ret.mon_grouping = 
47 __UNCONST(_CurrentMonetaryLocale->mon_grouping); 
48 ret.positive_sign = 
49 __UNCONST(_CurrentMonetaryLocale->positive_sign); 
50 ret.negative_sign = 
51 __UNCONST(_CurrentMonetaryLocale->negative_sign); 
52 ret.int_frac_digits = _CurrentMonetaryLocale->int_frac_digits; 
53 ret.frac_digits = _CurrentMonetaryLocale->frac_digits; 
54 ret.p_cs_precedes = _CurrentMonetaryLocale->p_cs_precedes; 
55 ret.p_sep_by_space = _CurrentMonetaryLocale->p_sep_by_space; 
56 ret.n_cs_precedes = _CurrentMonetaryLocale->n_cs_precedes; 
57 ret.n_sep_by_space = _CurrentMonetaryLocale->n_sep_by_space; 
58 ret.p_sign_posn = _CurrentMonetaryLocale->p_sign_posn; 
59 ret.n_sign_posn = _CurrentMonetaryLocale->n_sign_posn; 
60 ret.int_p_cs_precedes = 
61 _CurrentMonetaryLocale->int_p_cs_precedes; 
62 ret.int_n_cs_precedes = 
63 _CurrentMonetaryLocale->int_n_cs_precedes; 
64 ret.int_p_sep_by_space = 
65 _CurrentMonetaryLocale->int_p_sep_by_space; 
66 ret.int_n_sep_by_space = 
67 _CurrentMonetaryLocale->int_n_sep_by_space; 
68 ret.int_p_sign_posn = _CurrentMonetaryLocale->int_p_sign_posn; 
69 ret.int_n_sign_posn = _CurrentMonetaryLocale->int_n_sign_posn; 
70 __mlocale_changed = 0; 
71 } 
72 
73 if (__nlocale_changed) { 
74 /* LC_NUMERIC */ 
75 ret.decimal_point = 
76 __UNCONST(_CurrentNumericLocale->decimal_point); 
77 ret.thousands_sep = 
78 __UNCONST(_CurrentNumericLocale->thousands_sep); 
79 ret.grouping =  
80 __UNCONST(_CurrentNumericLocale->grouping); 
81 __nlocale_changed = 0; 
82 } 
83 45
84 return (&ret); 46 impl = *_current_locale();
 47 return &impl->cache.ldata;
85} 48}

cvs diff -r1.1 -r1.1.10.1 src/lib/libc/locale/Attic/localeio.c (expand / switch to unified diff)

--- src/lib/libc/locale/Attic/localeio.c 2008/05/17 03:49:54 1.1
+++ src/lib/libc/locale/Attic/localeio.c 2008/05/17 03:49:54 1.1.10.1
@@ -1,154 +0,0 @@ @@ -1,154 +0,0 @@
1/* $NetBSD: localeio.c,v 1.1 2008/05/17 03:49:54 ginsbach Exp $ */ 
2/* 
3 * Copyright (c) 2008, The NetBSD Foundation, Inc. 
4 * All rights reserved. 
5 *  
6 * This code is derived from software contributed to The NetBSD Foundation 
7 * by Brian Ginsbach. 
8 * 
9 * Redistribution and use in source and binary forms, with or without 
10 * modification, are permitted provided that the following conditions 
11 * are met: 
12 * 1. Redistributions of source code must retain the above copyright 
13 * notice, this list of conditions and the following disclaimer. 
14 * 2. Redistributions in binary form must reproduce the above copyright 
15 * notice, this list of conditions and the following disclaimer in the 
16 * documentation and/or other materials provided with the distribution. 
17 *  
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
28 * POSSIBILITY OF SUCH DAMAGE. 
29 */ 
30 
31#include <sys/cdefs.h> 
32#if defined(LIBC_SCCS) && !defined(lint) 
33__RCSID("$NetBSD: localeio.c,v 1.1 2008/05/17 03:49:54 ginsbach Exp $"); 
34#endif /* LIBC_SCCS and not lint */ 
35 
36#include "namespace.h" 
37 
38#include <sys/localedef.h> 
39#include <sys/types.h> 
40#include <sys/stat.h> 
41 
42#include <assert.h> 
43#include <fcntl.h> 
44#include <limits.h> 
45#include <locale.h> 
46#include <paths.h> 
47#include <stdlib.h> 
48#include <string.h> 
49#include <unistd.h> 
50 
51#include "localeio.h" 
52 
53int 
54__loadlocale(const char *name, size_t nstr, size_t nbytes, size_t localesize, 
55 void *currentlocale, const void *defaultlocale) 
56{ 
57 int fd, i; 
58 unsigned char **ap, *buf, *bp, *cp, *cbp, *ebp; 
59 unsigned char ***locale; 
60 struct stat st; 
61 size_t bufsize; 
62 
63 _DIAGASSERT(name != NULL); 
64 _DIAGASSERT(localesize != 0); 
65 _DIAGASSERT(currentlocale != NULL); 
66 _DIAGASSERT(defaultlocale != NULL); 
67 
68 if ((fd = open(name, O_RDONLY)) == -1) 
69 return 0; 
70 
71 if ((fstat(fd, &st) == -1) || (st.st_size <= 0)) 
72 goto error1; 
73 
74 bufsize = localesize + (size_t)st.st_size; 
75 if ((buf = malloc(bufsize)) == NULL) 
76 goto error1; 
77 
78 bp = buf + localesize; 
79 if (read(fd, bp, (size_t)st.st_size) != st.st_size) 
80 goto error2; 
81 
82 ap = (unsigned char **)(void *)buf; 
83 for (i = 0, ebp = buf + bufsize; i < nstr; i++) { 
84 ap[i] = bp; 
85 while (bp != ebp && *bp != '\n') 
86 bp++; 
87 if (bp == ebp) 
88 goto error2; 
89 *bp++ = '\0'; 
90 } 
91 
92 cp = buf + (sizeof(unsigned char *) * nstr); 
93 for (i = 0, cbp = bp; i < nbytes; i++) { 
94 int n; 
95 
96 while (bp != ebp && *bp != '\n') 
97 bp++; 
98 if (bp == ebp) 
99 goto error2; 
100 /* ignore overflow/underflow and bad characters */ 
101 n = (unsigned char)strtol((char *)cbp, NULL, 0); 
102 cp[i] = (unsigned char)(n & CHAR_MAX); 
103 cbp = bp; 
104 } 
105 
106 locale = currentlocale; 
107 if (*locale != defaultlocale) 
108 free(*locale); 
109 
110 *locale = (unsigned char **)(void *)buf; 
111 (void)close(fd); 
112 return 1; 
113 
114error2: 
115 free(buf); 
116error1: 
117 (void)close(fd); 
118 
119 return 0; 
120} 
121 
122/* 
123 * Convert a grouping sequence string into POSIX form. 
124 * 
125 * Examples: "3;3;-1" -> "\003\003\177\000" 
126 * "3" -> "\003\000" 
127 */ 
128 
129static const char nogrouping[] = { CHAR_MAX, '\0' }; 
130 
131const char * 
132__convertgrouping(const char *str) 
133{ 
134 char *src, *dst; 
135 
136 _DIAGASSERT(str != NULL); 
137 
138 src = dst = __UNCONST(str); 
139 
140 while (*src != '\0') { 
141 char *ep; 
142 int n; 
143 
144 if ((n = strtol(src, &ep, 0)) >= CHAR_MAX || 
145 ((*ep != ';') && (*ep != '\0'))) 
146 return nogrouping; /* invalid grouping string */ 
147 
148 *dst++ = n & CHAR_MAX; 
149 src = (*ep == ';')? ep + 1 : ep; 
150 } 
151 *dst = '\0'; 
152 
153 return (dst == str)? nogrouping : str; 
154} 

cvs diff -r1.1 -r1.1.10.1 src/lib/libc/locale/localeio.h (expand / switch to unified diff)

--- src/lib/libc/locale/localeio.h 2008/05/17 03:49:54 1.1
+++ src/lib/libc/locale/localeio.h 2008/05/17 03:49:54 1.1.10.1
@@ -1,34 +0,0 @@ @@ -1,34 +0,0 @@
1/* $NetBSD: localeio.h,v 1.1 2008/05/17 03:49:54 ginsbach Exp $ */ 
2/* 
3 * Copyright (c) 2008, The NetBSD Foundation, Inc. 
4 * All rights reserved. 
5 *  
6 * This code is derived from software contributed to The NetBSD Foundation 
7 * by Brian Ginsbach. 
8 * 
9 * Redistribution and use in source and binary forms, with or without 
10 * modification, are permitted provided that the following conditions 
11 * are met: 
12 * 1. Redistributions of source code must retain the above copyright 
13 * notice, this list of conditions and the following disclaimer. 
14 * 2. Redistributions in binary form must reproduce the above copyright 
15 * notice, this list of conditions and the following disclaimer in the 
16 * documentation and/or other materials provided with the distribution. 
17 *  
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
28 * POSSIBILITY OF SUCH DAMAGE. 
29 */ 
30 
31__BEGIN_DECLS 
32int __loadlocale(const char *, size_t, size_t, size_t, void *, const void *); 
33const char * __convertgrouping(const char *); 
34__END_DECLS 

cvs diff -r1.3 -r1.3.40.1 src/lib/libc/locale/multibyte.h (expand / switch to unified diff)

--- src/lib/libc/locale/multibyte.h 2003/04/29 14:53:12 1.3
+++ src/lib/libc/locale/multibyte.h 2009/01/04 17:02:20 1.3.40.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: multibyte.h,v 1.3 2003/04/29 14:53:12 scw Exp $ */ 1/* $NetBSD: multibyte.h,v 1.3.40.1 2009/01/04 17:02:20 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2002 Citrus Project, 4 * Copyright (c)2002 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -113,14 +113,14 @@ _init_ps(_RuneLocale *rl, mbstate_t *ps) @@ -113,14 +113,14 @@ _init_ps(_RuneLocale *rl, mbstate_t *ps)
113} 113}
114 114
115static __inline void 115static __inline void
116_fixup_ps(_RuneLocale *rl, mbstate_t *ps, int forceinit) 116_fixup_ps(_RuneLocale *rl, mbstate_t *ps, int forceinit)
117{ 117{
118 /* for future multi-locale facility */ 118 /* for future multi-locale facility */
119 _DIAGASSERT(rl != NULL); 119 _DIAGASSERT(rl != NULL);
120 120
121 if (ps != NULL && (_ps_to_runelocale(ps) == NULL || forceinit)) { 121 if (ps != NULL && (_ps_to_runelocale(ps) == NULL || forceinit)) {
122 _init_ps(rl, ps); 122 _init_ps(rl, ps);
123 } 123 }
124} 124}
125 125
126#endif 126#endif /*_MULTIBYTE_H_*/

cvs diff -r1.5 -r1.5.40.1 src/lib/libc/locale/multibyte_amd1.c (expand / switch to unified diff)

--- src/lib/libc/locale/multibyte_amd1.c 2003/03/05 20:18:16 1.5
+++ src/lib/libc/locale/multibyte_amd1.c 2009/01/04 17:02:20 1.5.40.1
@@ -1,171 +1,183 @@ @@ -1,171 +1,183 @@
1/* $NetBSD: multibyte_amd1.c,v 1.5 2003/03/05 20:18:16 tshiozak Exp $ */ 1/* $NetBSD: multibyte_amd1.c,v 1.5.40.1 2009/01/04 17:02:20 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2002 Citrus Project, 4 * Copyright (c)2002, 2008 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31__RCSID("$NetBSD: multibyte_amd1.c,v 1.5 2003/03/05 20:18:16 tshiozak Exp $"); 31__RCSID("$NetBSD: multibyte_amd1.c,v 1.5.40.1 2009/01/04 17:02:20 christos Exp $");
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
 34#include <sys/types.h>
34#include <assert.h> 35#include <assert.h>
35#include <wchar.h> 
36#include <errno.h> 36#include <errno.h>
37#include <sys/types.h> 37#include <langinfo.h>
38#include <citrus/citrus_module.h> 38#define __SETLOCALE_SOURCE__
39#include <citrus/citrus_ctype.h> 39#include <locale.h>
 40#include <wchar.h>
 41
 42#include "setlocale_local.h"
 43
 44#include "citrus_module.h"
 45#include "citrus_ctype.h"
40#include "rune.h" 46#include "rune.h"
41#include "multibyte.h" 47#include "multibyte.h"
42 48
 49#define _RUNE_LOCALE() \
 50 ((_RuneLocale *)(*_current_locale())->part_impl[(size_t)LC_CTYPE])
 51
 52#define _CITRUS_CTYPE() \
 53 (_RUNE_LOCALE()->rl_citrus_ctype)
 54
43size_t 55size_t
44mbrlen(const char *s, size_t n, mbstate_t *ps) 56mbrlen(const char *s, size_t n, mbstate_t *ps)
45{ 57{
46 size_t ret; 58 size_t ret;
47 int err0; 59 int err0;
48 60
49 _fixup_ps(_CurrentRuneLocale, ps, s==NULL); 61 _fixup_ps(_RUNE_LOCALE(), ps, s == NULL);
50 62
51 err0 = _citrus_ctype_mbrlen(_ps_to_ctype(ps), s, n, 63 err0 = _citrus_ctype_mbrlen(_ps_to_ctype(ps), s, n,
52 _ps_to_private(ps), &ret); 64 _ps_to_private(ps), &ret);
53 if (err0) 65 if (err0)
54 errno = err0; 66 errno = err0;
55 67
56 return ret; 68 return ret;
57} 69}
58 70
59int 71int
60mbsinit(const mbstate_t *ps) 72mbsinit(const mbstate_t *ps)
61{ 73{
62 int ret; 74 int ret;
63 int err0; 75 int err0;
64 _RuneLocale *rl; 76 _RuneLocale *rl;
65 77
66 if (ps == NULL) 78 if (ps == NULL)
67 return 1; 79 return 1;
68 80
69 if (_ps_to_runelocale(ps) == NULL) 81 if (_ps_to_runelocale(ps) == NULL)
70 rl = _CurrentRuneLocale; 82 rl = _RUNE_LOCALE();
71 else 83 else
72 rl = _ps_to_runelocale(ps); 84 rl = _ps_to_runelocale(ps);
73 85
74 /* mbsinit should cause no error... */ 86 /* mbsinit should cause no error... */
75 err0 = _citrus_ctype_mbsinit(rl->rl_citrus_ctype, 87 err0 = _citrus_ctype_mbsinit(rl->rl_citrus_ctype,
76 _ps_to_private_const(ps), &ret); 88 _ps_to_private_const(ps), &ret);
77 if (err0) 89 if (err0)
78 errno = err0; 90 errno = err0;
79 91
80 return ret; 92 return ret;
81} 93}
82 94
83size_t 95size_t
84mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) 96mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
85{ 97{
86 size_t ret; 98 size_t ret;
87 int err0; 99 int err0;
88 100
89 _fixup_ps(_CurrentRuneLocale, ps, s==NULL); 101 _fixup_ps(_RUNE_LOCALE(), ps, s == NULL);
90 102
91 err0 = _citrus_ctype_mbrtowc(_ps_to_ctype(ps), pwc, s, n, 103 err0 = _citrus_ctype_mbrtowc(_ps_to_ctype(ps), pwc, s, n,
92 _ps_to_private(ps), &ret); 104 _ps_to_private(ps), &ret);
93 if (err0) 105 if (err0)
94 errno = err0; 106 errno = err0;
95 107
96 return ret; 108 return ret;
97} 109}
98 110
99size_t 111size_t
100mbsrtowcs(wchar_t *pwcs, const char **s, size_t n, mbstate_t *ps) 112mbsrtowcs(wchar_t *pwcs, const char **s, size_t n, mbstate_t *ps)
101{ 113{
102 size_t ret; 114 size_t ret;
103 int err0; 115 int err0;
104 116
105 _fixup_ps(_CurrentRuneLocale, ps, s==NULL); 117 _fixup_ps(_RUNE_LOCALE(), ps, s == NULL);
106 118
107 err0 = _citrus_ctype_mbsrtowcs(_ps_to_ctype(ps), pwcs, s, n, 119 err0 = _citrus_ctype_mbsrtowcs(_ps_to_ctype(ps), pwcs, s, n,
108 _ps_to_private(ps), &ret); 120 _ps_to_private(ps), &ret);
109 if (err0) 121 if (err0)
110 errno = err0; 122 errno = err0;
111 123
112 return ret; 124 return ret;
113} 125}
114 126
115size_t 127size_t
116wcrtomb(char *s, wchar_t wc, mbstate_t *ps) 128wcrtomb(char *s, wchar_t wc, mbstate_t *ps)
117{ 129{
118 size_t ret; 130 size_t ret;
119 int err0; 131 int err0;
120 132
121 _fixup_ps(_CurrentRuneLocale, ps, s==NULL); 133 _fixup_ps(_RUNE_LOCALE(), ps, s == NULL);
122 134
123 err0 = _citrus_ctype_wcrtomb(_ps_to_ctype(ps), s, wc, 135 err0 = _citrus_ctype_wcrtomb(_ps_to_ctype(ps), s, wc,
124 _ps_to_private(ps), &ret); 136 _ps_to_private(ps), &ret);
125 if (err0) 137 if (err0)
126 errno = err0; 138 errno = err0;
127 139
128 return ret; 140 return ret;
129} 141}
130 142
131size_t 143size_t
132wcsrtombs(char *s, const wchar_t **ppwcs, size_t n, mbstate_t *ps) 144wcsrtombs(char *s, const wchar_t **ppwcs, size_t n, mbstate_t *ps)
133{ 145{
134 size_t ret; 146 size_t ret;
135 int err0; 147 int err0;
136 148
137 _fixup_ps(_CurrentRuneLocale, ps, s==NULL); 149 _fixup_ps(_RUNE_LOCALE(), ps, s == NULL);
138 150
139 err0 = _citrus_ctype_wcsrtombs(_ps_to_ctype(ps), s, ppwcs, n, 151 err0 = _citrus_ctype_wcsrtombs(_ps_to_ctype(ps), s, ppwcs, n,
140 _ps_to_private(ps), &ret); 152 _ps_to_private(ps), &ret);
141 if (err0) 153 if (err0)
142 errno = err0; 154 errno = err0;
143 155
144 return ret; 156 return ret;
145} 157}
146 158
147wint_t 159wint_t
148btowc(int c) 160btowc(int c)
149{ 161{
150 wint_t ret; 162 wint_t ret;
151 int err0; 163 int err0;
152 164
153 err0 = _citrus_ctype_btowc(_to_cur_ctype(), c, &ret); 165 err0 = _citrus_ctype_btowc(_CITRUS_CTYPE(), c, &ret);
154 if (err0) 166 if (err0)
155 errno = err0; 167 errno = err0;
156 168
157 return ret; 169 return ret;
158} 170}
159 171
160int 172int
161wctob(wint_t wc) 173wctob(wint_t wc)
162{ 174{
163 int ret; 175 int ret;
164 int err0; 176 int err0;
165 177
166 err0 = _citrus_ctype_wctob(_to_cur_ctype(), wc, &ret); 178 err0 = _citrus_ctype_wctob(_CITRUS_CTYPE(), wc, &ret);
167 if (err0) 179 if (err0)
168 errno = err0; 180 errno = err0;
169 181
170 return ret; 182 return ret;
171} 183}

cvs diff -r1.4 -r1.4.40.1 src/lib/libc/locale/multibyte_c90.c (expand / switch to unified diff)

--- src/lib/libc/locale/multibyte_c90.c 2003/03/05 20:18:16 1.4
+++ src/lib/libc/locale/multibyte_c90.c 2009/01/04 17:02:20 1.4.40.1
@@ -1,107 +1,118 @@ @@ -1,107 +1,118 @@
1/* $NetBSD: multibyte_c90.c,v 1.4 2003/03/05 20:18:16 tshiozak Exp $ */ 1/* $NetBSD: multibyte_c90.c,v 1.4.40.1 2009/01/04 17:02:20 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2002 Citrus Project, 4 * Copyright (c)2002, 2008 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31__RCSID("$NetBSD: multibyte_c90.c,v 1.4 2003/03/05 20:18:16 tshiozak Exp $"); 31__RCSID("$NetBSD: multibyte_c90.c,v 1.4.40.1 2009/01/04 17:02:20 christos Exp $");
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35#include <assert.h> 35#include <assert.h>
36#include <stdlib.h> 
37#include <errno.h> 36#include <errno.h>
 37#include <langinfo.h>
 38#define __SETLOCALE_SOURCE__
 39#include <locale.h>
 40#include <stdlib.h>
38#include <wchar.h> 41#include <wchar.h>
39#include <citrus/citrus_module.h> 42
40#include <citrus/citrus_ctype.h> 43#include "setlocale_local.h"
 44
 45#include "citrus_module.h"
 46#include "citrus_ctype.h"
41#include "rune.h" 47#include "rune.h"
42#include "multibyte.h" 48
 49#define _RUNE_LOCALE() \
 50 ((_RuneLocale *)(*_current_locale())->part_impl[(size_t)LC_CTYPE])
 51
 52#define _CITRUS_CTYPE() \
 53 (_RUNE_LOCALE()->rl_citrus_ctype)
43 54
44int 55int
45mblen(const char *s, size_t n) 56mblen(const char *s, size_t n)
46{ 57{
47 int ret; 58 int ret;
48 int err0; 59 int err0;
49 60
50 err0 = _citrus_ctype_mblen(_to_cur_ctype(), s, n, &ret); 61 err0 = _citrus_ctype_mblen(_CITRUS_CTYPE(), s, n, &ret);
51 if (err0) 62 if (err0)
52 errno = err0; 63 errno = err0;
53 64
54 return ret; 65 return ret;
55} 66}
56 67
57size_t 68size_t
58mbstowcs(wchar_t *pwcs, const char *s, size_t n) 69mbstowcs(wchar_t *pwcs, const char *s, size_t n)
59{ 70{
60 size_t ret; 71 size_t ret;
61 int err0; 72 int err0;
62 73
63 err0 = _citrus_ctype_mbstowcs(_to_cur_ctype(), pwcs, s, n, &ret); 74 err0 = _citrus_ctype_mbstowcs(_CITRUS_CTYPE(), pwcs, s, n, &ret);
64 if (err0) 75 if (err0)
65 errno = err0; 76 errno = err0;
66 77
67 return ret; 78 return ret;
68} 79}
69 80
70int 81int
71mbtowc(wchar_t *pw, const char *s, size_t n) 82mbtowc(wchar_t *pw, const char *s, size_t n)
72{ 83{
73 int ret; 84 int ret;
74 int err0; 85 int err0;
75 86
76 err0 = _citrus_ctype_mbtowc(_to_cur_ctype(), pw, s, n, &ret); 87 err0 = _citrus_ctype_mbtowc(_CITRUS_CTYPE(), pw, s, n, &ret);
77 if (err0) 88 if (err0)
78 errno = err0; 89 errno = err0;
79 90
80 return ret; 91 return ret;
81} 92}
82 93
83size_t 94size_t
84wcstombs(char *s, const wchar_t *wcs, size_t n) 95wcstombs(char *s, const wchar_t *wcs, size_t n)
85{ 96{
86 size_t ret; 97 size_t ret;
87 int err0; 98 int err0;
88 99
89 err0 = _citrus_ctype_wcstombs(_to_cur_ctype(), s, wcs, n, &ret); 100 err0 = _citrus_ctype_wcstombs(_CITRUS_CTYPE(), s, wcs, n, &ret);
90 if (err0) 101 if (err0)
91 errno = err0; 102 errno = err0;
92 103
93 return ret; 104 return ret;
94} 105}
95 106
96int 107int
97wctomb(char *s, wchar_t wc) 108wctomb(char *s, wchar_t wc)
98{ 109{
99 int ret; 110 int ret;
100 int err0; 111 int err0;
101 112
102 err0 = _citrus_ctype_wctomb(_to_cur_ctype(), s, wc, &ret); 113 err0 = _citrus_ctype_wctomb(_CITRUS_CTYPE(), s, wc, &ret);
103 if (err0) 114 if (err0)
104 errno = err0; 115 errno = err0;
105 116
106 return ret; 117 return ret;
107} 118}

cvs diff -r1.11 -r1.11.28.1 src/lib/libc/locale/nl_langinfo.c (expand / switch to unified diff)

--- src/lib/libc/locale/nl_langinfo.c 2005/11/29 03:11:59 1.11
+++ src/lib/libc/locale/nl_langinfo.c 2009/01/04 17:02:20 1.11.28.1
@@ -1,126 +1,56 @@ @@ -1,126 +1,56 @@
1/* $NetBSD: nl_langinfo.c,v 1.11 2005/11/29 03:11:59 christos Exp $ */ 1/* $NetBSD: nl_langinfo.c,v 1.11.28.1 2009/01/04 17:02:20 christos Exp $ */
2 2
3/* 3/*-
4 * Written by J.T. Conklin <jtc@NetBSD.org>. 4 * Copyright (c)2008 Citrus Project,
5 * Public domain. 5 * All rights reserved.
 6 *
 7 * Redistribution and use in source and binary forms, with or without
 8 * modification, are permitted provided that the following conditions
 9 * are met:
 10 * 1. Redistributions of source code must retain the above copyright
 11 * notice, this list of conditions and the following disclaimer.
 12 * 2. Redistributions in binary form must reproduce the above copyright
 13 * notice, this list of conditions and the following disclaimer in the
 14 * documentation and/or other materials provided with the distribution.
 15 *
 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 26 * SUCH DAMAGE.
6 */ 27 */
7 28
8#include <sys/cdefs.h> 29#include <sys/cdefs.h>
9#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
10__RCSID("$NetBSD: nl_langinfo.c,v 1.11 2005/11/29 03:11:59 christos Exp $"); 31__RCSID("$NetBSD: nl_langinfo.c,v 1.11.28.1 2009/01/04 17:02:20 christos Exp $");
11#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
12 33
13#include <sys/localedef.h> 34#include <sys/types.h>
14#include <locale.h> 
15#include <nl_types.h> 
16#include <langinfo.h> 35#include <langinfo.h>
17#include "rune.h" 36#define __SETLOCALE_SOURCE__
18#include "runetype.h" 37#include <locale.h>
 38#include <stdlib.h>
 39
 40#include "setlocale_local.h"
19 41
20char * 42char *
21nl_langinfo(item) 43nl_langinfo(nl_item item)
22 nl_item item; 
23{ 44{
24 const char *s; 45 const char *s;
 46 struct _locale_impl_t *impl;
25 47
26 switch (item) { 
27 case D_T_FMT: 
28 s = _CurrentTimeLocale->d_t_fmt; 
29 break;  
30 case D_FMT: 
31 s = _CurrentTimeLocale->d_fmt; 
32 break; 
33 case T_FMT: 
34 s = _CurrentTimeLocale->t_fmt; 
35 break; 
36 case T_FMT_AMPM: 
37 s = _CurrentTimeLocale->t_fmt_ampm; 
38 break; 
39 case AM_STR: 
40 case PM_STR: 
41 s = _CurrentTimeLocale->am_pm[(size_t)(item - AM_STR)]; 
42 break; 
43 case DAY_1: 
44 case DAY_2: 
45 case DAY_3: 
46 case DAY_4: 
47 case DAY_5: 
48 case DAY_6: 
49 case DAY_7: 
50 s = _CurrentTimeLocale->day[(size_t)(item - DAY_1)]; 
51 break; 
52 case ABDAY_1: 
53 case ABDAY_2: 
54 case ABDAY_3: 
55 case ABDAY_4: 
56 case ABDAY_5: 
57 case ABDAY_6: 
58 case ABDAY_7: 
59 s = _CurrentTimeLocale->abday[(size_t)(item - ABDAY_1)]; 
60 break; 
61 case MON_1: 
62 case MON_2: 
63 case MON_3: 
64 case MON_4: 
65 case MON_5: 
66 case MON_6: 
67 case MON_7: 
68 case MON_8: 
69 case MON_9: 
70 case MON_10: 
71 case MON_11: 
72 case MON_12: 
73 s = _CurrentTimeLocale->mon[(size_t)(item - MON_1)]; 
74 break; 
75 case ABMON_1: 
76 case ABMON_2: 
77 case ABMON_3: 
78 case ABMON_4: 
79 case ABMON_5: 
80 case ABMON_6: 
81 case ABMON_7: 
82 case ABMON_8: 
83 case ABMON_9: 
84 case ABMON_10: 
85 case ABMON_11: 
86 case ABMON_12: 
87 s = _CurrentTimeLocale->abmon[(size_t)(item - ABMON_1)]; 
88 break; 
89 case RADIXCHAR: 
90 s = _CurrentNumericLocale->decimal_point; 
91 break; 
92 case THOUSEP: 
93 s = _CurrentNumericLocale->thousands_sep; 
94 break; 
95 case YESSTR: 
96 s = _CurrentMessagesLocale->yesstr; 
97 break; 
98 case YESEXPR: 
99 s = _CurrentMessagesLocale->yesexpr; 
100 break; 
101 case NOSTR: 
102 s = _CurrentMessagesLocale->nostr; 
103 break; 
104 case NOEXPR: 
105 s = _CurrentMessagesLocale->noexpr; 
106 break; 
107 case CRNCYSTR: /* XXX */ 
108 s = ""; 
109 break; 
110 case CODESET: 
111#ifdef WITH_RUNE 
112 s = _CurrentRuneLocale->rl_codeset; 
113#else 
114 s = NULL; 48 s = NULL;
115#endif 49 if (item >= D_T_FMT && item <= ALT_DIGITS) {
116 if (!s) 50 impl = *_current_locale();
117 s = ""; 51 s = impl->cache.items[(size_t)item];
118 break; 
119 default: 
120 s = ""; 
121 break; 
122 } 52 }
123 53 if (s == NULL)
124 /* The return value should be really const, but the interface says OW */ 54 s = "";
125 return __UNCONST(s); 55 return __UNCONST(s);
126} 56}

cvs diff -r1.30 -r1.30.14.1 src/lib/libc/locale/rune.c (expand / switch to unified diff)

--- src/lib/libc/locale/rune.c 2007/09/29 07:55:45 1.30
+++ src/lib/libc/locale/rune.c 2009/01/04 17:02:20 1.30.14.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rune.c,v 1.30 2007/09/29 07:55:45 tnozaki Exp $ */ 1/* $NetBSD: rune.c,v 1.30.14.1 2009/01/04 17:02:20 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)1999 Citrus Project, 4 * Copyright (c)1999 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -53,41 +53,44 @@ @@ -53,41 +53,44 @@
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE. 58 * SUCH DAMAGE.
59 */ 59 */
60 60
61#include <sys/cdefs.h> 61#include <sys/cdefs.h>
62#if defined(LIBC_SCCS) && !defined(lint) 62#if defined(LIBC_SCCS) && !defined(lint)
63#if 0 63#if 0
64static char sccsid[] = "@(#)rune.c 8.1 (Berkeley) 6/4/93"; 64static char sccsid[] = "@(#)rune.c 8.1 (Berkeley) 6/4/93";
65#else 65#else
66__RCSID("$NetBSD: rune.c,v 1.30 2007/09/29 07:55:45 tnozaki Exp $"); 66__RCSID("$NetBSD: rune.c,v 1.30.14.1 2009/01/04 17:02:20 christos Exp $");
67#endif 67#endif
68#endif /* LIBC_SCCS and not lint */ 68#endif /* LIBC_SCCS and not lint */
69 69
70#include "namespace.h" 70#include "namespace.h"
71#include <assert.h> 71#include <assert.h>
72#include <stdio.h> 72#include <stdio.h>
73#include <string.h> 73#include <string.h>
74#include <stdlib.h> 74#include <stdlib.h>
75#include <errno.h> 75#include <errno.h>
76#include <wchar.h> 76#include <wchar.h>
77#include <sys/types.h> 77#include <sys/types.h>
78#include <sys/stat.h> 78#include <sys/stat.h>
79#include <citrus/citrus_module.h> 79
80#include <citrus/citrus_ctype.h> 80#include "citrus_module.h"
 81#include "citrus_ctype.h"
 82
 83#include "bsdctype.h"
81#include "rune.h" 84#include "rune.h"
82#include "rune_local.h" 85#include "rune_local.h"
83 86
84static int readrange __P((_RuneLocale *, _RuneRange *, _FileRuneRange *, void *, FILE *)); 87static int readrange __P((_RuneLocale *, _RuneRange *, _FileRuneRange *, void *, FILE *));
85static void _freeentry __P((_RuneRange *)); 88static void _freeentry __P((_RuneRange *));
86static void _wctype_init __P((_RuneLocale *rl)); 89static void _wctype_init __P((_RuneLocale *rl));
87 90
88static int 91static int
89readrange(_RuneLocale *rl, _RuneRange *rr, _FileRuneRange *frr, void *lastp, 92readrange(_RuneLocale *rl, _RuneRange *rr, _FileRuneRange *frr, void *lastp,
90 FILE *fp) 93 FILE *fp)
91{ 94{
92 uint32_t i; 95 uint32_t i;
93 _RuneEntry *re; 96 _RuneEntry *re;

cvs diff -r1.12 -r1.12.14.1 src/lib/libc/locale/Attic/rune.h (expand / switch to unified diff)

--- src/lib/libc/locale/Attic/rune.h 2007/09/03 20:31:56 1.12
+++ src/lib/libc/locale/Attic/rune.h 2009/01/04 17:02:20 1.12.14.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rune.h,v 1.12 2007/09/03 20:31:56 drochner Exp $ */ 1/* $NetBSD: rune.h,v 1.12.14.1 2009/01/04 17:02:20 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1993 4 * Copyright (c) 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Paul Borman at Krystal Technologies. 8 * Paul Borman at Krystal Technologies.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -79,20 +79,17 @@ @@ -79,20 +79,17 @@
79#define _RuneEntry _NBRuneEntry 79#define _RuneEntry _NBRuneEntry
80#define _RuneRange _NBRuneRange 80#define _RuneRange _NBRuneRange
81#define _RuneLocale _NBRuneLocale 81#define _RuneLocale _NBRuneLocale
82#define _RUNE_MAGIC_1 _NB_RUNE_MAGIC_1 82#define _RUNE_MAGIC_1 _NB_RUNE_MAGIC_1
83#define _RUNE_MODULE_1 _NB_RUNE_MODULE_1 83#define _RUNE_MODULE_1 _NB_RUNE_MODULE_1
84#define _RUNE_CODESET _NB_RUNE_CODESET 84#define _RUNE_CODESET _NB_RUNE_CODESET
85 85
86/* 86/*
87 * global variables 87 * global variables
88 */ 88 */
89extern size_t __mb_len_max_runtime; 89extern size_t __mb_len_max_runtime;
90#define __MB_LEN_MAX_RUNTIME __mb_len_max_runtime 90#define __MB_LEN_MAX_RUNTIME __mb_len_max_runtime
91 91
92extern _RuneLocale _DefaultRuneLocale; 92extern const _RuneLocale _DefaultRuneLocale;
93extern _RuneLocale *_CurrentRuneLocale; 93extern const _RuneLocale *_CurrentRuneLocale;
94extern const char *_PathLocale; 
95 
96#define _LOCALE_ALIAS_NAME "locale.alias" 
97 94
98#endif /*! _RUNE_H_ */ 95#endif /*! _RUNE_H_ */

cvs diff -r1.10 -r1.10.10.1 src/lib/libc/locale/Attic/rune_local.h (expand / switch to unified diff)

--- src/lib/libc/locale/Attic/rune_local.h 2008/04/01 19:19:33 1.10
+++ src/lib/libc/locale/Attic/rune_local.h 2008/04/01 19:19:33 1.10.10.1
@@ -1,48 +0,0 @@ @@ -1,48 +0,0 @@
1/* $NetBSD: rune_local.h,v 1.10 2008/04/01 19:19:33 drochner Exp $ */ 
2 
3/*- 
4 * Copyright (c) 2000 Citrus Project, 
5 * All rights reserved. 
6 * 
7 * Redistribution and use in source and binary forms, with or without 
8 * modification, are permitted provided that the following conditions 
9 * are met: 
10 * 1. Redistributions of source code must retain the above copyright 
11 * notice, this list of conditions and the following disclaimer. 
12 * 2. Redistributions in binary form must reproduce the above copyright 
13 * notice, this list of conditions and the following disclaimer in the 
14 * documentation and/or other materials provided with the distribution. 
15 * 
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
26 * SUCH DAMAGE. 
27 */ 
28 
29#ifndef _RUNE_LOCAL_H_ 
30#define _RUNE_LOCAL_H_ 
31 
32/* rune.c */ 
33extern _RuneLocale *_Read_RuneMagi __P((FILE *fp)); 
34extern _RuneLocale *_Read_CTypeAsRune __P((FILE *fp)); 
35extern void _NukeRune __P((_RuneLocale *)); 
36 
37/* setrunelocale.c */ 
38extern int _xpg4_setrunelocale __P((const char *)); 
39extern _RuneLocale *_findrunelocale __P((char *)); 
40extern int _newrunelocale __P((char *)); 
41 
42/* runeglue.c */ 
43extern int __runetable_to_netbsd_ctype __P((_RuneLocale *)); 
44 
45/* ___runetype_mb.c */ 
46extern _RuneType ___runetype_mb __P((wint_t)); 
47 
48#endif 

cvs diff -r1.13 -r1.13.2.1 src/lib/libc/locale/Attic/runeglue.c (expand / switch to unified diff)

--- src/lib/libc/locale/Attic/runeglue.c 2008/11/06 19:59:42 1.13
+++ src/lib/libc/locale/Attic/runeglue.c 2008/11/06 19:59:42 1.13.2.1
@@ -1,152 +0,0 @@ @@ -1,152 +0,0 @@
1/* $NetBSD: runeglue.c,v 1.13 2008/11/06 19:59:42 christos Exp $ */ 
2 
3/*- 
4 * Copyright (c)1999 Citrus Project, 
5 * All rights reserved. 
6 * 
7 * Redistribution and use in source and binary forms, with or without 
8 * modification, are permitted provided that the following conditions 
9 * are met: 
10 * 1. Redistributions of source code must retain the above copyright 
11 * notice, this list of conditions and the following disclaimer. 
12 * 2. Redistributions in binary form must reproduce the above copyright 
13 * notice, this list of conditions and the following disclaimer in the 
14 * documentation and/or other materials provided with the distribution. 
15 * 
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
26 * SUCH DAMAGE. 
27 * 
28 * Id: runeglue.c,v 1.7 2000/12/22 22:52:29 itojun Exp 
29 */ 
30 
31/* 
32 * Glue code to hide "rune" facility from user programs. 
33 * This is important to keep backward/future compatibility. 
34 */ 
35 
36#include <sys/cdefs.h> 
37#if defined(LIBC_SCCS) && !defined(lint) 
38__RCSID("$NetBSD: runeglue.c,v 1.13 2008/11/06 19:59:42 christos Exp $"); 
39#endif /* LIBC_SCCS and not lint */ 
40 
41#define _CTYPE_PRIVATE 
42#include <assert.h> 
43#include <limits.h> 
44#include <stdio.h> 
45#include <sys/types.h> 
46#include <ctype.h> 
47#include <stdlib.h> 
48#include <string.h> 
49#include <wchar.h> 
50#include "citrus/citrus_module.h" 
51#include "citrus/citrus_ctype.h" 
52#include "rune.h" 
53#include "rune_local.h" 
54 
55#if EOF != -1 
56#error "EOF != -1" 
57#endif 
58#if _CACHED_RUNES != 256 
59#error "_CACHED_RUNES != 256" 
60#endif 
61 
62int 
63__runetable_to_netbsd_ctype(rl) 
64 _RuneLocale *rl; 
65{ 
66 int i, ch; 
67 unsigned char *new_ctype; 
68 short *new_toupper, *new_tolower; 
69 
70 _DIAGASSERT(rl != NULL); 
71 
72 new_ctype = malloc(sizeof(*new_ctype) * (1 + _CTYPE_NUM_CHARS)); 
73 if (!new_ctype) 
74 return -1; 
75 new_toupper = malloc(sizeof(*new_toupper) * (1 + 256)); 
76 if (!new_toupper) { 
77 free(new_ctype); 
78 return -1; 
79 } 
80 new_tolower = malloc(sizeof(*new_tolower) * (1 + 256)); 
81 if (!new_tolower) { 
82 free(new_ctype); 
83 free(new_toupper); 
84 return -1; 
85 } 
86 
87 memset(new_ctype, 0, sizeof(*new_ctype) * (1 + _CTYPE_NUM_CHARS)); 
88 memset(new_toupper, 0, sizeof(*new_toupper) * (1 + 256)); 
89 memset(new_tolower, 0, sizeof(*new_tolower) * (1 + 256)); 
90 
91 new_ctype[0] = 0; 
92 new_toupper[0] = EOF; 
93 new_tolower[0] = EOF; 
94 for (i = 0; i < _CTYPE_NUM_CHARS; i++) { 
95 new_ctype[i + 1] = 0; 
96 new_toupper[i + 1] = i; 
97 new_tolower[i + 1] = i; 
98 
99 /* XXX: FIXME 
100 * expected 'x' == L'x', see defect report #279 
101 * http://www.open-std.org/JTC1/SC22/WG14/www/docs/dr_279.htm 
102 */ 
103 if (_citrus_ctype_wctob(rl->rl_citrus_ctype, (wint_t)i, &ch)) { 
104 free(new_ctype); 
105 free(new_toupper); 
106 free(new_tolower); 
107 return -1; 
108 } 
109 if (ch == EOF) 
110 continue; 
111 
112 if (rl->rl_runetype[i] & _CTYPE_U) 
113 new_ctype[i + 1] |= _U; 
114 if (rl->rl_runetype[i] & _CTYPE_L) 
115 new_ctype[i + 1] |= _L; 
116 if (rl->rl_runetype[i] & _CTYPE_D) 
117 new_ctype[i + 1] |= _N; 
118 if (rl->rl_runetype[i] & _CTYPE_S) 
119 new_ctype[i + 1] |= _S; 
120 if (rl->rl_runetype[i] & _CTYPE_P) 
121 new_ctype[i + 1] |= _P; 
122 if (rl->rl_runetype[i] & _CTYPE_C) 
123 new_ctype[i + 1] |= _C; 
124 if (rl->rl_runetype[i] & _CTYPE_X) 
125 new_ctype[i + 1] |= _X; 
126 /* 
127 * TWEAK! _B has been used incorrectly (or with older 
128 * declaration) in ctype.h isprint() macro. 
129 * _B does not mean isblank, it means "isprint && !isgraph". 
130 * the following is okay since isblank() was hardcoded in 
131 * function (i.e. isblank() is inherently locale unfriendly). 
132 */ 
133#if 1 
134 if ((rl->rl_runetype[i] & (_CTYPE_R | _CTYPE_G)) == _CTYPE_R) 
135 new_ctype[i + 1] |= _B; 
136#else 
137 if (rl->rl_runetype[i] & _CTYPE_B) 
138 new_ctype[i + 1] |= _B; 
139#endif 
140 new_toupper[i + 1] = (short)rl->rl_mapupper[i]; 
141 new_tolower[i + 1] = (short)rl->rl_maplower[i]; 
142 } 
143 
144 /* LINTED const cast */ 
145 rl->rl_ctype_tab = (const unsigned char *)new_ctype; 
146 /* LINTED const cast */ 
147 rl->rl_toupper_tab = (const short *)new_toupper; 
148 /* LINTED const cast */ 
149 rl->rl_tolower_tab = (const short *)new_tolower; 
150 
151 return 0; 
152} 

cvs diff -r1.17 -r1.17.6.1 src/lib/libc/locale/runetable.c (expand / switch to unified diff)

--- src/lib/libc/locale/runetable.c 2008/08/12 21:25:31 1.17
+++ src/lib/libc/locale/runetable.c 2008/08/12 21:25:31 1.17.6.1
@@ -1,354 +0,0 @@ @@ -1,354 +0,0 @@
1/* $NetBSD: runetable.c,v 1.17 2008/08/12 21:25:31 tnozaki Exp $ */ 
2 
3/*- 
4 * Copyright (c) 1993 
5 * The Regents of the University of California. All rights reserved. 
6 * 
7 * This code is derived from software contributed to Berkeley by 
8 * Paul Borman at Krystal Technologies. 
9 * 
10 * Redistribution and use in source and binary forms, with or without 
11 * modification, are permitted provided that the following conditions 
12 * are met: 
13 * 1. Redistributions of source code must retain the above copyright 
14 * notice, this list of conditions and the following disclaimer. 
15 * 2. Redistributions in binary form must reproduce the above copyright 
16 * notice, this list of conditions and the following disclaimer in the 
17 * documentation and/or other materials provided with the distribution. 
18 * 3. Neither the name of the University nor the names of its contributors 
19 * may be used to endorse or promote products derived from this software 
20 * without specific prior written permission. 
21 * 
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
32 * SUCH DAMAGE. 
33 * 
34 * $FreeBSD: src/lib/libc/locale/table.c,v 1.13 2000/02/08 07:43:25 obrien Exp $ 
35 */ 
36 
37#include <sys/cdefs.h> 
38#if defined(LIBC_SCCS) && !defined(lint) 
39#if 0 
40static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 6/27/93"; 
41#else 
42__RCSID("$NetBSD: runetable.c,v 1.17 2008/08/12 21:25:31 tnozaki Exp $"); 
43#endif 
44#endif /* LIBC_SCCS and not lint */ 
45 
46#include <stdlib.h> 
47#define _CTYPE_PRIVATE 
48#include <ctype.h> 
49#include <locale.h> 
50#include <assert.h> 
51#include <wchar.h> 
52#include <citrus/citrus_module.h> 
53#include <citrus/citrus_ctype.h> 
54#include "rune.h" 
55#include "rune_local.h" 
56 
57_RuneLocale _DefaultRuneLocale = { 
58 _RUNE_MAGIC_1, 
59 "NONE", 
60 _DEFAULT_INVALID_RUNE, 
61 
62 { /*00*/ _CTYPE_C, 
63 _CTYPE_C, 
64 _CTYPE_C, 
65 _CTYPE_C, 
66 _CTYPE_C, 
67 _CTYPE_C, 
68 _CTYPE_C, 
69 _CTYPE_C, 
70 /*08*/ _CTYPE_C, 
71 _CTYPE_C|_CTYPE_S|_CTYPE_B, 
72 _CTYPE_C|_CTYPE_S, 
73 _CTYPE_C|_CTYPE_S, 
74 _CTYPE_C|_CTYPE_S, 
75 _CTYPE_C|_CTYPE_S, 
76 _CTYPE_C, 
77 _CTYPE_C, 
78 /*10*/ _CTYPE_C, 
79 _CTYPE_C, 
80 _CTYPE_C, 
81 _CTYPE_C, 
82 _CTYPE_C, 
83 _CTYPE_C, 
84 _CTYPE_C, 
85 _CTYPE_C, 
86 /*18*/ _CTYPE_C, 
87 _CTYPE_C, 
88 _CTYPE_C, 
89 _CTYPE_C, 
90 _CTYPE_C, 
91 _CTYPE_C, 
92 _CTYPE_C, 
93 _CTYPE_C, 
94 /*20*/ _CTYPE_S|_CTYPE_B|_CTYPE_R|_CTYPE_SW1, 
95 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
96 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
97 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
98 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
99 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
100 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
101 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
102 /*28*/ _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
103 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
104 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
105 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
106 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
107 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
108 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
109 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
110 /*30*/ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_SW1|0, 
111 _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_SW1|1, 
112 _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_SW1|2, 
113 _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_SW1|3, 
114 _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_SW1|4, 
115 _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_SW1|5, 
116 _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_SW1|6, 
117 _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_SW1|7, 
118 /*38*/ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_SW1|8, 
119 _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_SW1|9, 
120 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
121 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
122 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
123 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
124 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
125 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
126 /*40*/ _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
127 _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1|10, 
128 _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1|11, 
129 _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1|12, 
130 _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1|13, 
131 _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1|14, 
132 _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1|15, 
133 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
134 /*48*/ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
135 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
136 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
137 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
138 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
139 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
140 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
141 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
142 /*50*/ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
143 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
144 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
145 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
146 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
147 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
148 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
149 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
150 /*58*/ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
151 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
152 _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
153 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
154 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
155 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
156 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
157 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
158 /*60*/ _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
159 _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1|10, 
160 _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1|11, 
161 _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1|12, 
162 _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1|13, 
163 _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1|14, 
164 _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1|15, 
165 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
166 /*68*/ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
167 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
168 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
169 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
170 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
171 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
172 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
173 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
174 /*70*/ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
175 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
176 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
177 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
178 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
179 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
180 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
181 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
182 /*78*/ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
183 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
184 _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A|_CTYPE_SW1, 
185 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
186 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
187 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
188 _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, 
189 _CTYPE_C, 
190#ifdef ALL_80_TO_FF_SW1 
191 /*80*/ _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
192 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
193 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
194 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
195 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
196 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
197 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
198 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
199 /*90*/ _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
200 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
201 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
202 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
203 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
204 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
205 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
206 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
207 /*A0*/ _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
208 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
209 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
210 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
211 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
212 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
213 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
214 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
215 /*B0*/ _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
216 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
217 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
218 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
219 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
220 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
221 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
222 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
223 /*C0*/ _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
224 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
225 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
226 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
227 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
228 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
229 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
230 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
231 /*D0*/ _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
232 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
233 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
234 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
235 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
236 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
237 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
238 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
239 /*E0*/ _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
240 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
241 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
242 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
243 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
244 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
245 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
246 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
247 /*F0*/ _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
248 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
249 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
250 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
251 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
252 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
253 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
254 _CTYPE_R|_CTYPE_SW1, _CTYPE_R|_CTYPE_SW1, 
255#endif 
256 }, 
257 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
258 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
259 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 
260 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 
261 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 
262 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 
263 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 
264 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 
265 0x40, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 
266 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 
267 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 
268 'x', 'y', 'z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 
269 0x60, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 
270 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 
271 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 
272 'x', 'y', 'z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 
273 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 
274 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 
275 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 
276 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 
277 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 
278 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 
279 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 
280 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 
281 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 
282 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 
283 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 
284 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 
285 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 
286 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 
287 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 
288 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 
289 }, 
290 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
291 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
292 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 
293 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 
294 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 
295 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 
296 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 
297 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 
298 0x40, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 
299 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 
300 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 
301 'X', 'Y', 'Z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 
302 0x60, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 
303 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 
304 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 
305 'X', 'Y', 'Z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 
306 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 
307 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 
308 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 
309 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 
310 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 
311 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 
312 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 
313 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 
314 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 
315 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 
316 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 
317 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 
318 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 
319 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 
320 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 
321 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 
322 }, 
323 { 0, NULL }, 
324 { 0, NULL }, 
325 { 0, NULL }, 
326 NULL, 0, 
327 "646", 
328 &_citrus_ctype_default, 
329 { 
330 { NULL, NULL, NULL }, 
331 { NULL, NULL, NULL }, 
332 }, 
333 { 
334 { "alnum", _CTYPE_A|_CTYPE_D }, 
335 { "alpha", _CTYPE_A }, 
336 { "blank", _CTYPE_B }, 
337 { "cntrl", _CTYPE_C }, 
338 { "digit", _CTYPE_D }, 
339 { "graph", _CTYPE_G }, 
340 { "lower", _CTYPE_L }, 
341 { "print", _CTYPE_R }, 
342 { "punct", _CTYPE_P }, 
343 { "space", _CTYPE_S }, 
344 { "upper", _CTYPE_U }, 
345 { "xdigit", _CTYPE_X }, 
346 }, 
347 _C_ctype_, 
348 _C_tolower_, 
349 _C_toupper_ 
350}; 
351 
352_RuneLocale *_CurrentRuneLocale = &_DefaultRuneLocale; 
353 
354const char *_PathLocale; 

cvs diff -r1.54 -r1.54.6.1 src/lib/libc/locale/setlocale.c (expand / switch to unified diff)

--- src/lib/libc/locale/setlocale.c 2008/06/12 20:33:23 1.54
+++ src/lib/libc/locale/setlocale.c 2008/06/12 20:33:23 1.54.6.1
@@ -1,460 +0,0 @@ @@ -1,460 +0,0 @@
1/* $NetBSD: setlocale.c,v 1.54 2008/06/12 20:33:23 ginsbach Exp $ */ 
2 
3/* 
4 * Copyright (c) 1991, 1993, 2008 
5 * The Regents of the University of California. All rights reserved. 
6 * 
7 * This code is derived from software contributed to Berkeley by 
8 * Paul Borman at Krystal Technologies. 
9 * 
10 * Redistribution and use in source and binary forms, with or without 
11 * modification, are permitted provided that the following conditions 
12 * are met: 
13 * 1. Redistributions of source code must retain the above copyright 
14 * notice, this list of conditions and the following disclaimer. 
15 * 2. Redistributions in binary form must reproduce the above copyright 
16 * notice, this list of conditions and the following disclaimer in the 
17 * documentation and/or other materials provided with the distribution. 
18 * 3. Neither the name of the University nor the names of its contributors 
19 * may be used to endorse or promote products derived from this software 
20 * without specific prior written permission. 
21 * 
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
32 * SUCH DAMAGE. 
33 */ 
34 
35#include <sys/cdefs.h> 
36#if defined(LIBC_SCCS) && !defined(lint) 
37#if 0 
38static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93"; 
39#else 
40__RCSID("$NetBSD: setlocale.c,v 1.54 2008/06/12 20:33:23 ginsbach Exp $"); 
41#endif 
42#endif /* LIBC_SCCS and not lint */ 
43 
44#define _CTYPE_PRIVATE 
45 
46#include "namespace.h" 
47#include <sys/localedef.h> 
48#include <sys/types.h> 
49#include <sys/stat.h> 
50#include <assert.h> 
51#include <limits.h> 
52#include <ctype.h> 
53#define __SETLOCALE_SOURCE__ 
54#include <locale.h> 
55#include <paths.h> 
56#include <stdio.h> 
57#include <stdlib.h> 
58#include <string.h> 
59#include <unistd.h> 
60#ifdef WITH_RUNE 
61#include "rune.h" 
62#include "rune_local.h" 
63#else 
64#include "ctypeio.h" 
65#endif 
66#include "lcmessages.h" 
67#include "lcmonetary.h" 
68#include "lcnumeric.h" 
69#include "lctime.h" 
70 
71#ifdef CITRUS 
72#include <citrus/citrus_namespace.h> 
73#include <citrus/citrus_region.h> 
74#include <citrus/citrus_lookup.h> 
75#include <citrus/citrus_bcs.h> 
76#else 
77#include <locale/aliasname_local.h> 
78#define _lookup_alias(p, a, b, s, c) __unaliasname((p), (a), (b), (s)) 
79#define _bcs_strcasecmp(a, b) strcasecmp((a), (b)) 
80#endif 
81 
82#define _LOCALE_SYM_FORCE "/force" 
83 
84/* 
85 * Category names for getenv() 
86 */ 
87static const char *const categories[_LC_LAST] = { 
88 "LC_ALL", 
89 "LC_COLLATE", 
90 "LC_CTYPE", 
91 "LC_MONETARY", 
92 "LC_NUMERIC", 
93 "LC_TIME", 
94 "LC_MESSAGES" 
95}; 
96 
97/* 
98 * Current locales for each category 
99 */ 
100static char current_categories[_LC_LAST][32] = { 
101 "C", 
102 "C", 
103 "C", 
104 "C", 
105 "C", 
106 "C", 
107 "C" 
108}; 
109 
110/* 
111 * The locales we are going to try and load 
112 */ 
113static char new_categories[_LC_LAST][32]; 
114 
115static char current_locale_string[_LC_LAST * 33]; 
116 
117static char *currentlocale __P((void)); 
118static void revert_to_default __P((int)); 
119static int force_locale_enable __P((int)); 
120static int load_locale_sub __P((int, const char *, int)); 
121static char *loadlocale __P((int)); 
122static const char *__get_locale_env __P((int)); 
123 
124char * 
125__setlocale(category, locale) 
126 int category; 
127 const char *locale; 
128{ 
129 int i, loadlocale_success; 
130 size_t len; 
131 const char *env, *r; 
132 
133 if (issetugid() || 
134 ((!_PathLocale && !(_PathLocale = getenv("PATH_LOCALE"))) || 
135 !*_PathLocale)) 
136 _PathLocale = _PATH_LOCALE; 
137 
138 if (category < 0 || category >= _LC_LAST) 
139 return (NULL); 
140 
141 if (!locale) 
142 return (category ? 
143 current_categories[category] : currentlocale()); 
144 
145 /* 
146 * Default to the current locale for everything. 
147 */ 
148 for (i = 1; i < _LC_LAST; ++i) 
149 (void)strlcpy(new_categories[i], current_categories[i], 
150 sizeof(new_categories[i])); 
151 
152 /* 
153 * Now go fill up new_categories from the locale argument 
154 */ 
155 if (!*locale) { 
156 if (category == LC_ALL) { 
157 for (i = 1; i < _LC_LAST; ++i) { 
158 env = __get_locale_env(i); 
159 (void)strlcpy(new_categories[i], env, 
160 sizeof(new_categories[i])); 
161 } 
162 } 
163 else { 
164 env = __get_locale_env(category); 
165 (void)strlcpy(new_categories[category], env, 
166 sizeof(new_categories[category])); 
167 } 
168 } else if (category) { 
169 (void)strlcpy(new_categories[category], locale, 
170 sizeof(new_categories[category])); 
171 } else { 
172 if ((r = strchr(locale, '/')) == 0) { 
173 for (i = 1; i < _LC_LAST; ++i) { 
174 (void)strlcpy(new_categories[i], locale, 
175 sizeof(new_categories[i])); 
176 } 
177 } else { 
178 for (i = 1;;) { 
179 _DIAGASSERT(*r == '/' || *r == 0); 
180 _DIAGASSERT(*locale != 0); 
181 if (*locale == '/') 
182 return (NULL); /* invalid format. */ 
183 len = r - locale; 
184 if (len + 1 > sizeof(new_categories[i])) 
185 return (NULL); /* too long */ 
186 (void)memcpy(new_categories[i], locale, len); 
187 new_categories[i][len] = '\0'; 
188 if (*r == 0) 
189 break; 
190 _DIAGASSERT(*r == '/'); 
191 if (*(locale = ++r) == 0) 
192 /* slash followed by NUL */ 
193 return (NULL); 
194 /* skip until NUL or '/' */ 
195 while (*r && *r != '/') 
196 r++; 
197 if (++i == _LC_LAST) 
198 return (NULL); /* too many slashes. */ 
199 } 
200 if (i + 1 != _LC_LAST) 
201 return (NULL); /* too few slashes. */ 
202 } 
203 } 
204 
205 if (category) 
206 return (loadlocale(category)); 
207 
208 loadlocale_success = 0; 
209 for (i = 1; i < _LC_LAST; ++i) { 
210 if (loadlocale(i) != NULL) 
211 loadlocale_success = 1; 
212 } 
213 
214 /* 
215 * If all categories failed, return NULL; we don't need to back 
216 * changes off, since none happened. 
217 */ 
218 if (!loadlocale_success) 
219 return NULL; 
220 
221 return (currentlocale()); 
222} 
223 
224static char * 
225currentlocale() 
226{ 
227 int i; 
228 
229 (void)strlcpy(current_locale_string, current_categories[1], 
230 sizeof(current_locale_string)); 
231 
232 for (i = 2; i < _LC_LAST; ++i) 
233 if (strcmp(current_categories[1], current_categories[i])) { 
234 (void)snprintf(current_locale_string, 
235 sizeof(current_locale_string), "%s/%s/%s/%s/%s/%s", 
236 current_categories[1], current_categories[2], 
237 current_categories[3], current_categories[4], 
238 current_categories[5], current_categories[6]); 
239 break; 
240 } 
241 return (current_locale_string); 
242} 
243 
244static void 
245revert_to_default(category) 
246 int category; 
247{ 
248 switch (category) { 
249 case LC_CTYPE: 
250#ifdef WITH_RUNE 
251 (void)_xpg4_setrunelocale("C"); 
252#else 
253 if (_ctype_ != _C_ctype_) { 
254 /* LINTED const castaway */ 
255 free((void *)_ctype_); 
256 _ctype_ = _C_ctype_; 
257 } 
258 if (_toupper_tab_ != _C_toupper_) { 
259 /* LINTED const castaway */ 
260 free((void *)_toupper_tab_); 
261 _toupper_tab_ = _C_toupper_; 
262 } 
263 if (_tolower_tab_ != _C_tolower_) { 
264 /* LINTED const castaway */ 
265 free((void *)_tolower_tab_); 
266 _tolower_tab_ = _C_tolower_; 
267 } 
268#endif 
269 break; 
270 case LC_TIME: 
271 if (_CurrentTimeLocale != &_DefaultTimeLocale) { 
272 free(__UNCONST(_CurrentTimeLocale)); 
273 _CurrentTimeLocale = &_DefaultTimeLocale; 
274 } 
275 break; 
276 case LC_MESSAGES: 
277 if (_CurrentMessagesLocale != &_DefaultMessagesLocale) { 
278 free(__UNCONST(_CurrentMessagesLocale)); 
279 _CurrentMessagesLocale = &_DefaultMessagesLocale; 
280 } 
281 break; 
282 case LC_COLLATE: 
283 break; 
284 case LC_MONETARY: 
285 if (_CurrentMonetaryLocale != &_DefaultMonetaryLocale) { 
286 free(__UNCONST(_CurrentMonetaryLocale)); 
287 _CurrentMonetaryLocale = &_DefaultMonetaryLocale; 
288 } 
289 break; 
290 case LC_NUMERIC: 
291 if (_CurrentNumericLocale != &_DefaultNumericLocale) { 
292 free(__UNCONST(_CurrentNumericLocale)); 
293 _CurrentNumericLocale = &_DefaultNumericLocale; 
294 } 
295 break; 
296 } 
297} 
298 
299static int 
300force_locale_enable(category) 
301 int category; 
302{ 
303 revert_to_default(category); 
304 
305 return 0; 
306} 
307 
308static int 
309load_locale_sub(category, locname, isspecial) 
310 int category; 
311 const char *locname; 
312 int isspecial; 
313{ 
314 char name[PATH_MAX]; 
315 int len; 
316 
317 /* check for the default locales */ 
318 if (!strcmp(new_categories[category], "C") || 
319 !strcmp(new_categories[category], "POSIX")) { 
320 revert_to_default(category); 
321 return 0; 
322 } 
323 
324 /* check whether special symbol */ 
325 if (isspecial && _bcs_strcasecmp(locname, _LOCALE_SYM_FORCE) == 0) 
326 return force_locale_enable(category); 
327 
328 /* sanity check */ 
329 if (strchr(locname, '/') != NULL) 
330 return -1; 
331 
332 len = snprintf(name, sizeof(name), "%s/%s/%s", 
333 _PathLocale, locname, categories[category]); 
334 if (len < 0 || len >= sizeof(name)) 
335 return -1; 
336 
337 switch (category) { 
338 case LC_CTYPE: 
339#ifdef WITH_RUNE 
340 if (_xpg4_setrunelocale(__UNCONST(locname))) 
341 return -1; 
342#else 
343 if (!__loadctype(name)) 
344 return -1; 
345#endif 
346 break; 
347 
348 case LC_MESSAGES: 
349 len += snprintf(name + len, sizeof(name) - len, "/%s", 
350 categories[category]); 
351 if (len >= sizeof(name)) 
352 return -1; 
353 if (!__loadmessages(name)) 
354#ifdef notyet 
355 return -1; 
356#else 
357 /* 
358 * XXX we don't have LC_MESSAGES support yet, 
359 * but catopen may use the value of LC_MESSAGES category. 
360 * so return successfully if locale directory is present. 
361 */ 
362 /* local */ 
363 { 
364 struct stat st; 
365 
366 (void)snprintf(name, sizeof(name), "%s/%s", 
367 _PathLocale, locname); 
368 if (stat(name, &st) < 0) 
369 return -1; 
370 if (!S_ISDIR(st.st_mode)) 
371 return -1; 
372 } 
373#endif 
374 break; 
375 
376 case LC_TIME: 
377 if (!__loadtime(name)) 
378 return -1; 
379 break; 
380 case LC_COLLATE: 
381 return -1; 
382 case LC_MONETARY: 
383 if (!__loadmonetary(name)) 
384 return -1; 
385 break; 
386 case LC_NUMERIC: 
387 if (!__loadnumeric(name)) 
388 return -1; 
389 break; 
390 } 
391 
392 return 0; 
393} 
394 
395static char * 
396loadlocale(category) 
397 int category; 
398{ 
399 char aliaspath[PATH_MAX], loccat[PATH_MAX], buf[PATH_MAX]; 
400 const char *alias; 
401 
402 _DIAGASSERT(0 < category && category < _LC_LAST); 
403 
404 if (strcmp(new_categories[category], current_categories[category]) == 0) 
405 return (current_categories[category]); 
406 
407 /* (1) non-aliased file */ 
408 if (!load_locale_sub(category, new_categories[category], 0)) 
409 goto success; 
410 
411 /* (2) lookup locname/catname type alias */ 
412 (void)snprintf(aliaspath, sizeof(aliaspath), 
413 "%s/" _LOCALE_ALIAS_NAME, _PathLocale); 
414 (void)snprintf(loccat, sizeof(loccat), "%s/%s", 
415 new_categories[category], categories[category]); 
416 alias = _lookup_alias(aliaspath, loccat, buf, sizeof(buf), 
417 _LOOKUP_CASE_SENSITIVE); 
418 if (!load_locale_sub(category, alias, 1)) 
419 goto success; 
420 
421 /* (3) lookup locname type alias */ 
422 alias = _lookup_alias(aliaspath, new_categories[category], 
423 buf, sizeof(buf), _LOOKUP_CASE_SENSITIVE); 
424 if (!load_locale_sub(category, alias, 1)) 
425 goto success; 
426 
427 return NULL; 
428 
429success: 
430 (void)strlcpy(current_categories[category], 
431 new_categories[category], 
432 sizeof(current_categories[category])); 
433 return current_categories[category]; 
434} 
435 
436static const char * 
437__get_locale_env(category) 
438 int category; 
439{ 
440 const char *env; 
441 
442 _DIAGASSERT(category != LC_ALL); 
443 
444 /* 1. check LC_ALL. */ 
445 env = getenv(categories[0]); 
446 
447 /* 2. check LC_* */ 
448 if (!env || !*env) 
449 env = getenv(categories[category]); 
450 
451 /* 3. check LANG */ 
452 if (!env || !*env) 
453 env = getenv("LANG"); 
454 
455 /* 4. if none is set, fall to "C" */ 
456 if (!env || !*env || strchr(env, '/')) 
457 env = "C"; 
458 
459 return env; 
460} 

File Deleted: src/lib/libc/locale/Attic/setrunelocale.c

cvs diff -r1.8 -r1.8.62.1 src/lib/libc/nls/Makefile.inc (expand / switch to unified diff)

--- src/lib/libc/nls/Makefile.inc 1996/05/13 23:29:32 1.8
+++ src/lib/libc/nls/Makefile.inc 2009/01/04 17:02:20 1.8.62.1
@@ -1,9 +1,16 @@ @@ -1,9 +1,16 @@
1# $NetBSD: Makefile.inc,v 1.8 1996/05/13 23:29:32 jtc Exp $ 1# $NetBSD: Makefile.inc,v 1.8.62.1 2009/01/04 17:02:20 christos Exp $
2 2
3.PATH: ${.CURDIR}/nls 3.PATH: ${.CURDIR}/nls
4 4
5SRCS+= catclose.c catgets.c catopen.c  5SRCS+= catclose.c catgets.c catopen.c
6MAN+= catclose.3 catgets.3 catopen.3 6MAN+= catclose.3 catgets.3 catopen.3
7 7
8# indirect reference stubs, to be removed soon. 8# indirect reference stubs, to be removed soon.
9SRCS+= _catclose.c _catgets.c _catopen.c 9SRCS+= _catclose.c _catgets.c _catopen.c
 10
 11.if ${CITRUS} == "yes"
 12CPPFLAGS.catopen.c+= -DHAVE_CITRUS -I${LIBCDIR}/citrus
 13.else
 14CPPFLAGS.catopen.c+= -UHAVE_CITRUS -I${LIBCDIR}/locale
 15.endif
 16

cvs diff -r1.25 -r1.25.8.1 src/lib/libc/nls/catopen.c (expand / switch to unified diff)

--- src/lib/libc/nls/catopen.c 2008/04/28 20:23:00 1.25
+++ src/lib/libc/nls/catopen.c 2008/04/28 20:23:00 1.25.8.1
@@ -1,192 +0,0 @@ @@ -1,192 +0,0 @@
1/* $NetBSD: catopen.c,v 1.25 2008/04/28 20:23:00 martin Exp $ */ 
2 
3/*- 
4 * Copyright (c) 1996 The NetBSD Foundation, Inc. 
5 * All rights reserved. 
6 * 
7 * This code is derived from software contributed to The NetBSD Foundation 
8 * by J.T. Conklin. 
9 * 
10 * Redistribution and use in source and binary forms, with or without 
11 * modification, are permitted provided that the following conditions 
12 * are met: 
13 * 1. Redistributions of source code must retain the above copyright 
14 * notice, this list of conditions and the following disclaimer. 
15 * 2. Redistributions in binary form must reproduce the above copyright 
16 * notice, this list of conditions and the following disclaimer in the 
17 * documentation and/or other materials provided with the distribution. 
18 * 
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
29 * POSSIBILITY OF SUCH DAMAGE. 
30 */ 
31 
32#include <sys/cdefs.h> 
33#if defined(LIBC_SCCS) && !defined(lint) 
34__RCSID("$NetBSD: catopen.c,v 1.25 2008/04/28 20:23:00 martin Exp $"); 
35#endif /* LIBC_SCCS and not lint */ 
36 
37#define _NLS_PRIVATE 
38 
39#include "namespace.h" 
40#include <sys/param.h> 
41#include <sys/stat.h> 
42#include <sys/mman.h> 
43 
44#include <assert.h> 
45#include <fcntl.h> 
46#include <limits.h> 
47#include <locale.h> 
48#include <nl_types.h> 
49#include <stdlib.h> 
50#include <string.h> 
51#include <unistd.h> 
52 
53#ifdef CITRUS 
54#include <citrus/citrus_namespace.h> 
55#include <citrus/citrus_region.h> 
56#include <citrus/citrus_lookup.h> 
57#else 
58#include <locale/aliasname_local.h> 
59#define _lookup_alias(p, a, b, s, c) __unaliasname((p), (a), (b), (s)) 
60#endif 
61 
62#define NLS_ALIAS_DB "/usr/share/nls/nls.alias" 
63 
64#define NLS_DEFAULT_PATH "/usr/share/nls/%L/%N.cat:/usr/share/nls/%N/%L" 
65#define NLS_DEFAULT_LANG "C" 
66 
67#ifdef __weak_alias 
68__weak_alias(catopen, _catopen) 
69#endif 
70 
71static nl_catd load_msgcat __P((const char *)); 
72 
73nl_catd 
74_catopen(name, oflag) 
75 const char *name; 
76 int oflag; 
77{ 
78 char tmppath[PATH_MAX+1]; 
79 const char *nlspath; 
80 const char *lang; 
81 char *t; 
82 const char *s, *u; 
83 nl_catd catd; 
84 char langbuf[PATH_MAX]; 
85 
86 if (name == NULL || *name == '\0') 
87 return (nl_catd)-1; 
88 
89 /* absolute or relative path? */ 
90 if (strchr(name, '/')) 
91 return load_msgcat(name); 
92 
93 if (issetugid() || (nlspath = getenv("NLSPATH")) == NULL) 
94 nlspath = NLS_DEFAULT_PATH; 
95 if (oflag == NL_CAT_LOCALE) { 
96 lang = setlocale(LC_MESSAGES, NULL); 
97 } 
98 else { 
99 lang = getenv("LANG"); 
100 } 
101 if (lang == NULL || strchr(lang, '/')) 
102 lang = NLS_DEFAULT_LANG; 
103 
104 lang = _lookup_alias(NLS_ALIAS_DB, lang, langbuf, sizeof(langbuf), 
105 _LOOKUP_CASE_SENSITIVE); 
106 
107 s = nlspath; 
108 t = tmppath; 
109 do { 
110 while (*s && *s != ':') { 
111 if (*s == '%') { 
112 switch (*(++s)) { 
113 case 'L': /* locale */ 
114 u = lang; 
115 while (*u && t < tmppath + PATH_MAX) 
116 *t++ = *u++; 
117 break; 
118 case 'N': /* name */ 
119 u = name; 
120 while (*u && t < tmppath + PATH_MAX) 
121 *t++ = *u++; 
122 break; 
123 case 'l': /* lang */ 
124 case 't': /* territory */ 
125 case 'c': /* codeset */ 
126 break; 
127 default: 
128 if (t < tmppath + PATH_MAX) 
129 *t++ = *s; 
130 } 
131 } else { 
132 if (t < tmppath + PATH_MAX) 
133 *t++ = *s; 
134 } 
135 s++; 
136 } 
137 
138 *t = '\0'; 
139 catd = load_msgcat(tmppath); 
140 if (catd != (nl_catd)-1) 
141 return catd; 
142 
143 if (*s) 
144 s++; 
145 t = tmppath; 
146 } while (*s); 
147 
148 return (nl_catd)-1; 
149} 
150 
151static nl_catd 
152load_msgcat(path) 
153 const char *path; 
154{ 
155 struct stat st; 
156 nl_catd catd; 
157 void *data; 
158 int fd; 
159 
160 _DIAGASSERT(path != NULL); 
161 
162 if ((fd = open(path, O_RDONLY)) == -1) 
163 return (nl_catd)-1; 
164 
165 if (fstat(fd, &st) != 0) { 
166 close (fd); 
167 return (nl_catd)-1; 
168 } 
169 
170 data = mmap(0, (size_t)st.st_size, PROT_READ, MAP_FILE|MAP_SHARED, fd, 
171 (off_t)0); 
172 close (fd); 
173 
174 if (data == (void *)-1) { 
175 return (nl_catd)-1; 
176 } 
177 
178 if (ntohl((u_int32_t)((struct _nls_cat_hdr *)data)->__magic) != 
179 _NLS_MAGIC) { 
180 munmap(data, (size_t)st.st_size); 
181 return (nl_catd)-1; 
182 } 
183 
184 if ((catd = malloc(sizeof (*catd))) == 0) { 
185 munmap(data, (size_t)st.st_size); 
186 return (nl_catd)-1; 
187 } 
188 
189 catd->__data = data; 
190 catd->__size = (int)st.st_size; 
191 return catd; 
192} 

cvs diff -r1.7 -r1.7.8.1 src/lib/libc/resolv/res_state.c (expand / switch to unified diff)

--- src/lib/libc/resolv/res_state.c 2008/04/28 20:23:00 1.7
+++ src/lib/libc/resolv/res_state.c 2008/04/28 20:23:00 1.7.8.1
@@ -1,73 +0,0 @@ @@ -1,73 +0,0 @@
1/* $NetBSD: res_state.c,v 1.7 2008/04/28 20:23:00 martin Exp $ */ 
2 
3/*- 
4 * Copyright (c) 2004 The NetBSD Foundation, Inc. 
5 * All rights reserved. 
6 * 
7 * This code is derived from software contributed to The NetBSD Foundation 
8 * by Christos Zoulas. 
9 * 
10 * Redistribution and use in source and binary forms, with or without 
11 * modification, are permitted provided that the following conditions 
12 * are met: 
13 * 1. Redistributions of source code must retain the above copyright 
14 * notice, this list of conditions and the following disclaimer. 
15 * 2. Redistributions in binary form must reproduce the above copyright 
16 * notice, this list of conditions and the following disclaimer in the 
17 * documentation and/or other materials provided with the distribution. 
18 * 
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
29 * POSSIBILITY OF SUCH DAMAGE. 
30 */ 
31 
32#include <sys/cdefs.h> 
33#if defined(LIBC_SCCS) && !defined(lint) 
34__RCSID("$NetBSD: res_state.c,v 1.7 2008/04/28 20:23:00 martin Exp $"); 
35#endif 
36 
37#include <sys/types.h> 
38#include <arpa/inet.h> 
39#include <arpa/nameser.h> 
40#include <netdb.h> 
41#include <resolv.h> 
42 
43struct __res_state _nres 
44# if defined(__BIND_RES_TEXT) 
45 = { .retrans = RES_TIMEOUT, } /*%< Motorola, et al. */ 
46# endif 
47 ; 
48 
49res_state __res_get_state_nothread(void); 
50void __res_put_state_nothread(res_state); 
51 
52#ifdef __weak_alias 
53__weak_alias(__res_get_state, __res_get_state_nothread) 
54__weak_alias(__res_put_state, __res_put_state_nothread) 
55/* Source compatibility; only for single threaded programs */ 
56__weak_alias(__res_state, __res_get_state_nothread) 
57#endif 
58 
59res_state 
60__res_get_state_nothread(void) 
61{ 
62 if ((_nres.options & RES_INIT) == 0 && res_ninit(&_nres) == -1) { 
63 h_errno = NETDB_INTERNAL; 
64 return NULL; 
65 } 
66 return &_nres; 
67} 
68 
69void 
70/*ARGSUSED*/ 
71__res_put_state_nothread(res_state res) 
72{ 
73} 

cvs diff -r1.11 -r1.11.40.1 src/lib/libc/rpc/rpc_soc.3 (expand / switch to unified diff)

--- src/lib/libc/rpc/rpc_soc.3 2004/02/16 02:39:36 1.11
+++ src/lib/libc/rpc/rpc_soc.3 2009/01/04 17:02:20 1.11.40.1
@@ -1,18 +1,18 @@ @@ -1,18 +1,18 @@
1.\" @(#)rpc.3n 2.4 88/08/08 4.0 RPCSRC; from 1.19 88/06/24 SMI 1.\" @(#)rpc.3n 2.4 88/08/08 4.0 RPCSRC; from 1.19 88/06/24 SMI
2.\" $NetBSD: rpc_soc.3,v 1.11 2004/02/16 02:39:36 lukem Exp $ 2.\" $NetBSD: rpc_soc.3,v 1.11.40.1 2009/01/04 17:02:20 christos Exp $
3.\" Converted to mdoc by Thomas Klausner <wiz@NetBSD.org> 3.\" Converted to mdoc by Thomas Klausner <wiz@NetBSD.org>
4.\" 4.\"
5.Dd April 17, 2003 5.Dd December 12, 2008
6.Dt RPC_SOC 3 6.Dt RPC_SOC 3
7.Os 7.Os
8.Sh NAME 8.Sh NAME
9.Nm rpc_soc , 9.Nm rpc_soc ,
10.Nm auth_destroy , 10.Nm auth_destroy ,
11.Nm authnone_create , 11.Nm authnone_create ,
12.Nm authunix_create , 12.Nm authunix_create ,
13.Nm authunix_create_default , 13.Nm authunix_create_default ,
14.Nm callrpc , 14.Nm callrpc ,
15.Nm clnt_broadcast , 15.Nm clnt_broadcast ,
16.Nm clnt_call , 16.Nm clnt_call ,
17.Nm clnt_control , 17.Nm clnt_control ,
18.Nm clnt_create , 18.Nm clnt_create ,
@@ -34,26 +34,27 @@ @@ -34,26 +34,27 @@
34.Nm pmap_getport , 34.Nm pmap_getport ,
35.Nm pmap_rmtcall , 35.Nm pmap_rmtcall ,
36.Nm pmap_set , 36.Nm pmap_set ,
37.Nm pmap_unset , 37.Nm pmap_unset ,
38.Nm registerrpc , 38.Nm registerrpc ,
39.Nm rpc_createerr , 39.Nm rpc_createerr ,
40.Nm svc_destroy , 40.Nm svc_destroy ,
41.Nm svc_fds , 41.Nm svc_fds ,
42.Nm svc_fdset , 42.Nm svc_fdset ,
43.Nm svc_getargs , 43.Nm svc_getargs ,
44.Nm svc_getcaller , 44.Nm svc_getcaller ,
45.Nm svc_getreg , 45.Nm svc_getreg ,
46.Nm svc_getregset , 46.Nm svc_getregset ,
 47.Nm svc_getrpccaller ,
47.Nm svc_register , 48.Nm svc_register ,
48.Nm svc_run , 49.Nm svc_run ,
49.Nm svc_sendreply , 50.Nm svc_sendreply ,
50.Nm svc_unregister , 51.Nm svc_unregister ,
51.Nm svcerr_auth , 52.Nm svcerr_auth ,
52.Nm svcerr_decode , 53.Nm svcerr_decode ,
53.Nm svcerr_noproc , 54.Nm svcerr_noproc ,
54.Nm svcerr_noprog , 55.Nm svcerr_noprog ,
55.Nm svcerr_progvers , 56.Nm svcerr_progvers ,
56.Nm svcerr_systemerr , 57.Nm svcerr_systemerr ,
57.Nm svcerr_weakauth , 58.Nm svcerr_weakauth ,
58.Nm svcfd_create , 59.Nm svcfd_create ,
59.Nm svcraw_create , 60.Nm svcraw_create ,
@@ -156,26 +157,28 @@ @@ -156,26 +157,28 @@
156.Fn svc_destroy "SVCXPRT *xprt" 157.Fn svc_destroy "SVCXPRT *xprt"
157.Fd fd_set svc_fdset; 158.Fd fd_set svc_fdset;
158.Fd int svc_fds; 159.Fd int svc_fds;
159.Ft int 160.Ft int
160.Fn svc_freeargs "SVCXPRT *xprt" "xdrproc_t inproc" "char *in" 161.Fn svc_freeargs "SVCXPRT *xprt" "xdrproc_t inproc" "char *in"
161.Ft int 162.Ft int
162.Fn svc_getargs "SVCXPRT *xprt" "xdrproc_t inproc" "char *in" 163.Fn svc_getargs "SVCXPRT *xprt" "xdrproc_t inproc" "char *in"
163.Ft struct sockaddr_in * 164.Ft struct sockaddr_in *
164.Fn svc_getcaller "SVCXPRT *xprt" 165.Fn svc_getcaller "SVCXPRT *xprt"
165.Ft int 166.Ft int
166.Fn svc_getreqset "fd_set *rdfds" 167.Fn svc_getreqset "fd_set *rdfds"
167.Ft int 168.Ft int
168.Fn svc_getreq "int rdfds" 169.Fn svc_getreq "int rdfds"
 170.Ft struct netbuf *
 171.Fn svc_getrpccaller "SVCXPRT *xprt"
169.Ft int 172.Ft int
170.Fn svc_register "SVCXPRT *xprt" "u_long prognum" "u_long versnum" \ 173.Fn svc_register "SVCXPRT *xprt" "u_long prognum" "u_long versnum" \
171"void (*dispatch)()" "u_long protocol" 174"void (*dispatch)()" "u_long protocol"
172.Ft int 175.Ft int
173.Fn svc_run "void" 176.Fn svc_run "void"
174.Ft int 177.Ft int
175.Fn svc_sendreply "SVCXPRT *xprt" "xdrproc_t outproc" "char *out" 178.Fn svc_sendreply "SVCXPRT *xprt" "xdrproc_t outproc" "char *out"
176.Ft void 179.Ft void
177.Fn svc_unregister "u_long prognum" "u_long versnum" 180.Fn svc_unregister "u_long prognum" "u_long versnum"
178.Ft void 181.Ft void
179.Fn svcerr_auth "SVCXPRT *xprt" "enum auth_stat why" 182.Fn svcerr_auth "SVCXPRT *xprt" "enum auth_stat why"
180.Ft void 183.Ft void
181.Fn svcerr_decode "SVCXPRT *xprt" 184.Fn svcerr_decode "SVCXPRT *xprt"
@@ -782,50 +785,56 @@ system when it decoded the arguments to  @@ -782,50 +785,56 @@ system when it decoded the arguments to
782This routine returns 1 if the results were successfully freed, 785This routine returns 1 if the results were successfully freed,
783and zero otherwise. 786and zero otherwise.
784.It Fn svc_getargs 787.It Fn svc_getargs
785A macro that decodes the arguments of an RPC request associated with 788A macro that decodes the arguments of an RPC request associated with
786the RPC service transport handle, 789the RPC service transport handle,
787.Fa xprt . 790.Fa xprt .
788The parameter 791The parameter
789.Fa in 792.Fa in
790is the address where the arguments will be placed; 793is the address where the arguments will be placed;
791.Fa inproc 794.Fa inproc
792is the XDR routine used to decode the arguments. 795is the XDR routine used to decode the arguments.
793This routine returns one if decoding succeeds, and zero otherwise. 796This routine returns one if decoding succeeds, and zero otherwise.
794.It Fn svc_getcaller 797.It Fn svc_getcaller
795The approved way of getting the network address of the caller 798The obsolete way of getting the network address of the caller
796of a procedure associated with the RPC service transport handle, 799of a procedure associated with the RPC service transport handle,
797.Fa xprt . 800.Fa xprt ,
 801use
 802.Fn svc_getrpccaller .
798.It Fn svc_getreqset 803.It Fn svc_getreqset
799This routine is only of interest if a service implementor 804This routine is only of interest if a service implementor
800does not call 805does not call
801.Fn svc_run , 806.Fn svc_run ,
802but instead implements custom asynchronous event processing. 807but instead implements custom asynchronous event processing.
803It is called when the 808It is called when the
804.Xr select 2 809.Xr select 2
805system call has determined that an RPC request has arrived on some 810system call has determined that an RPC request has arrived on some
806RPC socket(s) ; 811RPC socket(s) ;
807.Fa rdfds 812.Fa rdfds
808is the resultant read file descriptor bit mask. 813is the resultant read file descriptor bit mask.
809The routine returns when all sockets associated with the 814The routine returns when all sockets associated with the
810value of 815value of
811.Fa rdfds 816.Fa rdfds
812have been serviced. 817have been serviced.
813.It Fn svc_getreq 818.It Fn svc_getreq
814Similar to 819Similar to
815.Fn svc_getreqset , 820.Fn svc_getreqset ,
816but limited to 32 descriptors. 821but limited to 32 descriptors.
817This interface is obsoleted by 822This interface is obsoleted by
818.Fn svc_getreqset . 823.Fn svc_getreqset .
 824.It Fn svc_getrpccaller
 825The approved way of getting the network address of the caller
 826of a procedure associated with the RPC service transport handle,
 827.Fa xprt .
819.It Fn svc_register 828.It Fn svc_register
820Associates 829Associates
821.Fa prognum 830.Fa prognum
822and 831and
823.Fa versnum 832.Fa versnum
824with the service dispatch procedure, 833with the service dispatch procedure,
825.Fa dispatch . 834.Fa dispatch .
826If 835If
827.Fa protocol 836.Fa protocol
828is zero, the service is not registered with the 837is zero, the service is not registered with the
829.Xr rpcbind 8 838.Xr rpcbind 8
830service. 839service.
831If 840If

cvs diff -r1.12 -r1.12.40.1 src/lib/libc/stdio/fread.3 (expand / switch to unified diff)

--- src/lib/libc/stdio/fread.3 2003/08/07 16:43:25 1.12
+++ src/lib/libc/stdio/fread.3 2009/01/04 17:02:20 1.12.40.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: fread.3,v 1.12 2003/08/07 16:43:25 agc Exp $ 1.\" $NetBSD: fread.3,v 1.12.40.1 2009/01/04 17:02:20 christos Exp $
2.\" 2.\"
3.\" Copyright (c) 1990, 1991, 1993 3.\" Copyright (c) 1990, 1991, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
5.\" 5.\"
6.\" This code is derived from software contributed to Berkeley by 6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3, 7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems. 8.\" on Information Processing Systems.
9.\" 9.\"
10.\" Redistribution and use in source and binary forms, with or without 10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions 11.\" modification, are permitted provided that the following conditions
12.\" are met: 12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright 13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer. 14.\" notice, this list of conditions and the following disclaimer.
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE. 32.\" SUCH DAMAGE.
33.\" 33.\"
34.\" @(#)fread.3 8.2 (Berkeley) 3/8/94 34.\" @(#)fread.3 8.2 (Berkeley) 3/8/94
35.\" 35.\"
36.Dd March 8, 1994 36.Dd December 19, 2008
37.Dt FREAD 3 37.Dt FREAD 3
38.Os 38.Os
39.Sh NAME 39.Sh NAME
40.Nm fread , 40.Nm fread ,
41.Nm fwrite 41.Nm fwrite
42.Nd binary stream input/output 42.Nd binary stream input/output
43.Sh LIBRARY 43.Sh LIBRARY
44.Lb libc 44.Lb libc
45.Sh SYNOPSIS 45.Sh SYNOPSIS
46.In stdio.h 46.In stdio.h
47.Ft size_t 47.Ft size_t
48.Fn fread "void * restrict ptr" "size_t size" "size_t nmemb" "FILE * restrict stream" 48.Fn fread "void * restrict ptr" "size_t size" "size_t nmemb" "FILE * restrict stream"
49.Ft size_t 49.Ft size_t
@@ -60,26 +60,37 @@ bytes long, from the stream pointed to b @@ -60,26 +60,37 @@ bytes long, from the stream pointed to b
60storing them at the location given by 60storing them at the location given by
61.Fa ptr . 61.Fa ptr .
62.Pp 62.Pp
63The function 63The function
64.Fn fwrite 64.Fn fwrite
65writes 65writes
66.Fa nmemb 66.Fa nmemb
67objects, each 67objects, each
68.Fa size 68.Fa size
69bytes long, to the stream pointed to by 69bytes long, to the stream pointed to by
70.Fa stream , 70.Fa stream ,
71obtaining them from the location given by 71obtaining them from the location given by
72.Fa ptr . 72.Fa ptr .
 73.Pp
 74Mixing
 75.Fn fread
 76and
 77.Fn fwrite
 78calls without setting the file position explicitly using
 79.Fn fsetpos
 80between read and write or write and read operations will lead to unexpected
 81results because of buffering the file pointer not being set to the
 82expected position after each operation completes.
 83This behavior is allowed by ANSI C for efficiency and it will not be changed.
73.Sh RETURN VALUES 84.Sh RETURN VALUES
74The functions 85The functions
75.Fn fread 86.Fn fread
76and 87and
77.Fn fwrite 88.Fn fwrite
78advance the file position indicator for the stream 89advance the file position indicator for the stream
79by the number of bytes read or written. 90by the number of bytes read or written.
80They return the number of objects read or written. 91They return the number of objects read or written.
81If 92If
82.Fa size 93.Fa size
83or 94or
84.Fa nmemb 95.Fa nmemb
85is 0, the functions return 0 and the state of 96is 0, the functions return 0 and the state of

cvs diff -r1.44 -r1.44.20.1 src/lib/libc/stdio/printf.3 (expand / switch to unified diff)

--- src/lib/libc/stdio/printf.3 2007/06/09 18:51:19 1.44
+++ src/lib/libc/stdio/printf.3 2009/01/04 17:02:20 1.44.20.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: printf.3,v 1.44 2007/06/09 18:51:19 christos Exp $ 1.\" $NetBSD: printf.3,v 1.44.20.1 2009/01/04 17:02:20 christos Exp $
2.\" 2.\"
3.\" Copyright (c) 1990, 1991, 1993 3.\" Copyright (c) 1990, 1991, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
5.\" 5.\"
6.\" This code is derived from software contributed to Berkeley by 6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3, 7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems. 8.\" on Information Processing Systems.
9.\" 9.\"
10.\" Redistribution and use in source and binary forms, with or without 10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions 11.\" modification, are permitted provided that the following conditions
12.\" are met: 12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright 13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer. 14.\" notice, this list of conditions and the following disclaimer.
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE. 32.\" SUCH DAMAGE.
33.\" 33.\"
34.\" @(#)printf.3 8.1 (Berkeley) 6/4/93 34.\" @(#)printf.3 8.1 (Berkeley) 6/4/93
35.\" 35.\"
36.Dd June 9, 2007 36.Dd December 16, 2008
37.Dt PRINTF 3 37.Dt PRINTF 3
38.Os 38.Os
39.Sh NAME 39.Sh NAME
40.Nm printf , 40.Nm printf ,
41.Nm fprintf , 41.Nm fprintf ,
42.Nm sprintf , 42.Nm sprintf ,
43.Nm snprintf , 43.Nm snprintf ,
44.Nm asprintf , 44.Nm asprintf ,
45.Nm vprintf , 45.Nm vprintf ,
46.Nm vfprintf , 46.Nm vfprintf ,
47.Nm vsprintf , 47.Nm vsprintf ,
48.Nm vsnprintf , 48.Nm vsnprintf ,
49.Nm vasprintf 49.Nm vasprintf
@@ -103,34 +103,26 @@ and @@ -103,34 +103,26 @@ and
103.Fn asprintf 103.Fn asprintf
104and 104and
105.Fn vasprintf 105.Fn vasprintf
106write to a dynamically allocated string that is stored in 106write to a dynamically allocated string that is stored in
107.Fa ret . 107.Fa ret .
108.Pp 108.Pp
109These functions write the output under the control of a 109These functions write the output under the control of a
110.Fa format 110.Fa format
111string that specifies how subsequent arguments 111string that specifies how subsequent arguments
112(or arguments accessed via the variable-length argument facilities of 112(or arguments accessed via the variable-length argument facilities of
113.Xr stdarg 3 ) 113.Xr stdarg 3 )
114are converted for output. 114are converted for output.
115.Pp 115.Pp
116These functions return 
117the number of characters printed 
118(not including the trailing 
119.Ql \e0 
120used to end output to strings). 
121If an output error was encountered, these functions shall return a 
122negative value. 
123.Pp 
124.Fn asprintf 116.Fn asprintf
125and 117and
126.Fn vasprintf 118.Fn vasprintf
127return a pointer to a buffer sufficiently large to hold the 119return a pointer to a buffer sufficiently large to hold the
128string in the 120string in the
129.Fa ret 121.Fa ret
130argument. 122argument.
131This pointer should be passed to 123This pointer should be passed to
132.Xr free 3 124.Xr free 3
133to release the allocated storage when it is no longer needed. 125to release the allocated storage when it is no longer needed.
134If sufficient space cannot be allocated, these functions 126If sufficient space cannot be allocated, these functions
135will return \-1 and set 127will return \-1 and set
136.Fa ret 128.Fa ret
@@ -384,30 +376,30 @@ or @@ -384,30 +376,30 @@ or
384.Cm i 376.Cm i
385conversion, indicates that the argument is of a signed type equivalent in 377conversion, indicates that the argument is of a signed type equivalent in
386size to a 378size to a
387.Vt size_t . 379.Vt size_t .
388Similarly, when applied to an 380Similarly, when applied to an
389.Cm n 381.Cm n
390conversion, it indicates that the argument is a pointer to a signed type 382conversion, it indicates that the argument is a pointer to a signed type
391equivalent in size to a 383equivalent in size to a
392.Vt size_t . 384.Vt size_t .
393.Pp 385.Pp
394The following length modifier is valid for the 386The following length modifier is valid for the
395.Cm a , 387.Cm a ,
396.Cm A , 388.Cm A ,
397.Cm e ,  389.Cm e ,
398.Cm E ,  390.Cm E ,
399.Cm f ,  391.Cm f ,
400.Cm F ,  392.Cm F ,
401.Cm g , 393.Cm g ,
402or 394or
403.Cm G 395.Cm G
404conversion: 396conversion:
405.Bl -column ".Sy Modifier" ".Cm a , A , e , E , f , F , g , G" 397.Bl -column ".Sy Modifier" ".Cm a , A , e , E , f , F , g , G"
406.It Sy Modifier Ta Cm a , A , e , E , f , F , g , G 398.It Sy Modifier Ta Cm a , A , e , E , f , F , g , G
407.It Cm l No (ell) Ta Vt double 399.It Cm l No (ell) Ta Vt double
408(ignored, same behavior as without it) 400(ignored, same behavior as without it)
409.It Cm L Ta Vt "long double" 401.It Cm L Ta Vt "long double"
410.El 402.El
411.Pp 403.Pp
412The following length modifier is valid for the 404The following length modifier is valid for the
413.Cm c 405.Cm c
@@ -700,29 +692,41 @@ is written. @@ -700,29 +692,41 @@ is written.
700No argument is converted. 692No argument is converted.
701The complete conversion specification is 693The complete conversion specification is
702.Ql %% . 694.Ql %% .
703.El 695.El
704.Pp 696.Pp
705The decimal point 697The decimal point
706character is defined in the program's locale (category 698character is defined in the program's locale (category
707.Dv LC_NUMERIC ) . 699.Dv LC_NUMERIC ) .
708.Pp 700.Pp
709In no case does a non-existent or small field width cause truncation of 701In no case does a non-existent or small field width cause truncation of
710a numeric field; if the result of a conversion is wider than the field 702a numeric field; if the result of a conversion is wider than the field
711width, the 703width, the
712field is expanded to contain the conversion result. 704field is expanded to contain the conversion result.
 705.Sh RETURN VALUES
 706These functions return
 707the number of characters printed, or that would be printed if there
 708was adequate space in case of
 709.Fn snprintf
 710and
 711.Fn vsnprintf ,
 712(not including the trailing
 713.Ql \e0
 714used to end output to strings).
 715If an output error was encountered, these functions shall return a
 716negative value.
713.Sh EXAMPLES 717.Sh EXAMPLES
714.br 718.br
715To print a date and time in the form  719To print a date and time in the form
716.Dq Li "Sunday, July 3, 10:02" , 720.Dq Li "Sunday, July 3, 10:02" ,
717where 721where
718.Fa weekday 722.Fa weekday
719and 723and
720.Fa month 724.Fa month
721are pointers to strings: 725are pointers to strings:
722.Bd -literal -offset indent 726.Bd -literal -offset indent
723#include \*[Lt]stdio.h\*[Gt] 727#include \*[Lt]stdio.h\*[Gt]
724fprintf(stdout, "%s, %s %d, %.2d:%.2d\en", 728fprintf(stdout, "%s, %s %d, %.2d:%.2d\en",
725 weekday, month, day, hour, min); 729 weekday, month, day, hour, min);
726.Ed 730.Ed
727.Pp 731.Pp
728To print \*(Pi 732To print \*(Pi
@@ -740,116 +744,45 @@ To allocate a 128 byte string and print  @@ -740,116 +744,45 @@ To allocate a 128 byte string and print
740#include \*[Lt]stdarg.h\*[Gt] 744#include \*[Lt]stdarg.h\*[Gt]
741char *newfmt(const char *fmt, ...) 745char *newfmt(const char *fmt, ...)
742{ 746{
743 char *p; 747 char *p;
744 va_list ap; 748 va_list ap;
745 if ((p = malloc(128)) == NULL) 749 if ((p = malloc(128)) == NULL)
746 return (NULL); 750 return (NULL);
747 va_start(ap, fmt); 751 va_start(ap, fmt);
748 (void) vsnprintf(p, 128, fmt, ap); 752 (void) vsnprintf(p, 128, fmt, ap);
749 va_end(ap); 753 va_end(ap);
750 return (p); 754 return (p);
751} 755}
752.Ed 756.Ed
753.Sh SECURITY CONSIDERATIONS 
754The 
755.Fn sprintf 
756and 
757.Fn vsprintf 
758functions are easily misused in a manner which enables malicious users 
759to arbitrarily change a running program's functionality through 
760a buffer overflow attack. 
761Because 
762.Fn sprintf 
763and 
764.Fn vsprintf 
765assume an infinitely long string, 
766callers must be careful not to overflow the actual space; 
767this is often hard to assure. 
768For safety, programmers should use the 
769.Fn snprintf 
770interface instead. 
771For example: 
772.Bd -literal 
773void 
774foo(const char *arbitrary_string, const char *and_another) 
775{ 
776 char onstack[8]; 
777 
778#ifdef BAD 
779 /* 
780 * This first sprintf is bad behavior. Do not use sprintf! 
781 */ 
782 sprintf(onstack, "%s, %s", arbitrary_string, and_another); 
783#else 
784 /* 
785 * The following two lines demonstrate better use of 
786 * snprintf(). 
787 */ 
788 snprintf(onstack, sizeof(onstack), "%s, %s", arbitrary_string, 
789 and_another); 
790#endif 
791} 
792.Ed 
793.Pp 
794The 
795.Fn printf 
796and 
797.Fn sprintf 
798family of functions are also easily misused in a manner 
799allowing malicious users to arbitrarily change a running program's 
800functionality by either causing the program 
801to print potentially sensitive data 
802.Dq "left on the stack" , 
803or causing it to generate a memory fault or bus error 
804by dereferencing an invalid pointer. 
805.Pp 
806.Cm %n 
807can be used to write arbitrary data to potentially carefully-selected 
808addresses. 
809Programmers are therefore strongly advised to never pass untrusted strings 
810as the 
811.Fa format 
812argument, as an attacker can put format specifiers in the string 
813to mangle your stack, 
814leading to a possible security hole. 
815This holds true even if the string was built using a function like 
816.Fn snprintf , 
817as the resulting string may still contain user-supplied conversion specifiers 
818for later interpolation by 
819.Fn printf . 
820.Pp 
821Always use the proper secure idiom: 
822.Pp 
823.Dl "snprintf(buffer, sizeof(buffer), \*q%s\*q, string);" 
824.Sh ERRORS 757.Sh ERRORS
825In addition to the errors documented for the 758In addition to the errors documented for the
826.Xr write 2 759.Xr write 2
827system call, the 760system call, the
828.Fn printf 761.Fn printf
829family of functions may fail if: 762family of functions may fail if:
830.Bl -tag -width Er 763.Bl -tag -width Er
831.It Bq Er EILSEQ 764.It Bq Er EILSEQ
832An invalid wide character code was encountered. 765An invalid wide character code was encountered.
833.It Bq Er ENOMEM 766.It Bq Er ENOMEM
834Insufficient storage space is available. 767Insufficient storage space is available.
835.El 768.El
836.Sh SEE ALSO 769.Sh SEE ALSO
837.Xr printf 1 , 770.Xr printf 1 ,
838.Xr fmtcheck 3 , 771.Xr fmtcheck 3 ,
839.Xr printf 9 , 
840.Xr scanf 3 , 772.Xr scanf 3 ,
841.Xr setlocale 3 , 773.Xr setlocale 3 ,
842.Xr wprintf 3 774.Xr wprintf 3 ,
 775.Xr printf 9
843.Sh STANDARDS 776.Sh STANDARDS
844Subject to the caveats noted in the 777Subject to the caveats noted in the
845.Sx BUGS 778.Sx BUGS
846section below, the 779section below, the
847.Fn fprintf , 780.Fn fprintf ,
848.Fn printf , 781.Fn printf ,
849.Fn sprintf , 782.Fn sprintf ,
850.Fn vprintf , 783.Fn vprintf ,
851.Fn vfprintf , 784.Fn vfprintf ,
852and 785and
853.Fn vsprintf 786.Fn vsprintf
854functions 787functions
855conform to 788conform to
@@ -944,13 +877,84 @@ of the @@ -944,13 +877,84 @@ of the
944flag on 877flag on
945.Cm %n 878.Cm %n
946and 879and
947.Cm %p 880.Cm %p
948conversions, as well as other nonsensical combinations such as 881conversions, as well as other nonsensical combinations such as
949.Cm %Ld , 882.Cm %Ld ,
950are not standard; such combinations should be avoided. 883are not standard; such combinations should be avoided.
951.Pp 884.Pp
952The 885The
953.Nm 886.Nm
954family of functions do not correctly handle multibyte characters in the 887family of functions do not correctly handle multibyte characters in the
955.Fa format 888.Fa format
956argument. 889argument.
 890.Sh SECURITY CONSIDERATIONS
 891The
 892.Fn sprintf
 893and
 894.Fn vsprintf
 895functions are easily misused in a manner which enables malicious users
 896to arbitrarily change a running program's functionality through
 897a buffer overflow attack.
 898Because
 899.Fn sprintf
 900and
 901.Fn vsprintf
 902assume an infinitely long string,
 903callers must be careful not to overflow the actual space;
 904this is often hard to assure.
 905For safety, programmers should use the
 906.Fn snprintf
 907interface instead.
 908For example:
 909.Bd -literal
 910void
 911foo(const char *arbitrary_string, const char *and_another)
 912{
 913 char onstack[8];
 914
 915#ifdef BAD
 916 /*
 917 * This first sprintf is bad behavior. Do not use sprintf!
 918 */
 919 sprintf(onstack, "%s, %s", arbitrary_string, and_another);
 920#else
 921 /*
 922 * The following two lines demonstrate better use of
 923 * snprintf().
 924 */
 925 snprintf(onstack, sizeof(onstack), "%s, %s", arbitrary_string,
 926 and_another);
 927#endif
 928}
 929.Ed
 930.Pp
 931The
 932.Fn printf
 933and
 934.Fn sprintf
 935family of functions are also easily misused in a manner
 936allowing malicious users to arbitrarily change a running program's
 937functionality by either causing the program
 938to print potentially sensitive data
 939.Dq "left on the stack" ,
 940or causing it to generate a memory fault or bus error
 941by dereferencing an invalid pointer.
 942.Pp
 943.Cm %n
 944can be used to write arbitrary data to potentially carefully-selected
 945addresses.
 946Programmers are therefore strongly advised to never pass untrusted strings
 947as the
 948.Fa format
 949argument, as an attacker can put format specifiers in the string
 950to mangle your stack,
 951leading to a possible security hole.
 952This holds true even if the string was built using a function like
 953.Fn snprintf ,
 954as the resulting string may still contain user-supplied conversion specifiers
 955for later interpolation by
 956.Fn printf .
 957.Pp
 958Always use the proper secure idiom:
 959.Pp
 960.Dl "snprintf(buffer, sizeof(buffer), \*q%s\*q, string);"

cvs diff -r1.3 -r1.3.6.1 src/lib/libc/stdio/vfwscanf.c (expand / switch to unified diff)

--- src/lib/libc/stdio/vfwscanf.c 2008/08/28 16:41:21 1.3
+++ src/lib/libc/stdio/vfwscanf.c 2008/08/28 16:41:21 1.3.6.1
@@ -1,900 +0,0 @@ @@ -1,900 +0,0 @@
1/* $NetBSD: vfwscanf.c,v 1.3 2008/08/28 16:41:21 christos Exp $ */ 
2 
3/*- 
4 * Copyright (c) 1990, 1993 
5 * The Regents of the University of California. All rights reserved. 
6 * 
7 * This code is derived from software contributed to Berkeley by 
8 * Chris Torek. 
9 * 
10 * Redistribution and use in source and binary forms, with or without 
11 * modification, are permitted provided that the following conditions 
12 * are met: 
13 * 1. Redistributions of source code must retain the above copyright 
14 * notice, this list of conditions and the following disclaimer. 
15 * 2. Redistributions in binary form must reproduce the above copyright 
16 * notice, this list of conditions and the following disclaimer in the 
17 * documentation and/or other materials provided with the distribution. 
18 * 3. All advertising materials mentioning features or use of this software 
19 * must display the following acknowledgement: 
20 * This product includes software developed by the University of 
21 * California, Berkeley and its contributors. 
22 * 4. Neither the name of the University nor the names of its contributors 
23 * may be used to endorse or promote products derived from this software 
24 * without specific prior written permission. 
25 * 
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
36 * SUCH DAMAGE. 
37 */ 
38 
39#include <sys/cdefs.h> 
40#if defined(LIBC_SCCS) && !defined(lint) 
41#if 0 
42static char sccsid[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95"; 
43__FBSDID("$FreeBSD: src/lib/libc/stdio/vfwscanf.c,v 1.12 2004/05/02 20:13:29 obrien Exp $"); 
44#else 
45__RCSID("$NetBSD: vfwscanf.c,v 1.3 2008/08/28 16:41:21 christos Exp $"); 
46#endif 
47#endif /* LIBC_SCCS and not lint */ 
48 
49#include "namespace.h" 
50#include <ctype.h> 
51#include <inttypes.h> 
52#include <stdio.h> 
53#include <stdlib.h> 
54#include <stddef.h> 
55#include <stdarg.h> 
56#include <string.h> 
57#include <limits.h> 
58#include <wchar.h> 
59#include <wctype.h> 
60 
61#include "reentrant.h" 
62#include "local.h" 
63 
64#ifndef NO_FLOATING_POINT 
65#include <locale.h> 
66#endif 
67 
68#define BUF 513 /* Maximum length of numeric string. */ 
69 
70/* 
71 * Flags used during conversion. 
72 */ 
73#define LONG 0x01 /* l: long or double */ 
74#define LONGDBL 0x02 /* L: long double */ 
75#define SHORT 0x04 /* h: short */ 
76#define SUPPRESS 0x08 /* *: suppress assignment */ 
77#define POINTER 0x10 /* p: void * (as hex) */ 
78#define NOSKIP 0x20 /* [ or c: do not skip blanks */ 
79#define LONGLONG 0x400 /* ll: quad_t (+ deprecated q: quad) */ 
80#define INTMAXT 0x800 /* j: intmax_t */ 
81#define PTRDIFFT 0x1000 /* t: ptrdiff_t */ 
82#define SIZET 0x2000 /* z: size_t */ 
83#define SHORTSHORT 0x4000 /* hh: char */ 
84#define UNSIGNED 0x8000 /* %[oupxX] conversions */ 
85 
86/* 
87 * The following are used in integral conversions only: 
88 * SIGNOK, NDIGITS, PFXOK, and NZDIGITS 
89 */ 
90#define SIGNOK 0x40 /* +/- is (still) legal */ 
91#define NDIGITS 0x80 /* no digits detected */ 
92#define PFXOK 0x100 /* 0x prefix is (still) legal */ 
93#define NZDIGITS 0x200 /* no zero digits detected */ 
94#define HAVESIGN 0x10000 /* sign detected */ 
95 
96/* 
97 * Conversion types. 
98 */ 
99#define CT_CHAR 0 /* %c conversion */ 
100#define CT_CCL 1 /* %[...] conversion */ 
101#define CT_STRING 2 /* %s conversion */ 
102#define CT_INT 3 /* %[dioupxX] conversion */ 
103#define CT_FLOAT 4 /* %[efgEFG] conversion */ 
104 
105static int parsefloat(FILE *, wchar_t *, wchar_t *); 
106 
107#define INCCL(_c) \ 
108 (cclcompl ? (wmemchr(ccls, (_c), (size_t)(ccle - ccls)) == NULL) : \ 
109 (wmemchr(ccls, (_c), (size_t)(ccle - ccls)) != NULL)) 
110 
111/* 
112 * MT-safe version. 
113 */ 
114int 
115vfwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, va_list ap) 
116{ 
117 int ret; 
118 
119 FLOCKFILE(fp); 
120 _SET_ORIENTATION(fp, 1); 
121 ret = __vfwscanf_unlocked(fp, fmt, ap); 
122 FUNLOCKFILE(fp); 
123 return (ret); 
124} 
125 
126#define SCANF_SKIP_SPACE() \ 
127do { \ 
128 wint_t tc; \ 
129 \ 
130 while ((tc = __fgetwc_unlock(fp)) != WEOF && iswspace(tc)) \ 
131 continue; \ 
132 if (tc != WEOF) \ 
133 ungetwc(tc, fp); \ 
134} while (/*CONSTCOND*/ 0) 
135 
136/* 
137 * Non-MT-safe version. 
138 */ 
139int 
140__vfwscanf_unlocked(FILE * __restrict fp, const wchar_t * __restrict fmt, va_list ap) 
141{ 
142 wint_t c; /* character from format, or conversion */ 
143 size_t width; /* field width, or 0 */ 
144 wchar_t *p; /* points into all kinds of strings */ 
145 int n; /* handy integer */ 
146 int flags; /* flags as defined above */ 
147 wchar_t *p0; /* saves original value of p when necessary */ 
148 int nassigned; /* number of fields assigned */ 
149 int nconversions; /* number of conversions */ 
150 int nread; /* number of characters consumed from fp */ 
151 int base; /* base argument to conversion function */ 
152 wchar_t buf[BUF]; /* buffer for numeric conversions */ 
153 const wchar_t *ccls; /* character class start */ 
154 const wchar_t *ccle; /* character class end */ 
155 int cclcompl; /* ccl is complemented? */ 
156 wint_t wi; /* handy wint_t */ 
157 char *mbp; /* multibyte string pointer for %c %s %[ */ 
158 size_t nconv; /* number of bytes in mb. conversion */ 
159 char mbbuf[MB_LEN_MAX]; /* temporary mb. character buffer */ 
160 static const mbstate_t initial; 
161 mbstate_t mbs; 
162 
163 /* `basefix' is used to avoid `if' tests in the integer scanner */ 
164 static short basefix[17] = 
165 { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; 
166 
167 nassigned = 0; 
168 nconversions = 0; 
169 nread = 0; 
170 ccls = ccle = NULL; 
171 base = 0; 
172 cclcompl = 0; 
173 mbp = NULL; 
174 for (;;) { 
175 c = *fmt++; 
176 if (c == 0) 
177 return (nassigned); 
178 if (iswspace(c)) { 
179 while ((c = __fgetwc_unlock(fp)) != WEOF && 
180 iswspace(c)) 
181 ; 
182 if (c != WEOF) 
183 ungetwc(c, fp); 
184 continue; 
185 } 
186 if (c != '%') 
187 goto literal; 
188 width = 0; 
189 flags = 0; 
190 /* 
191 * switch on the format. continue if done; 
192 * break once format type is derived. 
193 */ 
194again: c = *fmt++; 
195 switch (c) { 
196 case '%': 
197 SCANF_SKIP_SPACE(); 
198literal: 
199 if ((wi = __fgetwc_unlock(fp)) == WEOF) 
200 goto input_failure; 
201 if (wi != c) { 
202 ungetwc(wi, fp); 
203 goto input_failure; 
204 } 
205 nread++; 
206 continue; 
207 
208 case '*': 
209 flags |= SUPPRESS; 
210 goto again; 
211 case 'j': 
212 flags |= INTMAXT; 
213 goto again; 
214 case 'l': 
215 if (flags & LONG) { 
216 flags &= ~LONG; 
217 flags |= LONGLONG; 
218 } else 
219 flags |= LONG; 
220 goto again; 
221 case 'q': 
222 flags |= LONGLONG; /* not quite */ 
223 goto again; 
224 case 't': 
225 flags |= PTRDIFFT; 
226 goto again; 
227 case 'z': 
228 flags |= SIZET; 
229 goto again; 
230 case 'L': 
231 flags |= LONGDBL; 
232 goto again; 
233 case 'h': 
234 if (flags & SHORT) { 
235 flags &= ~SHORT; 
236 flags |= SHORTSHORT; 
237 } else 
238 flags |= SHORT; 
239 goto again; 
240 
241 case '0': case '1': case '2': case '3': case '4': 
242 case '5': case '6': case '7': case '8': case '9': 
243 width = width * 10 + c - '0'; 
244 goto again; 
245 
246 /* 
247 * Conversions. 
248 */ 
249 case 'd': 
250 c = CT_INT; 
251 base = 10; 
252 break; 
253 
254 case 'i': 
255 c = CT_INT; 
256 base = 0; 
257 break; 
258 
259 case 'o': 
260 c = CT_INT; 
261 flags |= UNSIGNED; 
262 base = 8; 
263 break; 
264 
265 case 'u': 
266 c = CT_INT; 
267 flags |= UNSIGNED; 
268 base = 10; 
269 break; 
270 
271 case 'X': 
272 case 'x': 
273 flags |= PFXOK; /* enable 0x prefixing */ 
274 c = CT_INT; 
275 flags |= UNSIGNED; 
276 base = 16; 
277 break; 
278 
279#ifndef NO_FLOATING_POINT 
280 case 'A': case 'E': case 'F': case 'G': 
281 case 'a': case 'e': case 'f': case 'g': 
282 c = CT_FLOAT; 
283 break; 
284#endif 
285 
286 case 'S': 
287 flags |= LONG; 
288 /* FALLTHROUGH */ 
289 case 's': 
290 c = CT_STRING; 
291 break; 
292 
293 case '[': 
294 ccls = fmt; 
295 if (*fmt == '^') { 
296 cclcompl = 1; 
297 fmt++; 
298 } else 
299 cclcompl = 0; 
300 if (*fmt == ']') 
301 fmt++; 
302 while (*fmt != '\0' && *fmt != ']') 
303 fmt++; 
304 ccle = fmt; 
305 fmt++; 
306 flags |= NOSKIP; 
307 c = CT_CCL; 
308 break; 
309 
310 case 'C': 
311 flags |= LONG; 
312 /* FALLTHROUGH */ 
313 case 'c': 
314 flags |= NOSKIP; 
315 c = CT_CHAR; 
316 break; 
317 
318 case 'p': /* pointer format is like hex */ 
319 flags |= POINTER | PFXOK; 
320 c = CT_INT; /* assumes sizeof(uintmax_t) */ 
321 flags |= UNSIGNED; /* >= sizeof(uintptr_t) */ 
322 base = 16; 
323 break; 
324 
325 case 'n': 
326 nconversions++; 
327 if (flags & SUPPRESS) /* ??? */ 
328 continue; 
329 if (flags & SHORTSHORT) 
330 *va_arg(ap, char *) = nread; 
331 else if (flags & SHORT) 
332 *va_arg(ap, short *) = nread; 
333 else if (flags & LONG) 
334 *va_arg(ap, long *) = nread; 
335 else if (flags & LONGLONG) 
336 *va_arg(ap, quad_t *) = nread; 
337 else if (flags & INTMAXT) 
338 *va_arg(ap, intmax_t *) = nread; 
339 else if (flags & SIZET) 
340 *va_arg(ap, size_t *) = nread; 
341 else if (flags & PTRDIFFT) 
342 *va_arg(ap, ptrdiff_t *) = nread; 
343 else 
344 *va_arg(ap, int *) = nread; 
345 continue; 
346 
347 default: 
348 goto match_failure; 
349 
350 /* 
351 * Disgusting backwards compatibility hack. XXX 
352 */ 
353 case '\0': /* compat */ 
354 return (EOF); 
355 } 
356 
357 /* 
358 * Consume leading white space, except for formats 
359 * that suppress this. 
360 */ 
361 if ((flags & NOSKIP) == 0) { 
362 while ((wi = __fgetwc_unlock(fp)) != WEOF && iswspace(wi)) 
363 nread++; 
364 if (wi == WEOF) 
365 goto input_failure; 
366 ungetwc(wi, fp); 
367 } 
368 
369 /* 
370 * Do the conversion. 
371 */ 
372 switch (c) { 
373 
374 case CT_CHAR: 
375 /* scan arbitrary characters (sets NOSKIP) */ 
376 if (width == 0) 
377 width = 1; 
378 if (flags & LONG) { 
379 if (!(flags & SUPPRESS)) 
380 p = va_arg(ap, wchar_t *); 
381 n = 0; 
382 while (width-- != 0 && 
383 (wi = __fgetwc_unlock(fp)) != WEOF) { 
384 if (!(flags & SUPPRESS)) 
385 *p++ = (wchar_t)wi; 
386 n++; 
387 } 
388 if (n == 0) 
389 goto input_failure; 
390 nread += n; 
391 if (!(flags & SUPPRESS)) 
392 nassigned++; 
393 } else { 
394 if (!(flags & SUPPRESS)) 
395 mbp = va_arg(ap, char *); 
396 n = 0; 
397 mbs = initial; 
398 while (width != 0 && 
399 (wi = __fgetwc_unlock(fp)) != WEOF) { 
400 if (width >= MB_CUR_MAX && 
401 !(flags & SUPPRESS)) { 
402 nconv = wcrtomb(mbp, wi, &mbs); 
403 if (nconv == (size_t)-1) 
404 goto input_failure; 
405 } else { 
406 nconv = wcrtomb(mbbuf, wi, 
407 &mbs); 
408 if (nconv == (size_t)-1) 
409 goto input_failure; 
410 if (nconv > width) { 
411 ungetwc(wi, fp); 
412 break; 
413 } 
414 if (!(flags & SUPPRESS)) 
415 memcpy(mbp, mbbuf, 
416 nconv); 
417 } 
418 if (!(flags & SUPPRESS)) 
419 mbp += nconv; 
420 width -= nconv; 
421 n++; 
422 } 
423 if (n == 0) 
424 goto input_failure; 
425 nread += n; 
426 if (!(flags & SUPPRESS)) 
427 nassigned++; 
428 } 
429 nconversions++; 
430 break; 
431 
432 case CT_CCL: 
433 /* scan a (nonempty) character class (sets NOSKIP) */ 
434 if (width == 0) 
435 width = (size_t)~0; /* `infinity' */ 
436 /* take only those things in the class */ 
437 if ((flags & SUPPRESS) && (flags & LONG)) { 
438 n = 0; 
439 while ((wi = __fgetwc_unlock(fp)) != WEOF && 
440 width-- != 0 && INCCL(wi)) 
441 n++; 
442 if (wi != WEOF) 
443 ungetwc(wi, fp); 
444 if (n == 0) 
445 goto match_failure; 
446 } else if (flags & LONG) { 
447 p0 = p = va_arg(ap, wchar_t *); 
448 while ((wi = __fgetwc_unlock(fp)) != WEOF && 
449 width-- != 0 && INCCL(wi)) 
450 *p++ = (wchar_t)wi; 
451 if (wi != WEOF) 
452 ungetwc(wi, fp); 
453 n = p - p0; 
454 if (n == 0) 
455 goto match_failure; 
456 *p = 0; 
457 nassigned++; 
458 } else { 
459 if (!(flags & SUPPRESS)) 
460 mbp = va_arg(ap, char *); 
461 n = 0; 
462 mbs = initial; 
463 while ((wi = __fgetwc_unlock(fp)) != WEOF && 
464 width != 0 && INCCL(wi)) { 
465 if (width >= MB_CUR_MAX && 
466 !(flags & SUPPRESS)) { 
467 nconv = wcrtomb(mbp, wi, &mbs); 
468 if (nconv == (size_t)-1) 
469 goto input_failure; 
470 } else { 
471 nconv = wcrtomb(mbbuf, wi, 
472 &mbs); 
473 if (nconv == (size_t)-1) 
474 goto input_failure; 
475 if (nconv > width) 
476 break; 
477 if (!(flags & SUPPRESS)) 
478 memcpy(mbp, mbbuf, 
479 nconv); 
480 } 
481 if (!(flags & SUPPRESS)) 
482 mbp += nconv; 
483 width -= nconv; 
484 n++; 
485 } 
486 if (wi != WEOF) 
487 ungetwc(wi, fp); 
488 if (!(flags & SUPPRESS)) { 
489 *mbp = 0; 
490 nassigned++; 
491 } 
492 } 
493 nread += n; 
494 nconversions++; 
495 break; 
496 
497 case CT_STRING: 
498 /* like CCL, but zero-length string OK, & no NOSKIP */ 
499 if (width == 0) 
500 width = (size_t)~0; 
501 if ((flags & SUPPRESS) && (flags & LONG)) { 
502 while ((wi = __fgetwc_unlock(fp)) != WEOF && 
503 width-- != 0 && 
504 !iswspace(wi)) 
505 nread++; 
506 if (wi != WEOF) 
507 ungetwc(wi, fp); 
508 } else if (flags & LONG) { 
509 p0 = p = va_arg(ap, wchar_t *); 
510 while ((wi = __fgetwc_unlock(fp)) != WEOF && 
511 width-- != 0 && 
512 !iswspace(wi)) { 
513 *p++ = (wchar_t)wi; 
514 nread++; 
515 } 
516 if (wi != WEOF) 
517 ungetwc(wi, fp); 
518 *p = '\0'; 
519 nassigned++; 
520 } else { 
521 if (!(flags & SUPPRESS)) 
522 mbp = va_arg(ap, char *); 
523 mbs = initial; 
524 while ((wi = __fgetwc_unlock(fp)) != WEOF && 
525 width != 0 && 
526 !iswspace(wi)) { 
527 if (width >= MB_CUR_MAX && 
528 !(flags & SUPPRESS)) { 
529 nconv = wcrtomb(mbp, wi, &mbs); 
530 if (nconv == (size_t)-1) 
531 goto input_failure; 
532 } else { 
533 nconv = wcrtomb(mbbuf, wi, 
534 &mbs); 
535 if (nconv == (size_t)-1) 
536 goto input_failure; 
537 if (nconv > width) 
538 break; 
539 if (!(flags & SUPPRESS)) 
540 memcpy(mbp, mbbuf, 
541 nconv); 
542 } 
543 if (!(flags & SUPPRESS)) 
544 mbp += nconv; 
545 width -= nconv; 
546 nread++; 
547 } 
548 if (wi != WEOF) 
549 ungetwc(wi, fp); 
550 if (!(flags & SUPPRESS)) { 
551 *mbp = 0; 
552 nassigned++; 
553 } 
554 } 
555 nconversions++; 
556 continue; 
557 
558 case CT_INT: 
559 /* scan an integer as if by the conversion function */ 
560 if (width == 0 || width > sizeof(buf) / 
561 sizeof(*buf) - 1) 
562 width = sizeof(buf) / sizeof(*buf) - 1; 
563 flags |= SIGNOK | NDIGITS | NZDIGITS; 
564 for (p = buf; width; width--) { 
565 c = __fgetwc_unlock(fp); 
566 /* 
567 * Switch on the character; `goto ok' 
568 * if we accept it as a part of number. 
569 */ 
570 switch (c) { 
571 
572 /* 
573 * The digit 0 is always legal, but is 
574 * special. For %i conversions, if no 
575 * digits (zero or nonzero) have been 
576 * scanned (only signs), we will have 
577 * base==0. In that case, we should set 
578 * it to 8 and enable 0x prefixing. 
579 * Also, if we have not scanned zero digits 
580 * before this, do not turn off prefixing 
581 * (someone else will turn it off if we 
582 * have scanned any nonzero digits). 
583 */ 
584 case '0': 
585 if (base == 0) { 
586 base = 8; 
587 flags |= PFXOK; 
588 } 
589 if (flags & NZDIGITS) 
590 flags &= ~(SIGNOK|NZDIGITS|NDIGITS); 
591 else 
592 flags &= ~(SIGNOK|PFXOK|NDIGITS); 
593 goto ok; 
594 
595 /* 1 through 7 always legal */ 
596 case '1': case '2': case '3': 
597 case '4': case '5': case '6': case '7': 
598 base = basefix[base]; 
599 flags &= ~(SIGNOK | PFXOK | NDIGITS); 
600 goto ok; 
601 
602 /* digits 8 and 9 ok iff decimal or hex */ 
603 case '8': case '9': 
604 base = basefix[base]; 
605 if (base <= 8) 
606 break; /* not legal here */ 
607 flags &= ~(SIGNOK | PFXOK | NDIGITS); 
608 goto ok; 
609 
610 /* letters ok iff hex */ 
611 case 'A': case 'B': case 'C': 
612 case 'D': case 'E': case 'F': 
613 case 'a': case 'b': case 'c': 
614 case 'd': case 'e': case 'f': 
615 /* no need to fix base here */ 
616 if (base <= 10) 
617 break; /* not legal here */ 
618 flags &= ~(SIGNOK | PFXOK | NDIGITS); 
619 goto ok; 
620 
621 /* sign ok only as first character */ 
622 case '+': case '-': 
623 if (flags & SIGNOK) { 
624 flags &= ~SIGNOK; 
625 flags |= HAVESIGN; 
626 goto ok; 
627 } 
628 break; 
629  
630 /* 
631 * x ok iff flag still set & 2nd char (or 
632 * 3rd char if we have a sign). 
633 */ 
634 case 'x': case 'X': 
635 if (flags & PFXOK && p == 
636 buf + 1 + !!(flags & HAVESIGN)) { 
637 base = 16; /* if %i */ 
638 flags &= ~PFXOK; 
639 goto ok; 
640 } 
641 break; 
642 } 
643 
644 /* 
645 * If we got here, c is not a legal character 
646 * for a number. Stop accumulating digits. 
647 */ 
648 if (c != WEOF) 
649 ungetwc(c, fp); 
650 break; 
651 ok: 
652 /* 
653 * c is legal: store it and look at the next. 
654 */ 
655 *p++ = (wchar_t)c; 
656 } 
657 /* 
658 * If we had only a sign, it is no good; push 
659 * back the sign. If the number ends in `x', 
660 * it was [sign] '0' 'x', so push back the x 
661 * and treat it as [sign] '0'. 
662 */ 
663 if (flags & NDIGITS) { 
664 if (p > buf) 
665 ungetwc(*--p, fp); 
666 goto match_failure; 
667 } 
668 c = p[-1]; 
669 if (c == 'x' || c == 'X') { 
670 --p; 
671 ungetwc(c, fp); 
672 } 
673 if ((flags & SUPPRESS) == 0) { 
674 uintmax_t res; 
675 
676 *p = 0; 
677 if ((flags & UNSIGNED) == 0) 
678 res = wcstoimax(buf, NULL, base); 
679 else 
680 res = wcstoumax(buf, NULL, base); 
681 if (flags & POINTER) 
682 *va_arg(ap, void **) = 
683 (void *)(uintptr_t)res; 
684 else if (flags & SHORTSHORT) 
685 *va_arg(ap, char *) = (char)res; 
686 else if (flags & SHORT) 
687 *va_arg(ap, short *) = (short)res; 
688 else if (flags & LONG) 
689 *va_arg(ap, long *) = (long)res; 
690 else if (flags & LONGLONG) 
691 *va_arg(ap, quad_t *) = res; 
692 else if (flags & INTMAXT) 
693 *va_arg(ap, intmax_t *) = res; 
694 else if (flags & PTRDIFFT) 
695 *va_arg(ap, ptrdiff_t *) = (ptrdiff_t)res; 
696 else if (flags & SIZET) 
697 *va_arg(ap, size_t *) = (size_t)res; 
698 else 
699 *va_arg(ap, int *) = (int)res; 
700 nassigned++; 
701 } 
702 nread += p - buf; 
703 nconversions++; 
704 break; 
705 
706#ifndef NO_FLOATING_POINT 
707 case CT_FLOAT: 
708 /* scan a floating point number as if by strtod */ 
709 if (width == 0 || width > sizeof(buf) / 
710 sizeof(*buf) - 1) 
711 width = sizeof(buf) / sizeof(*buf) - 1; 
712 if ((width = parsefloat(fp, buf, buf + width)) == 0) 
713 goto match_failure; 
714 if ((flags & SUPPRESS) == 0) { 
715#ifdef notyet 
716 if (flags & LONGDBL) { 
717 long double res = wcstold(buf, &p); 
718 *va_arg(ap, long double *) = res; 
719 } else 
720#endif 
721 if (flags & LONG) { 
722 double res = wcstod(buf, &p); 
723 *va_arg(ap, double *) = res; 
724#ifdef notyet 
725 } else { 
726 float res = wcstof(buf, &p); 
727 *va_arg(ap, float *) = res; 
728#endif 
729 } 
730#ifdef DEBUG 
731 if (p - buf != width) 
732 abort(); 
733#endif 
734 nassigned++; 
735 } 
736 nread += width; 
737 nconversions++; 
738 break; 
739#endif /* !NO_FLOATING_POINT */ 
740 } 
741 } 
742input_failure: 
743 return (nconversions != 0 ? nassigned : EOF); 
744match_failure: 
745 return (nassigned); 
746} 
747 
748#ifndef NO_FLOATING_POINT 
749static int 
750parsefloat(FILE *fp, wchar_t *buf, wchar_t *end) 
751{ 
752 wchar_t *commit, *p; 
753 int infnanpos = 0; 
754 enum { 
755 S_START, S_GOTSIGN, S_INF, S_NAN, S_MAYBEHEX, 
756 S_DIGITS, S_FRAC, S_EXP, S_EXPDIGITS 
757 } state = S_START; 
758 wchar_t c; 
759 wchar_t decpt = (wchar_t)(unsigned char)*localeconv()->decimal_point; 
760 int gotmantdig = 0, ishex = 0; 
761 
762 /* 
763 * We set commit = p whenever the string we have read so far 
764 * constitutes a valid representation of a floating point 
765 * number by itself. At some point, the parse will complete 
766 * or fail, and we will ungetc() back to the last commit point. 
767 * To ensure that the file offset gets updated properly, it is 
768 * always necessary to read at least one character that doesn't 
769 * match; thus, we can't short-circuit "infinity" or "nan(...)". 
770 */ 
771 commit = buf - 1; 
772 c = WEOF; 
773 for (p = buf; p < end; ) { 
774 if ((c = __fgetwc_unlock(fp)) == WEOF) 
775 break; 
776reswitch: 
777 switch (state) { 
778 case S_START: 
779 state = S_GOTSIGN; 
780 if (c == '-' || c == '+') 
781 break; 
782 else 
783 goto reswitch; 
784 case S_GOTSIGN: 
785 switch (c) { 
786 case '0': 
787 state = S_MAYBEHEX; 
788 commit = p; 
789 break; 
790 case 'I': 
791 case 'i': 
792 state = S_INF; 
793 break; 
794 case 'N': 
795 case 'n': 
796 state = S_NAN; 
797 break; 
798 default: 
799 state = S_DIGITS; 
800 goto reswitch; 
801 } 
802 break; 
803 case S_INF: 
804 if (infnanpos > 6 || 
805 (c != "nfinity"[infnanpos] && 
806 c != "NFINITY"[infnanpos])) 
807 goto parsedone; 
808 if (infnanpos == 1 || infnanpos == 6) 
809 commit = p; /* inf or infinity */ 
810 infnanpos++; 
811 break; 
812 case S_NAN: 
813 switch (infnanpos) { 
814 case -1: /* XXX kludge to deal with nan(...) */ 
815 goto parsedone; 
816 case 0: 
817 if (c != 'A' && c != 'a') 
818 goto parsedone; 
819 break; 
820 case 1: 
821 if (c != 'N' && c != 'n') 
822 goto parsedone; 
823 else 
824 commit = p; 
825 break; 
826 case 2: 
827 if (c != '(') 
828 goto parsedone; 
829 break; 
830 default: 
831 if (c == ')') { 
832 commit = p; 
833 infnanpos = -2; 
834 } else if (!iswalnum(c) && c != '_') 
835 goto parsedone; 
836 break; 
837 } 
838 infnanpos++; 
839 break; 
840 case S_MAYBEHEX: 
841 state = S_DIGITS; 
842 if (c == 'X' || c == 'x') { 
843 ishex = 1; 
844 break; 
845 } else { /* we saw a '0', but no 'x' */ 
846 gotmantdig = 1; 
847 goto reswitch; 
848 } 
849 case S_DIGITS: 
850 if ((ishex && iswxdigit(c)) || iswdigit(c)) 
851 gotmantdig = 1; 
852 else { 
853 state = S_FRAC; 
854 if (c != decpt) 
855 goto reswitch; 
856 } 
857 if (gotmantdig) 
858 commit = p; 
859 break; 
860 case S_FRAC: 
861 if (((c == 'E' || c == 'e') && !ishex) || 
862 ((c == 'P' || c == 'p') && ishex)) { 
863 if (!gotmantdig) 
864 goto parsedone; 
865 else 
866 state = S_EXP; 
867 } else if ((ishex && iswxdigit(c)) || iswdigit(c)) { 
868 commit = p; 
869 gotmantdig = 1; 
870 } else 
871 goto parsedone; 
872 break; 
873 case S_EXP: 
874 state = S_EXPDIGITS; 
875 if (c == '-' || c == '+') 
876 break; 
877 else 
878 goto reswitch; 
879 case S_EXPDIGITS: 
880 if (iswdigit(c)) 
881 commit = p; 
882 else 
883 goto parsedone; 
884 break; 
885 default: 
886 abort(); 
887 } 
888 *p++ = c; 
889 c = WEOF; 
890 } 
891 
892parsedone: 
893 if (c != WEOF) 
894 ungetwc(c, fp); 
895 while (commit < --p) 
896 ungetwc(*p, fp); 
897 *++commit = '\0'; 
898 return (commit - buf); 
899} 
900#endif 

cvs diff -r1.3 -r1.3.28.1 src/lib/libc/stdio/vswscanf.c (expand / switch to unified diff)

--- src/lib/libc/stdio/vswscanf.c 2005/12/02 13:51:22 1.3
+++ src/lib/libc/stdio/vswscanf.c 2009/01/04 17:02:20 1.3.28.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vswscanf.c,v 1.3 2005/12/02 13:51:22 yamt Exp $ */ 1/* $NetBSD: vswscanf.c,v 1.3.28.1 2009/01/04 17:02:20 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1990, 1993 4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Donn Seeley at UUNET Technologies, Inc. 8 * Donn Seeley at UUNET Technologies, Inc.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -32,27 +32,27 @@ @@ -32,27 +32,27 @@
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE. 36 * SUCH DAMAGE.
37 */ 37 */
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40#if defined(LIBC_SCCS) && !defined(lint) 40#if defined(LIBC_SCCS) && !defined(lint)
41#if 0 41#if 0
42static char sccsid[] = "@(#)vsscanf.c 8.1 (Berkeley) 6/4/93"; 42static char sccsid[] = "@(#)vsscanf.c 8.1 (Berkeley) 6/4/93";
43__FBSDID("$FreeBSD: src/lib/libc/stdio/vswscanf.c,v 1.3 2004/04/07 09:55:05 tjr Exp $"); 43__FBSDID("$FreeBSD: src/lib/libc/stdio/vswscanf.c,v 1.3 2004/04/07 09:55:05 tjr Exp $");
44#else 44#else
45__RCSID("$NetBSD: vswscanf.c,v 1.3 2005/12/02 13:51:22 yamt Exp $"); 45__RCSID("$NetBSD: vswscanf.c,v 1.3.28.1 2009/01/04 17:02:20 christos Exp $");
46#endif 46#endif
47#endif /* LIBC_SCCS and not lint */ 47#endif /* LIBC_SCCS and not lint */
48 48
49#include <limits.h> 49#include <limits.h>
50#include <stdarg.h> 50#include <stdarg.h>
51#include <stdio.h> 51#include <stdio.h>
52#include <stdlib.h> 52#include <stdlib.h>
53#include <string.h> 53#include <string.h>
54#include <wchar.h> 54#include <wchar.h>
55#include "reentrant.h" 55#include "reentrant.h"
56#include "local.h" 56#include "local.h"
57 57
58static int eofread(void *, char *, int); 58static int eofread(void *, char *, int);
@@ -80,25 +80,26 @@ vswscanf(const wchar_t * __restrict str, @@ -80,25 +80,26 @@ vswscanf(const wchar_t * __restrict str,
80 80
81 /* 81 /*
82 * XXX Convert the wide character string to multibyte, which 82 * XXX Convert the wide character string to multibyte, which
83 * __vfwscanf() will convert back to wide characters. 83 * __vfwscanf() will convert back to wide characters.
84 */ 84 */
85 if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX + 1)) == NULL) 85 if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX + 1)) == NULL)
86 return (EOF); 86 return (EOF);
87 mbs = initial; 87 mbs = initial;
88 if ((mlen = wcsrtombs(mbstr, &rstr, SIZE_T_MAX, &mbs)) == (size_t)-1) { 88 if ((mlen = wcsrtombs(mbstr, &rstr, SIZE_T_MAX, &mbs)) == (size_t)-1) {
89 free(mbstr); 89 free(mbstr);
90 return (EOF); 90 return (EOF);
91 } 91 }
92 _FILEEXT_SETUP(&f, &fext); 92 _FILEEXT_SETUP(&f, &fext);
 93 (void)memset(WCIO_GET(&f), 0, sizeof(struct wchar_io_data));
93 f._file = -1; 94 f._file = -1;
94 f._flags = __SRD; 95 f._flags = __SRD;
95 f._bf._base = f._p = (unsigned char *)mbstr; 96 f._bf._base = f._p = (unsigned char *)mbstr;
96 f._bf._size = f._r = mlen; 97 f._bf._size = f._r = mlen;
97 f._read = eofread; 98 f._read = eofread;
98 _UB(&f)._base = NULL; 99 _UB(&f)._base = NULL;
99 f._lb._base = NULL; 100 f._lb._base = NULL;
100 r = __vfwscanf_unlocked(&f, fmt, ap); 101 r = __vfwscanf_unlocked(&f, fmt, ap);
101 free(mbstr); 102 free(mbstr);
102 103
103 return (r); 104 return (r);
104} 105}

cvs diff -r1.2 -r1.2.28.1 src/lib/libc/stdio/wprintf.3 (expand / switch to unified diff)

--- src/lib/libc/stdio/wprintf.3 2005/06/03 20:32:20 1.2
+++ src/lib/libc/stdio/wprintf.3 2009/01/04 17:02:20 1.2.28.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: wprintf.3,v 1.2 2005/06/03 20:32:20 wiz Exp $ 1.\" $NetBSD: wprintf.3,v 1.2.28.1 2009/01/04 17:02:20 christos Exp $
2.\" Copyright (c) 1990, 1991, 1993 2.\" Copyright (c) 1990, 1991, 1993
3.\" The Regents of the University of California. All rights reserved. 3.\" The Regents of the University of California. All rights reserved.
4.\" 4.\"
5.\" This code is derived from software contributed to Berkeley by 5.\" This code is derived from software contributed to Berkeley by
6.\" Chris Torek and the American National Standards Committee X3, 6.\" Chris Torek and the American National Standards Committee X3,
7.\" on Information Processing Systems. 7.\" on Information Processing Systems.
8.\" 8.\"
9.\" Redistribution and use in source and binary forms, with or without 9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions 10.\" modification, are permitted provided that the following conditions
11.\" are met: 11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright 12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer. 13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" 2. Redistributions in binary form must reproduce the above copyright
@@ -85,31 +85,26 @@ write output to the given output @@ -85,31 +85,26 @@ write output to the given output
85.Fn swprintf 85.Fn swprintf
86and 86and
87.Fn vswprintf 87.Fn vswprintf
88write to the wide character string 88write to the wide character string
89.Fa ws . 89.Fa ws .
90.Pp 90.Pp
91These functions write the output under the control of a 91These functions write the output under the control of a
92.Fa format 92.Fa format
93string that specifies how subsequent arguments 93string that specifies how subsequent arguments
94(or arguments accessed via the variable-length argument facilities of 94(or arguments accessed via the variable-length argument facilities of
95.Xr stdarg 3 ) 95.Xr stdarg 3 )
96are converted for output. 96are converted for output.
97.Pp 97.Pp
98These functions return the number of characters printed 
99(not including the trailing 
100.Ql \e0 
101used to end output to strings). 
102.Pp 
103The 98The
104.Fn swprintf 99.Fn swprintf
105and 100and
106.Fn vswprintf 101.Fn vswprintf
107functions will fail if 102functions will fail if
108.Fa n 103.Fa n
109or more wide characters were requested to be written, 104or more wide characters were requested to be written,
110.Pp 105.Pp
111The format string is composed of zero or more directives: 106The format string is composed of zero or more directives:
112ordinary 107ordinary
113characters (not 108characters (not
114.Cm % ) , 109.Cm % ) ,
115which are copied unchanged to the output stream; 110which are copied unchanged to the output stream;
@@ -583,26 +578,31 @@ No argument is converted. @@ -583,26 +578,31 @@ No argument is converted.
583The complete conversion specification 578The complete conversion specification
584is 579is
585.Ql %% . 580.Ql %% .
586.El 581.El
587.Pp 582.Pp
588The decimal point 583The decimal point
589character is defined in the program's locale (category 584character is defined in the program's locale (category
590.Dv LC_NUMERIC ) . 585.Dv LC_NUMERIC ) .
591.Pp 586.Pp
592In no case does a non-existent or small field width cause truncation of 587In no case does a non-existent or small field width cause truncation of
593a numeric field; if the result of a conversion is wider than the field 588a numeric field; if the result of a conversion is wider than the field
594width, the 589width, the
595field is expanded to contain the conversion result. 590field is expanded to contain the conversion result.
 591.Sh RETURN VALUES
 592These functions return the number of characters printed
 593(not including the trailing
 594.Ql \e0
 595used to end output to strings).
596.Sh SEE ALSO 596.Sh SEE ALSO
597.Xr btowc 3 , 597.Xr btowc 3 ,
598.Xr fputws 3 , 598.Xr fputws 3 ,
599.Xr printf 3 , 599.Xr printf 3 ,
600.Xr putwc 3 , 600.Xr putwc 3 ,
601.Xr setlocale 3 , 601.Xr setlocale 3 ,
602.Xr wcsrtombs 3 , 602.Xr wcsrtombs 3 ,
603.Xr wscanf 3 603.Xr wscanf 3
604.Sh STANDARDS 604.Sh STANDARDS
605Subject to the caveats noted in the 605Subject to the caveats noted in the
606.Sh SECURITY CONSIDERATIONS 606.Sh SECURITY CONSIDERATIONS
607Refer to 607Refer to
608.Xr printf 3 . 608.Xr printf 3 .

File Deleted: src/lib/libc/stdlib/Attic/heapsort.c

cvs diff -r1.15 -r1.15.10.1 src/lib/libc/stdlib/qsort.c (expand / switch to unified diff)

--- src/lib/libc/stdlib/qsort.c 2008/03/11 18:04:59 1.15
+++ src/lib/libc/stdlib/qsort.c 2009/01/04 17:02:20 1.15.10.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: qsort.c,v 1.15 2008/03/11 18:04:59 rmind Exp $ */ 1/* $NetBSD: qsort.c,v 1.15.10.1 2009/01/04 17:02:20 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,27 +24,27 @@ @@ -24,27 +24,27 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#if defined(LIBC_SCCS) && !defined(lint) 33#if defined(LIBC_SCCS) && !defined(lint)
34#if 0 34#if 0
35static char sccsid[] = "@(#)qsort.c 8.1 (Berkeley) 6/4/93"; 35static char sccsid[] = "@(#)qsort.c 8.1 (Berkeley) 6/4/93";
36#else 36#else
37__RCSID("$NetBSD: qsort.c,v 1.15 2008/03/11 18:04:59 rmind Exp $"); 37__RCSID("$NetBSD: qsort.c,v 1.15.10.1 2009/01/04 17:02:20 christos Exp $");
38#endif 38#endif
39#endif /* LIBC_SCCS and not lint */ 39#endif /* LIBC_SCCS and not lint */
40 40
41#include <sys/types.h> 41#include <sys/types.h>
42 42
43#include <assert.h> 43#include <assert.h>
44#include <errno.h> 44#include <errno.h>
45#include <stdlib.h> 45#include <stdlib.h>
46 46
47static inline char *med3 __P((char *, char *, char *, 47static inline char *med3 __P((char *, char *, char *,
48 int (*)(const void *, const void *))); 48 int (*)(const void *, const void *)));
49static inline void swapfunc __P((char *, char *, size_t, int)); 49static inline void swapfunc __P((char *, char *, size_t, int));
50 50

cvs diff -r1.67 -r1.67.20.1 src/lib/libc/string/Makefile.inc (expand / switch to unified diff)

--- src/lib/libc/string/Makefile.inc 2007/02/17 09:32:58 1.67
+++ src/lib/libc/string/Makefile.inc 2009/01/04 17:02:20 1.67.20.1
@@ -1,30 +1,32 @@ @@ -1,30 +1,32 @@
1# from: @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 1# from: @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
2# $NetBSD: Makefile.inc,v 1.67 2007/02/17 09:32:58 wiz Exp $ 2# $NetBSD: Makefile.inc,v 1.67.20.1 2009/01/04 17:02:20 christos Exp $
3 3
4# string sources 4# string sources
5.PATH: ${ARCHDIR}/string ${.CURDIR}/string 5.PATH: ${ARCHDIR}/string ${.CURDIR}/string
6 6
7SRCS+= bm.c strcasecmp.c strncasecmp.c strcasestr.c strcoll.c strdup.c \ 7SRCS+= bm.c strcasecmp.c strncasecmp.c strcasestr.c strcoll.c strdup.c \
8 strerror.c strlcat.c strlcpy.c strmode.c strsignal.c strtok.c \ 8 strerror.c strlcat.c strlcpy.c strmode.c strsignal.c strtok.c \
9 strtok_r.c strxfrm.c __strsignal.c strerror_r.c strndup.c \ 9 strtok_r.c strxfrm.c __strsignal.c strerror_r.c strndup.c \
10 stresep.c 10 stresep.c
11 11
12# wide char 12# wide char
13SRCS+= wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c wcslcat.c wcslcpy.c \ 13SRCS+= wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c wcslcat.c wcslcpy.c \
14 wcslen.c wcsncat.c wcscasecmp.c wcsdup.c wcsncasecmp.c \ 14 wcslen.c wcsncat.c wcscasecmp.c wcsdup.c wcsncasecmp.c \
15 wcsncmp.c wcsncpy.c wcspbrk.c wcsrchr.c wcsspn.c wcsstr.c wcstok.c \ 15 wcsncmp.c wcsncpy.c wcspbrk.c wcsrchr.c wcsspn.c wcsstr.c wcstok.c \
16 wcswcs.c wcswidth.c \ 16 wcswcs.c wmemchr.c wmemcmp.c wmemcpy.c wmemmove.c wmemset.c
17 wmemchr.c wmemcmp.c wmemcpy.c wmemmove.c wmemset.c  17CPPFLAGS.wcscmp.c+= -I${LIBCDIR}/locale
 18CPPFLAGS.wcsncmp.c+= -I${LIBCDIR}/locale
 19CPPFLAGS.wmemcmp.c+= -I${LIBCDIR}/locale
18 20
19# namespace protection wrappers 21# namespace protection wrappers
20SRCS+= _strlcat.c _strlcpy.c _strerror_r.c 22SRCS+= _strlcat.c _strlcpy.c _strerror_r.c
21 23
22# machine-dependent net sources 24# machine-dependent net sources
23# m-d Makefile.inc must include sources for: 25# m-d Makefile.inc must include sources for:
24# bcmp() bcopy() bzero() ffs() index() memchr() memcmp() memset() 26# bcmp() bcopy() bzero() ffs() index() memchr() memcmp() memset()
25# rindex() strcat() strcmp() strcpy() strcspn() strlen() 27# rindex() strcat() strcmp() strcpy() strcspn() strlen()
26# strncat() strncmp() strncpy() strpbrk() strsep() 28# strncat() strncmp() strncpy() strpbrk() strsep()
27# strspn() strstr() swav() 29# strspn() strstr() swav()
28# m-d Makefile.inc may include sources for: 30# m-d Makefile.inc may include sources for:
29# memcpy() memmem() memmove() strchr() strrchr() 31# memcpy() memmem() memmove() strchr() strrchr()
30 32

cvs diff -r1.5 -r1.5.40.1 src/lib/libc/string/wcscmp.c (expand / switch to unified diff)

--- src/lib/libc/string/wcscmp.c 2003/08/07 16:43:54 1.5
+++ src/lib/libc/string/wcscmp.c 2009/01/04 17:02:20 1.5.40.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: wcscmp.c,v 1.5 2003/08/07 16:43:54 agc Exp $ */ 1/* $NetBSD: wcscmp.c,v 1.5.40.1 2009/01/04 17:02:20 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1990, 1993 4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Chris Torek. 8 * Chris Torek.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -27,33 +27,33 @@ @@ -27,33 +27,33 @@
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36#if defined(LIBC_SCCS) && !defined(lint) 36#if defined(LIBC_SCCS) && !defined(lint)
37#if 0 37#if 0
38static char sccsid[] = "@(#)strcmp.c 8.1 (Berkeley) 6/4/93"; 38static char sccsid[] = "@(#)strcmp.c 8.1 (Berkeley) 6/4/93";
39#else 39#else
40__RCSID("$NetBSD: wcscmp.c,v 1.5 2003/08/07 16:43:54 agc Exp $"); 40__RCSID("$NetBSD: wcscmp.c,v 1.5.40.1 2009/01/04 17:02:20 christos Exp $");
41#endif 41#endif
42#endif /* LIBC_SCCS and not lint */ 42#endif /* LIBC_SCCS and not lint */
43 43
44#include <assert.h> 44#include <assert.h>
45#include <wchar.h> 45#include <wchar.h>
46#include "locale/runetype.h" 46#include "runetype.h"
47 47
48/* 48/*
49 * Compare strings. 49 * Compare strings.
50 */ 50 */
51int 51int
52wcscmp(s1, s2) 52wcscmp(s1, s2)
53 const wchar_t *s1, *s2; 53 const wchar_t *s1, *s2;
54{ 54{
55 55
56 _DIAGASSERT(s1 != NULL); 56 _DIAGASSERT(s1 != NULL);
57 _DIAGASSERT(s2 != NULL); 57 _DIAGASSERT(s2 != NULL);
58 58
59 while (*s1 == *s2++) 59 while (*s1 == *s2++)

cvs diff -r1.5 -r1.5.40.1 src/lib/libc/string/wcsncmp.c (expand / switch to unified diff)

--- src/lib/libc/string/wcsncmp.c 2003/08/07 16:43:54 1.5
+++ src/lib/libc/string/wcsncmp.c 2009/01/04 17:02:20 1.5.40.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: wcsncmp.c,v 1.5 2003/08/07 16:43:54 agc Exp $ */ 1/* $NetBSD: wcsncmp.c,v 1.5.40.1 2009/01/04 17:02:20 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1989, 1993 4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,33 +24,33 @@ @@ -24,33 +24,33 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#if defined(LIBC_SCCS) && !defined(lint) 33#if defined(LIBC_SCCS) && !defined(lint)
34#if 0 34#if 0
35static char sccsid[] = "@(#)strncmp.c 8.1 (Berkeley) 6/4/93"; 35static char sccsid[] = "@(#)strncmp.c 8.1 (Berkeley) 6/4/93";
36#else 36#else
37__RCSID("$NetBSD: wcsncmp.c,v 1.5 2003/08/07 16:43:54 agc Exp $"); 37__RCSID("$NetBSD: wcsncmp.c,v 1.5.40.1 2009/01/04 17:02:20 christos Exp $");
38#endif 38#endif
39#endif /* LIBC_SCCS and not lint */ 39#endif /* LIBC_SCCS and not lint */
40 40
41#include <assert.h> 41#include <assert.h>
42#include <wchar.h> 42#include <wchar.h>
43#include "locale/runetype.h" 43#include "runetype.h"
44 44
45int 45int
46wcsncmp(s1, s2, n) 46wcsncmp(s1, s2, n)
47 const wchar_t *s1, *s2; 47 const wchar_t *s1, *s2;
48 size_t n; 48 size_t n;
49{ 49{
50 50
51 _DIAGASSERT(s1 != NULL); 51 _DIAGASSERT(s1 != NULL);
52 _DIAGASSERT(s2 != NULL); 52 _DIAGASSERT(s2 != NULL);
53 53
54 if (n == 0) 54 if (n == 0)
55 return (0); 55 return (0);
56 do { 56 do {

File Deleted: src/lib/libc/string/Attic/wcswidth.c

cvs diff -r1.3 -r1.3.40.1 src/lib/libc/string/wmemcmp.c (expand / switch to unified diff)

--- src/lib/libc/string/wmemcmp.c 2003/04/06 18:33:23 1.3
+++ src/lib/libc/string/wmemcmp.c 2009/01/04 17:02:20 1.3.40.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: wmemcmp.c,v 1.3 2003/04/06 18:33:23 tshiozak Exp $ */ 1/* $NetBSD: wmemcmp.c,v 1.3.40.1 2009/01/04 17:02:20 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)1999 Citrus Project, 4 * Copyright (c)1999 Citrus Project,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -20,32 +20,32 @@ @@ -20,32 +20,32 @@
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 * 27 *
28 * citrus Id: wmemcmp.c,v 1.2 2000/12/20 14:08:31 itojun Exp 28 * citrus Id: wmemcmp.c,v 1.2 2000/12/20 14:08:31 itojun Exp
29 */ 29 */
30 30
31#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32#if defined(LIBC_SCCS) && !defined(lint) 32#if defined(LIBC_SCCS) && !defined(lint)
33__RCSID("$NetBSD: wmemcmp.c,v 1.3 2003/04/06 18:33:23 tshiozak Exp $"); 33__RCSID("$NetBSD: wmemcmp.c,v 1.3.40.1 2009/01/04 17:02:20 christos Exp $");
34#endif /* LIBC_SCCS and not lint */ 34#endif /* LIBC_SCCS and not lint */
35 35
36#include <assert.h> 36#include <assert.h>
37#include <wchar.h> 37#include <wchar.h>
38#include "locale/runetype.h" 38#include "runetype.h"
39 39
40int 40int
41wmemcmp(s1, s2, n) 41wmemcmp(s1, s2, n)
42 const wchar_t *s1; 42 const wchar_t *s1;
43 const wchar_t *s2; 43 const wchar_t *s2;
44 size_t n; 44 size_t n;
45{ 45{
46 size_t i; 46 size_t i;
47 47
48 _DIAGASSERT(s1 != NULL); 48 _DIAGASSERT(s1 != NULL);
49 _DIAGASSERT(s2 != NULL); 49 _DIAGASSERT(s2 != NULL);
50 50
51 for (i = 0; i < n; i++) { 51 for (i = 0; i < n; i++) {

cvs diff -r1.33 -r1.33.6.1 src/lib/libc/sys/chmod.2 (expand / switch to unified diff)

--- src/lib/libc/sys/chmod.2 2008/09/05 03:28:15 1.33
+++ src/lib/libc/sys/chmod.2 2008/09/05 03:28:15 1.33.6.1
@@ -1,246 +0,0 @@ @@ -1,246 +0,0 @@
1.\" $NetBSD: chmod.2,v 1.33 2008/09/05 03:28:15 dholland Exp $ 
2.\" 
3.\" Copyright (c) 1980, 1991, 1993 
4.\" The Regents of the University of California. All rights reserved. 
5.\" 
6.\" Redistribution and use in source and binary forms, with or without 
7.\" modification, are permitted provided that the following conditions 
8.\" are met: 
9.\" 1. Redistributions of source code must retain the above copyright 
10.\" notice, this list of conditions and the following disclaimer. 
11.\" 2. Redistributions in binary form must reproduce the above copyright 
12.\" notice, this list of conditions and the following disclaimer in the 
13.\" documentation and/or other materials provided with the distribution. 
14.\" 3. Neither the name of the University nor the names of its contributors 
15.\" may be used to endorse or promote products derived from this software 
16.\" without specific prior written permission. 
17.\" 
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
28.\" SUCH DAMAGE. 
29.\" 
30.\" @(#)chmod.2 8.1 (Berkeley) 6/4/93 
31.\" 
32.Dd September 4, 2008 
33.Dt CHMOD 2 
34.Os 
35.Sh NAME 
36.Nm chmod , 
37.Nm lchmod , 
38.Nm fchmod 
39.Nd change mode of file 
40.Sh LIBRARY 
41.Lb libc 
42.Sh SYNOPSIS 
43.In sys/stat.h 
44.Ft int 
45.Fn chmod "const char *path" "mode_t mode" 
46.Ft int 
47.Fn lchmod "const char *path" "mode_t mode" 
48.Ft int 
49.Fn fchmod "int fd" "mode_t mode" 
50.Sh DESCRIPTION 
51The function 
52.Fn chmod 
53sets the file permission bits 
54of the file 
55specified by the pathname 
56.Fa path 
57to 
58.Fa mode . 
59.Fn fchmod 
60sets the permission bits of the specified 
61file descriptor 
62.Fa fd . 
63.Fn lchmod 
64is like 
65.Fn chmod 
66except in the case where the named file is a symbolic link, 
67in which case 
68.Fn lchmod 
69sets the permission bits of the link, 
70while 
71.Fn chmod 
72sets the bits of the file the link references. 
73.Fn chmod 
74verifies that the process owner (user) either owns 
75the file specified by 
76.Fa path 
77(or 
78.Fa fd ) , 
79or 
80is the super-user. 
81A mode is created from 
82.Em or'd 
83permission bit masks 
84defined in 
85.Aq Pa sys/stat.h : 
86.Bd -literal -offset indent -compact 
87#define S_IRWXU 0000700 /* RWX mask for owner */ 
88#define S_IRUSR 0000400 /* R for owner */ 
89#define S_IWUSR 0000200 /* W for owner */ 
90#define S_IXUSR 0000100 /* X for owner */ 
91 
92#define S_IRWXG 0000070 /* RWX mask for group */ 
93#define S_IRGRP 0000040 /* R for group */ 
94#define S_IWGRP 0000020 /* W for group */ 
95#define S_IXGRP 0000010 /* X for group */ 
96 
97#define S_IRWXO 0000007 /* RWX mask for other */ 
98#define S_IROTH 0000004 /* R for other */ 
99#define S_IWOTH 0000002 /* W for other */ 
100#define S_IXOTH 0000001 /* X for other */ 
101 
102#define S_ISUID 0004000 /* set user id on execution */ 
103#define S_ISGID 0002000 /* set group id on execution */ 
104#define S_ISVTX 0001000 /* save swapped text even after use */ 
105.Ed 
106.Pp 
107If mode 
108.Dv ISVTX 
109(the 
110.Sq sticky bit ) 
111is set on a regular file, it historically meant that the system should 
112save a shareable copy of the program text in the swap area. 
113When applied to commonly used programs like the shell or editor, this 
114would decrease memory usage and startup time. 
115In 
116.Nx , 
117the sticky bit may still be set on regular files by the super-user, 
118but has no effect. 
119The historical meaning became obsolete in the 1980s with the advent of 
120memory-mapped executables, and is only documented as a matter of 
121historical interest. 
122.Pp 
123If mode 
124.Dv ISVTX 
125(the 
126.Sq sticky bit ) 
127is set on a directory, 
128an unprivileged user may not delete or rename 
129files of other users in that directory. 
130The sticky bit may be set by any user on a directory which the user 
131owns or has appropriate permissions. 
132.Pp 
133For more information about the properties of the sticky bit, see 
134.Xr sticky 7 . 
135.Pp 
136Changing the owner of a file 
137turns off the set-user-id and set-group-id bits; 
138writing to a file 
139turns off the set-user-id and set-group-id bits 
140unless the user is the super-user. 
141This makes the system somewhat more secure 
142by protecting set-user-id (set-group-id) files 
143from remaining set-user-id (set-group-id) if they are modified, 
144at the expense of a degree of compatibility. 
145.Sh RETURN VALUES 
146Upon successful completion, a value of 0 is returned. 
147Otherwise, a value of \-1 is returned and 
148.Va errno 
149is set to indicate the error. 
150.Sh ERRORS 
151.Fn chmod 
152and 
153.Fn lchmod 
154will fail and the file mode will be unchanged if: 
155.Bl -tag -width Er 
156.It Bq Er ENOTDIR 
157A component of the path prefix is not a directory. 
158.It Bq Er ENAMETOOLONG 
159A component of a pathname exceeded 
160.Dv {NAME_MAX} 
161characters, or an entire path name exceeded 
162.Dv {PATH_MAX} 
163characters. 
164.It Bq Er ENOENT 
165The named file does not exist. 
166.It Bq Er EACCES 
167Search permission is denied for a component of the path prefix. 
168.It Bq Er ELOOP 
169Too many symbolic links were encountered in translating the pathname. 
170.It Bq Er EPERM 
171The effective user ID does not match the owner of the file and 
172the effective user ID is not the super-user. 
173.It Bq Er EPERM 
174The mode includes the setgid bit 
175.Pq Dv S_ISGID 
176but the file's group is neither the effective group ID nor is it in the 
177group access list. 
178.It Bq Er EROFS 
179The named file resides on a read-only file system. 
180.It Bq Er EFAULT 
181.Fa path 
182points outside the process's allocated address space. 
183.It Bq Er EIO 
184An I/O error occurred while reading from or writing to the file system. 
185.It Bq Er EFTYPE 
186The effective user ID is not the super-user, the 
187.Fa mode 
188includes the sticky bit 
189.Pq Dv S_ISVTX , 
190and 
191.Fa path 
192does not refer to a directory. 
193.El 
194.Pp 
195.Fn fchmod 
196will fail if: 
197.Bl -tag -width Er 
198.It Bq Er EBADF 
199The descriptor is not valid. 
200.It Bq Er EINVAL 
201.Fa fd 
202refers to a socket, not to a file. 
203.It Bq Er EPERM 
204The effective user ID does not match the owner of the file and 
205the effective user ID is not the super-user. 
206.It Bq Er EPERM 
207The mode includes the setgid bit 
208.Pq Dv S_ISGID 
209but the file's group is neither the effective group ID nor is it in the 
210group access list. 
211.It Bq Er EROFS 
212The file resides on a read-only file system. 
213.It Bq Er EIO 
214An I/O error occurred while reading from or writing to the file system. 
215.It Bq Er EFTYPE 
216The effective user ID is not the super-user, the 
217.Fa mode 
218includes the sticky bit 
219.Pq Dv S_ISVTX , 
220and 
221.Fa fd 
222does not refer to a directory. 
223.El 
224.Sh SEE ALSO 
225.Xr chmod 1 , 
226.Xr chflags 2 , 
227.Xr chown 2 , 
228.Xr open 2 , 
229.Xr stat 2 , 
230.Xr sticky 7 , 
231.Xr symlink 7 
232.Sh STANDARDS 
233The 
234.Fn chmod 
235function conforms to 
236.St -p1003.1-90 . 
237.Sh HISTORY 
238The 
239.Fn fchmod 
240function call 
241appeared in 
242.Bx 4.2 . 
243The 
244.Fn lchmod 
245function call appeared in 
246.Nx 1.3 . 

cvs diff -r1.19 -r1.19.12.1 src/lib/libc/sys/dup.2 (expand / switch to unified diff)

--- src/lib/libc/sys/dup.2 2008/02/09 04:58:30 1.19
+++ src/lib/libc/sys/dup.2 2009/01/04 17:02:20 1.19.12.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: dup.2,v 1.19 2008/02/09 04:58:30 dholland Exp $ 1.\" $NetBSD: dup.2,v 1.19.12.1 2009/01/04 17:02:20 christos Exp $
2.\" 2.\"
3.\" Copyright (c) 1980, 1991, 1993 3.\" Copyright (c) 1980, 1991, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
5.\" 5.\"
6.\" Redistribution and use in source and binary forms, with or without 6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions 7.\" modification, are permitted provided that the following conditions
8.\" are met: 8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright 9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer. 10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the 12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution. 13.\" documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors 14.\" 3. Neither the name of the University nor the names of its contributors
@@ -19,27 +19,27 @@ @@ -19,27 +19,27 @@
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE. 28.\" SUCH DAMAGE.
29.\" 29.\"
30.\" @(#)dup.2 8.1 (Berkeley) 6/4/93 30.\" @(#)dup.2 8.1 (Berkeley) 6/4/93
31.\" 31.\"
32.Dd February 8, 2008 32.Dd December 2, 2008
33.Dt DUP 2 33.Dt DUP 2
34.Os 34.Os
35.Sh NAME 35.Sh NAME
36.Nm dup , 36.Nm dup ,
37.Nm dup2 37.Nm dup2
38.Nd duplicate an existing file descriptor 38.Nd duplicate an existing file descriptor
39.Sh LIBRARY 39.Sh LIBRARY
40.Lb libc 40.Lb libc
41.Sh SYNOPSIS 41.Sh SYNOPSIS
42.In unistd.h 42.In unistd.h
43.Ft int 43.Ft int
44.Fn dup "int oldd" 44.Fn dup "int oldd"
45.Ft int 45.Ft int
@@ -103,29 +103,30 @@ are the same, the call has no effect. @@ -103,29 +103,30 @@ are the same, the call has no effect.
103.Sh RETURN VALUES 103.Sh RETURN VALUES
104The value \-1 is returned if an error occurs in either call. 104The value \-1 is returned if an error occurs in either call.
105The external variable 105The external variable
106.Va errno 106.Va errno
107indicates the cause of the error. 107indicates the cause of the error.
108.Sh ERRORS 108.Sh ERRORS
109.Fn dup 109.Fn dup
110and 110and
111.Fn dup2 111.Fn dup2
112fail if: 112fail if:
113.Bl -tag -width Er 113.Bl -tag -width Er
114.It Bq Er EBADF 114.It Bq Er EBADF
115.Fa oldd 115.Fa oldd
 116is not a valid active descriptor
116or 117or
117.Fa newd 118.Fa newd
118is not a valid active descriptor 119is not in the range of valid file descriptors.
119.It Bq Er EMFILE 120.It Bq Er EMFILE
120Too many descriptors are active. 121Too many descriptors are active.
121.El 122.El
122.Sh SEE ALSO 123.Sh SEE ALSO
123.Xr accept 2 , 124.Xr accept 2 ,
124.Xr close 2 , 125.Xr close 2 ,
125.Xr fcntl 2 , 126.Xr fcntl 2 ,
126.Xr open 2 , 127.Xr open 2 ,
127.Xr pipe 2 , 128.Xr pipe 2 ,
128.Xr socket 2 , 129.Xr socket 2 ,
129.Xr socketpair 2 , 130.Xr socketpair 2 ,
130.Xr getdtablesize 3 131.Xr getdtablesize 3
131.Sh STANDARDS 132.Sh STANDARDS

cvs diff -r1.49 -r1.49.12.1 src/lib/libc/sys/intro.2 (expand / switch to unified diff)

--- src/lib/libc/sys/intro.2 2008/02/13 10:48:18 1.49
+++ src/lib/libc/sys/intro.2 2009/01/04 17:02:20 1.49.12.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: intro.2,v 1.49 2008/02/13 10:48:18 rillig Exp $ 1.\" $NetBSD: intro.2,v 1.49.12.1 2009/01/04 17:02:20 christos Exp $
2.\" 2.\"
3.\" Copyright (c) 1980, 1983, 1986, 1991, 1993 3.\" Copyright (c) 1980, 1983, 1986, 1991, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
5.\" 5.\"
6.\" Redistribution and use in source and binary forms, with or without 6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions 7.\" modification, are permitted provided that the following conditions
8.\" are met: 8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright 9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer. 10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the 12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution. 13.\" documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors 14.\" 3. Neither the name of the University nor the names of its contributors
@@ -19,27 +19,27 @@ @@ -19,27 +19,27 @@
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE. 28.\" SUCH DAMAGE.
29.\" 29.\"
30.\" @(#)intro.2 8.5 (Berkeley) 2/27/95 30.\" @(#)intro.2 8.5 (Berkeley) 2/27/95
31.\" 31.\"
32.Dd November 4, 2007 32.Dd November 28, 2008
33.Dt INTRO 2 33.Dt INTRO 2
34.Os 34.Os
35.Sh NAME 35.Sh NAME
36.Nm intro , 36.Nm intro ,
37.Nm errno 37.Nm errno
38.Nd introduction to system calls and error numbers 38.Nd introduction to system calls and error numbers
39.Sh SYNOPSIS 39.Sh SYNOPSIS
40.In errno.h 40.In errno.h
41.Sh DESCRIPTION 41.Sh DESCRIPTION
42This section provides an overview of the system calls, 42This section provides an overview of the system calls,
43their error returns, and other common definitions and concepts. 43their error returns, and other common definitions and concepts.
44.\".Pp 44.\".Pp
45.\".Sy System call restart 45.\".Sy System call restart
@@ -565,27 +565,27 @@ These are initialized from the equivalen @@ -565,27 +565,27 @@ These are initialized from the equivalen
565of the process that created it. 565of the process that created it.
566.It "Effective User Id, Effective Group Id, and Group Access List" 566.It "Effective User Id, Effective Group Id, and Group Access List"
567Access to system resources is governed by two values: 567Access to system resources is governed by two values:
568the effective user ID, and the group access list. 568the effective user ID, and the group access list.
569The first member of the group access list is also known as the 569The first member of the group access list is also known as the
570effective group ID. 570effective group ID.
571(In POSIX.1, the group access list is known as the set of supplementary 571(In POSIX.1, the group access list is known as the set of supplementary
572group IDs, and it is unspecified whether the effective group ID is 572group IDs, and it is unspecified whether the effective group ID is
573a member of the list.) 573a member of the list.)
574.Pp 574.Pp
575The effective user ID and effective group ID are initially the 575The effective user ID and effective group ID are initially the
576process's real user ID and real group ID respectively. 576process's real user ID and real group ID respectively.
577Either may be modified through execution of a set-user-ID or 577Either may be modified through execution of a set-user-ID or
578set-group-ID file (possibly by one its ancestors) (see 578set-group-ID file (possibly by one of its ancestors) (see
579.Xr execve 2 ) . 579.Xr execve 2 ) .
580By convention, the effective group ID (the first member of the group access 580By convention, the effective group ID (the first member of the group access
581list) is duplicated, so that the execution of a set-group-ID program 581list) is duplicated, so that the execution of a set-group-ID program
582does not result in the loss of the original (real) group ID. 582does not result in the loss of the original (real) group ID.
583.Pp 583.Pp
584The group access list is a set of group IDs 584The group access list is a set of group IDs
585used only in determining resource accessibility. 585used only in determining resource accessibility.
586Access checks are performed as described below in 586Access checks are performed as described below in
587.Qq File Access Permissions . 587.Qq File Access Permissions .
588.It "Saved Set User ID and Saved Set Group ID" 588.It "Saved Set User ID and Saved Set Group ID"
589When a process executes a new file, the effective user ID is set 589When a process executes a new file, the effective user ID is set
590to the owner of the file if the file is set-user-ID, and the effective 590to the owner of the file if the file is set-user-ID, and the effective
591group ID (first element of the group access list) is set to the group 591group ID (first element of the group access list) is set to the group

cvs diff -r1.12 -r1.12.34.1 src/lib/libc/sys/undelete.2 (expand / switch to unified diff)

--- src/lib/libc/sys/undelete.2 2004/05/13 10:20:58 1.12
+++ src/lib/libc/sys/undelete.2 2009/01/04 17:02:20 1.12.34.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: undelete.2,v 1.12 2004/05/13 10:20:58 wiz Exp $ 1.\" $NetBSD: undelete.2,v 1.12.34.1 2009/01/04 17:02:20 christos Exp $
2.\" 2.\"
3.\" Copyright (c) 1994 3.\" Copyright (c) 1994
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
5.\" 5.\"
6.\" Redistribution and use in source and binary forms, with or without 6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions 7.\" modification, are permitted provided that the following conditions
8.\" are met: 8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright 9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer. 10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the 12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution. 13.\" documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors 14.\" 3. Neither the name of the University nor the names of its contributors
@@ -50,86 +50,79 @@ @@ -50,86 +50,79 @@
50.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 50.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 51.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 52.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 54.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 55.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 56.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 57.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59.\" SUCH DAMAGE. 59.\" SUCH DAMAGE.
60.\" 60.\"
61.\" @(#)undelete.2 8.4 (Berkeley) 10/18/94 61.\" @(#)undelete.2 8.4 (Berkeley) 10/18/94
62.\" 62.\"
63.Dd October 18, 1994 63.Dd November 28, 2008
64.Dt UNDELETE 2 64.Dt UNDELETE 2
65.Os 65.Os
66.Sh NAME 66.Sh NAME
67.Nm undelete 67.Nm undelete
68.Nd attempt to recover a deleted file 68.Nd remove whiteout
69.Sh LIBRARY 69.Sh LIBRARY
70.Lb libc 70.Lb libc
71.Sh SYNOPSIS 71.Sh SYNOPSIS
72.In unistd.h 72.In unistd.h
73.Ft int 73.Ft int
74.Fn undelete "const char *path" 74.Fn undelete "const char *path"
75.Sh DESCRIPTION 75.Sh DESCRIPTION
76The 76Currently
77.Fn undelete 77.Nm
78function attempts to recover the deleted file named by 78works only when the named object
79.Fa path . 
80Currently, this works only when the named object 
81is a whiteout in a union filesystem. 79is a whiteout in a union filesystem.
82The system call removes the whiteout causing 80The system call removes the whiteout causing
83any objects in a lower layer of the 81any objects in a lower layer of the
84union stack to become visible once more. 82union stack to become visible once more.
85.Pp 
86Eventually, the 
87.Nm undelete 
88functionality may be expanded to other filesystems able to recover 
89deleted files such as the log-structured filesystem. 
90.Sh RETURN VALUES 83.Sh RETURN VALUES
91Upon successful completion, a value of 0 is returned. 84Upon successful completion, a value of 0 is returned.
92Otherwise, a value of \-1 is returned and 85Otherwise, a value of \-1 is returned and
93.Va errno 86.Va errno
94is set to indicate the error. 87is set to indicate the error.
95.Sh ERRORS 88.Sh ERRORS
96The 89The
97.Fn undelete 90.Fn undelete
98succeeds unless: 91succeeds unless:
99.Bl -tag -width ENAMETOOLONGAA 92.Bl -tag -width ENAMETOOLONGAA
100.It Bq Er ENOTDIR 93.It Bq Er EACCES
101A component of the path prefix is not a directory. 94Search permission is denied for a component of the path prefix, or
 95write permission is denied on the directory containing the name
 96to be undeleted.
 97.It Bq Er EEXIST
 98The path does not reference a whiteout.
 99.It Bq Er EFAULT
 100.Fa path
 101points outside the process's allocated address space.
102.It Bq Er EINVAL 102.It Bq Er EINVAL
103The pathname contains a character with the high-order bit set. 103The pathname contains a character with the high-order bit set.
 104.It Bq Er EIO
 105An I/O error occurred while updating the directory entry.
 106.It Bq Er ELOOP
 107Too many symbolic links were encountered in translating the pathname.
104.It Bq Er ENAMETOOLONG 108.It Bq Er ENAMETOOLONG
105A component of a pathname exceeded 255 characters, 109A component of a pathname exceeded 255 characters,
106or an entire path name exceeded 1023 characters. 110or an entire path name exceeded 1023 characters.
107.It Bq Er EEXIST 
108The path does not reference a whiteout. 
109.It Bq Er ENOENT 111.It Bq Er ENOENT
110The named whiteout does not exist. 112The named whiteout does not exist.
111.It Bq Er EACCES 113.It Bq Er ENOTDIR
112Search permission is denied for a component of the path prefix, or 114A component of the path prefix is not a directory.
113write permission is denied on the directory containing the name 
114to be undeleted. 
115.It Bq Er ELOOP 
116Too many symbolic links were encountered in translating the pathname. 
117.It Bq Er EPERM 115.It Bq Er EPERM
118The directory containing the name is marked sticky, 116The directory containing the name is marked sticky,
119and the containing directory is not owned by the effective user ID. 117and the containing directory is not owned by the effective user ID.
120.It Bq Er EIO 
121An I/O error occurred while updating the directory entry. 
122.It Bq Er EROFS 118.It Bq Er EROFS
123The name resides on a read-only file system. 119The name resides on a read-only file system.
124.It Bq Er EFAULT 
125.Fa path 
126points outside the process's allocated address space. 
127.El 120.El
128.Sh SEE ALSO 121.Sh SEE ALSO
129.Xr unlink 2 , 122.Xr unlink 2 ,
130.Xr mount_union 8 123.Xr mount_union 8
131.Sh HISTORY 124.Sh HISTORY
132An 125An
133.Nm undelete 126.Nm undelete
134function call first appeared in 127function call first appeared in
135.Bx 4.4 -Lite . 128.Bx 4.4 -Lite .