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
--- 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] | | | |
28 | major=12 | | | |
29 | minor=163 | | | |
--- 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 | | | | |
47 | int | | | |
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 | } | | | |
--- 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 | |
6 | CITRUS?= yes | | 6 | CITRUS?= yes |
7 | | | 7 | |
8 | .if ${CITRUS} == "yes" | | 8 | .if ${CITRUS} == "yes" |
9 | MODULE_SHLIB_MAJOR!= . ${NETBSDSRCDIR}/lib/i18n_module/shlib_version ; echo $$major | | 9 | MODULE_SHLIB_MAJOR!= . ${NETBSDSRCDIR}/lib/i18n_module/shlib_version ; echo $$major |
10 | CPPFLAGS+= -DI18NMODULE_MAJOR=${MODULE_SHLIB_MAJOR} -DCITRUS | | 10 | CPPFLAGS.citrus_module.c+=-DI18NMODULE_MAJOR=${MODULE_SHLIB_MAJOR} |
11 | | | 11 | SRCS+= citrus_bcs.c citrus_bcs_strtol.c citrus_bcs_strtoul.c \ |
12 | SRCS+= 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 | | | 17 | SRCS+= citrus_lc_ctype.c \ |
| | | 18 | citrus_lc_monetary.c \ |
| | | 19 | citrus_lc_numeric.c \ |
| | | 20 | citrus_lc_time.c \ |
| | | 21 | citrus_lc_messages.c |
| | | 22 | CPPFLAGS.citrus_bcs_strtol.c+= -I${LIBCDIR}/../../common/lib/libc/stdlib |
| | | 23 | CPPFLAGS.citrus_bcs_strtoul.c+= -I${LIBCDIR}/../../common/lib/libc/stdlib |
| | | 24 | CPPFLAGS.citrus_lc_ctype.c+= -I${LIBCDIR}/locale |
| | | 25 | CPPFLAGS.citrus_lc_monetary.c+= -I${LIBCDIR}/locale |
| | | 26 | CPPFLAGS.citrus_lc_numeric.c+= -I${LIBCDIR}/locale |
| | | 27 | CPPFLAGS.citrus_lc_time.c+= -I${LIBCDIR}/locale |
| | | 28 | CPPFLAGS.citrus_lc_messages.c+= -I${LIBCDIR}/locale |
18 | .endif | | 29 | .endif |
/* $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_*/
/* $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"
/* $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"
/* $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_*/
/* $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_);
/* $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_);
/* $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_*/
/* $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_);
/* $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_*/
/* $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_);
/* $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_*/
/* $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_ */
/* $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_*/
/* $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_);
/* $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_*/
--- 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 |
78 | int _citrus_bcs_strcasecmp(const char * __restrict, const char * __restrict); | | 78 | int _citrus_bcs_strcasecmp(const char * __restrict, const char * __restrict); |
79 | int _citrus_bcs_strncasecmp(const char * __restrict, const char * __restrict, | | 79 | int _citrus_bcs_strncasecmp(const char * __restrict, const char * __restrict, |
80 | size_t); | | 80 | size_t); |
81 | const char *_citrus_bcs_skip_ws(const char * __restrict); | | 81 | const char *_citrus_bcs_skip_ws(const char * __restrict); |
82 | const char *_citrus_bcs_skip_nonws(const char * __restrict); | | 82 | const char *_citrus_bcs_skip_nonws(const char * __restrict); |
83 | const char *_citrus_bcs_skip_ws_len(const char * __restrict, | | 83 | const char *_citrus_bcs_skip_ws_len(const char * __restrict, |
84 | size_t * __restrict); | | 84 | size_t * __restrict); |
85 | const char *_citrus_bcs_skip_nonws_len(const char * __restrict, | | 85 | const char *_citrus_bcs_skip_nonws_len(const char * __restrict, |
86 | size_t * __restrict); | | 86 | size_t * __restrict); |
87 | void _citrus_bcs_trunc_rws_len(const char * __restrict, size_t * __restrict); | | 87 | void _citrus_bcs_trunc_rws_len(const char * __restrict, size_t * __restrict); |
88 | void _citrus_bcs_convert_to_lower(char *); | | 88 | void _citrus_bcs_convert_to_lower(char *); |
89 | void _citrus_bcs_convert_to_upper(char *); | | 89 | void _citrus_bcs_convert_to_upper(char *); |
| | | 90 | |
| | | 91 | long int _citrus_bcs_strtol( |
| | | 92 | const char * __restrict, char ** __restrict, int); |
| | | 93 | unsigned 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 |
--- 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 | |
216 | static int | | 216 | static int |
217 | find_dst(struct parse_arg *pasrc, const char *dst) | | 217 | find_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); |
--- 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 | | | | |
112 | static int _getdewey(int [], char *); | | | |
113 | static int _cmpndewey(int [], int, int [], int); | | | |
114 | static const char *_findshlib(char *, int *, int *); | | | |
115 | | | | |
116 | static 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 | | | | |
123 | static 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 | */ | | | |
151 | static 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 | | | | |
179 | static 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 | | | | |
274 | void * | | | |
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 | | | | |
291 | int | | | |
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 | | | | |
326 | void | | | |
327 | _citrus_unload_module(_citrus_module_t handle) | | | |
328 | { | | | |
329 | if (handle) | | | |
330 | dlclose((void *)handle); | | | |
331 | } | | | |
332 | #else | | | |
333 | /* !_I18N_DYNAMIC */ | | | |
334 | | | | |
335 | void * | | | |
336 | /*ARGSUSED*/ | | | |
337 | _citrus_find_getops(_citrus_module_t handle, const char *modname, | | | |
338 | const char *ifname) | | | |
339 | { | | | |
340 | return (NULL); | | | |
341 | } | | | |
342 | | | | |
343 | int | | | |
344 | /*ARGSUSED*/ | | | |
345 | _citrus_load_module(_citrus_module_t *rhandle, char const *modname) | | | |
346 | { | | | |
347 | return (EINVAL); | | | |
348 | } | | | |
349 | | | | |
350 | void | | | |
351 | /*ARGSUSED*/ | | | |
352 | _citrus_unload_module(_citrus_module_t handle) | | | |
353 | { | | | |
354 | } | | | |
355 | #endif | | | |
--- 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 |
--- 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 | | | | |
88 | typedef struct { | | | |
89 | char ch[3]; | | | |
90 | int chlen; | | | |
91 | } _EUCState; | | | |
92 | | | | |
93 | typedef struct { | | | |
94 | unsigned count[4]; | | | |
95 | wchar_t bits[4]; | | | |
96 | wchar_t mask; | | | |
97 | unsigned mb_cur_max; | | | |
98 | } _EUCEncodingInfo; | | | |
99 | | | | |
100 | typedef 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 | | | | |
130 | static __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 | | | | |
138 | static __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 | | | | |
180 | static __inline void | | | |
181 | /*ARGSUSED*/ | | | |
182 | _citrus_EUC_init_state(_EUCEncodingInfo *ei, _EUCState *s) | | | |
183 | { | | | |
184 | memset(s, 0, sizeof(*s)); | | | |
185 | } | | | |
186 | | | | |
187 | static __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 | | | | |
194 | static __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 | | | | |
202 | static 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 | | | | |
287 | encoding_error: | | | |
288 | psenc->chlen = 0; | | | |
289 | *nresult = (size_t)-1; | | | |
290 | return (EILSEQ); | | | |
291 | | | | |
292 | restart: | | | |
293 | *nresult = (size_t)-2; | | | |
294 | *s = s0; | | | |
295 | return (0); | | | |
296 | } | | | |
297 | | | | |
298 | static 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 | | | | |
345 | err: | | | |
346 | *nresult = (size_t)-1; | | | |
347 | return ret; | | | |
348 | } | | | |
349 | | | | |
350 | static __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 | | | | |
369 | static __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 | | | | |
386 | static __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 | | | | |
401 | static 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 | | | | |
412 | static 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" | | | |
--- 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 | | | | |
7 | SRCS+= _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. | | | |
37 | SRCS+= _err.c _errx.c \ | | | |
38 | _sysconf.c _verr.c _verrx.c _vwarn.c _vwarnx.c _warn.c _warnx.c | | | |
39 | | | | |
40 | # uses alloca | | | |
41 | COPTS.execvp.c = -Wno-stack-protector | | | |
42 | COPTS.execl.c = -Wno-stack-protector | | | |
43 | COPTS.execle.c = -Wno-stack-protector | | | |
44 | COPTS.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 | | | | |
53 | MAN+= 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 | | | | |
78 | MLINKS+=bswap.3 bswap16.3 bswap.3 bswap32.3 bswap.3 bswap64.3 | | | |
79 | MLINKS+=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 | | | |
82 | MLINKS+=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 | | | |
85 | MLINKS+=endutxent.3 getutxent.3 endutxent.3 getutxid.3 \ | | | |
86 | endutxent.3 getutxline.3 endutxent.3 pututxline.3 \ | | | |
87 | endutxent.3 setutxent.3 | | | |
88 | MLINKS+=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 | | | |
90 | MLINKS+=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 | | | |
92 | MLINKS+=extattr.3 extattr_namespace_to_string.3 \ | | | |
93 | extattr.3 extattr_string_to_namespace.3 | | | |
94 | MLINKS+=fpgetmask.3 fpgetround.3 fpgetmask.3 fpgetsticky.3 \ | | | |
95 | fpgetmask.3 fpsetmask.3 fpgetmask.3 fpsetround.3 \ | | | |
96 | fpgetmask.3 fpsetsticky.3 | | | |
97 | MLINKS+=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 | | | |
99 | MLINKS+=ftw.3 nftw.3 | | | |
100 | MLINKS+=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 | | | |
104 | MLINKS+=getcwd.3 getwd.3 | | | |
105 | MLINKS+=getdiskbyname.3 setdisktab.3 | | | |
106 | MLINKS+=getdomainname.3 setdomainname.3 | | | |
107 | MLINKS+=getfsent.3 endfsent.3 getfsent.3 getfsfile.3 getfsent.3 getfsspec.3 \ | | | |
108 | getfsent.3 setfsent.3 | | | |
109 | MLINKS+=getgrent.3 endgrent.3 getgrent.3 setgroupent.3 getgrent.3 getgrgid.3 \ | | | |
110 | getgrent.3 getgrnam.3 getgrent.3 setgrent.3 | | | |
111 | MLINKS+=getgrent.3 getgrgid_r.3 getgrent.3 getgrnam_r.3 getgrent.3 getgrent_r.3 | | | |
112 | MLINKS+=getgrouplist.3 getgroupmembership.3 | | | |
113 | MLINKS+=gethostname.3 sethostname.3 | | | |
114 | MLINKS+=getlastlogx.3 getutmp.3 getlastlogx.3 getutmpx.3 | | | |
115 | MLINKS+=getlastlogx.3 updlastlogx.3 getlastlogx.3 updwtmpx.3 | | | |
116 | MLINKS+=getlastlogx.3 utmpxname.3 | | | |
117 | MLINKS+=getnetgrent.3 endnetgrent.3 getnetgrent.3 innetgr.3 \ | | | |
118 | getnetgrent.3 setnetgrent.3 | | | |
119 | MLINKS+=getprogname.3 setprogname.3 | | | |
120 | MLINKS+=getpwent.3 endpwent.3 getpwent.3 setpassent.3 getpwent.3 getpwnam.3 \ | | | |
121 | getpwent.3 getpwuid.3 getpwent.3 setpwent.3 | | | |
122 | MLINKS+=getpwent.3 getpwnam_r.3 getpwent.3 getpwuid_r.3 getpwent.3 getpwent_r.3 | | | |
123 | # getpwent.3 setpwfile.3 - deprecated | | | |
124 | MLINKS+=getttyent.3 endttyent.3 getttyent.3 getttynam.3 \ | | | |
125 | getttyent.3 setttyent.3 getttyent.3 setttyentpath.3 | | | |
126 | MLINKS+=getusershell.3 endusershell.3 getusershell.3 setusershell.3 | | | |
127 | MLINKS+=glob.3 globfree.3 | | | |
128 | MLINKS+=humanize_number.3 dehumanize_number.3 | | | |
129 | MLINKS+=makecontext.3 swapcontext.3 | | | |
130 | MLINKS+=popen.3 pclose.3 | | | |
131 | MLINKS+=psignal.3 sys_siglist.3 psignal.3 sys_signame.3 | | | |
132 | MLINKS+=pwcache.3 user_from_uid.3 pwcache.3 group_from_gid.3 | | | |
133 | MLINKS+=pwcache.3 uid_from_user.3 pwcache.3 gid_from_group.3 | | | |
134 | MLINKS+=pwcache.3 pwcache_userdb.3 pwcache.3 pwcache_groupdb.3 | | | |
135 | MLINKS+=randomid.3 randomid_new.3 randomid.3 randomid_delete.3 | | | |
136 | MLINKS+=scandir.3 alphasort.3 | | | |
137 | MLINKS+=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 | | | |
139 | MLINKS+=setmode.3 getmode.3 | | | |
140 | MLINKS+=shquote.3 shquotev.3 | | | |
141 | MLINKS+=sigsetops.3 sigemptyset.3 sigsetops.3 sigfillset.3 \ | | | |
142 | sigsetops.3 sigaddset.3 sigsetops.3 sigdelset.3 \ | | | |
143 | sigsetops.3 sigismember.3 | | | |
144 | MLINKS+=stringlist.3 sl_init.3 stringlist.3 sl_free.3 stringlist.3 sl_add.3 \ | | | |
145 | stringlist.3 sl_find.3 | | | |
146 | MLINKS+=sysctl.3 sysctlbyname.3 sysctl.3 sysctlgetmibinfo.3 \ | | | |
147 | sysctl.3 sysctlnametomib.3 | | | |
148 | MLINKS+=syslog.3 closelog.3 syslog.3 openlog.3 syslog.3 setlogmask.3 \ | | | |
149 | syslog.3 vsyslog.3 | | | |
150 | MLINKS+=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 | | | |
152 | MLINKS+=ttyname.3 isatty.3 ttyname.3 ttyslot.3 ttyname.3 ttyname_r.3 | | | |
153 | MLINKS+=unvis.3 strunvis.3 unvis.3 strunvisx.3 | | | |
154 | MLINKS+=vis.3 svis.3 vis.3 strvis.3 vis.3 strvisx.3 vis.3 strsvis.3 \ | | | |
155 | vis.3 strsvisx.3 | | | |
--- 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 |
66 | The | | 69 | The |
67 | .Fn opendir | | 70 | .Fn opendir |
68 | function | | 71 | function opens the directory named by |
69 | opens the directory named by | | 72 | .Fa filename |
70 | .Fa filename , | | 73 | and associates a |
71 | associates a | | | |
72 | .Em directory stream | | 74 | .Em directory stream |
73 | with it | | 75 | with it. |
74 | and | | 76 | .Pp |
75 | returns a pointer to be used to identify the | | 77 | The |
| | | 78 | .Fn fdopendir |
| | | 79 | function associates a |
| | | 80 | .Em directory stream |
| | | 81 | with the directory file descriptor |
| | | 82 | .Fa fd . |
| | | 83 | The file descriptor |
| | | 84 | .Fa fd |
| | | 85 | must not be used further by the caller in any way. |
| | | 86 | .Pp |
| | | 87 | Both functions return a pointer to be used to identify the |
76 | .Em directory stream | | 88 | .Em directory stream |
77 | in subsequent operations. | | 89 | in subsequent operations. |
78 | The pointer | | 90 | The pointer |
79 | .Dv NULL | | 91 | .Dv NULL |
80 | is returned if | | 92 | is returned if |
81 | .Fa filename | | 93 | .Fa filename |
82 | cannot be accessed, or if it cannot | | 94 | cannot be accessed, or if it cannot |
83 | .Xr malloc 3 | | 95 | .Xr malloc 3 |
84 | enough memory to hold the whole thing. | | 96 | enough memory to hold the whole thing. |
85 | .Pp | | 97 | .Pp |
86 | The | | 98 | The |
87 | .Fn readdir | | 99 | .Fn readdir |
88 | function | | 100 | function |
| @@ -90,27 +102,28 @@ returns a pointer to the next directory | | | @@ -90,27 +102,28 @@ returns a pointer to the next directory |
90 | It returns | | 102 | It returns |
91 | .Dv NULL | | 103 | .Dv NULL |
92 | upon reaching the end of the directory or detecting an invalid | | 104 | upon reaching the end of the directory or detecting an invalid |
93 | .Fn seekdir | | 105 | .Fn seekdir |
94 | operation. | | 106 | operation. |
95 | .Pp | | 107 | .Pp |
96 | The | | 108 | The |
97 | .Fn readdir_r | | 109 | .Fn readdir_r |
98 | function | | 110 | function |
99 | provides the same functionality as | | 111 | provides the same functionality as |
100 | .Fn readdir , | | 112 | .Fn readdir , |
101 | but the caller must provide a directory | | 113 | but the caller must provide a directory |
102 | .Fa entry | | 114 | .Fa entry |
103 | buffer to store the results in. If the read succeeds, | | 115 | buffer to store the results in. |
| | | 116 | If the read succeeds, |
104 | .Fa result | | 117 | .Fa result |
105 | is pointed at the | | 118 | is pointed at the |
106 | .Fa entry ; | | 119 | .Fa entry ; |
107 | upon reaching the end of the directory | | 120 | upon reaching the end of the directory |
108 | .Fa result | | 121 | .Fa result |
109 | is set to | | 122 | is set to |
110 | .Dv NULL . | | 123 | .Dv NULL . |
111 | The | | 124 | The |
112 | .Fn readdir_r | | 125 | .Fn readdir_r |
113 | function | | 126 | function |
114 | returns 0 on success or an error number to indicate failure. | | 127 | returns 0 on success or an error number to indicate failure. |
115 | .Pp | | 128 | .Pp |
116 | The | | 129 | The |
--- 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 | | | |
39 | static 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 | | | | |
62 | static FTSENT *fts_alloc(FTS *, const char *, size_t); | | | |
63 | static FTSENT *fts_build(FTS *, int); | | | |
64 | static void fts_free(FTSENT *); | | | |
65 | static void fts_lfree(FTSENT *); | | | |
66 | static void fts_load(FTS *, FTSENT *); | | | |
67 | static size_t fts_maxarglen(char * const *); | | | |
68 | static size_t fts_pow2(size_t); | | | |
69 | static int fts_palloc(FTS *, size_t); | | | |
70 | static void fts_padjust(FTS *, FTSENT *); | | | |
71 | static FTSENT *fts_sort(FTS *, FTSENT *, size_t); | | | |
72 | static unsigned short fts_stat(FTS *, FTSENT *, int); | | | |
73 | static 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 | | | | |
100 | FTS * | | | |
101 | fts_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 | | | | |
211 | mem3: fts_lfree(root); | | | |
212 | fts_free(parent); | | | |
213 | mem2: free(sp->fts_path); | | | |
214 | mem1: free(sp); | | | |
215 | return (NULL); | | | |
216 | } | | | |
217 | | | | |
218 | static void | | | |
219 | fts_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 | | | | |
245 | int | | | |
246 | fts_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 | | | | |
318 | FTSENT * | | | |
319 | fts_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. */ | | | |
421 | next: 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 | | | | |
462 | name: 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 */ | | | |
520 | int | | | |
521 | fts_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 | | | | |
536 | FTSENT * | | | |
537 | fts_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 | */ | | | |
620 | static FTSENT * | | | |
621 | fts_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 | */ | | | |
753 | mem1: 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 | | | | |
890 | static unsigned short | | | |
891 | fts_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; | | | |
933 | err: 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 | | | | |
973 | static FTSENT * | | | |
974 | fts_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 | | | | |
1007 | static FTSENT * | | | |
1008 | fts_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 | | | | |
1060 | static void | | | |
1061 | fts_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 | | | | |
1070 | static void | | | |
1071 | fts_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 | | | | |
1084 | static size_t | | | |
1085 | fts_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 | */ | | | |
1110 | static int | | | |
1111 | fts_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 | */ | | | |
1137 | static void | | | |
1138 | fts_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 | | | | |
1165 | static size_t | | | |
1166 | fts_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 | */ | | | |
1183 | static int | | | |
1184 | fts_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 | | | | |
1205 | bail: | | | |
1206 | if (oldfd < 0) { | | | |
1207 | int save_errno = errno; | | | |
1208 | (void)close(fd); | | | |
1209 | errno = save_errno; | | | |
1210 | } | | | |
1211 | return ret; | | | |
1212 | } | | | |
--- 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 $"); |
40 | static 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" |
50 | int | | | |
51 | isalnum(c) | | | |
52 | int c; | | | |
53 | { | | | |
54 | return((_ctype_ + 1)[c] & (_U|_L|_N)); | | | |
55 | } | | | |
56 | | | | |
57 | #undef isalpha | | | |
58 | int | | | |
59 | isalpha(c) | | | |
60 | int c; | | | |
61 | { | | | |
62 | return((_ctype_ + 1)[c] & (_U|_L)); | | | |
63 | } | | | |
64 | | | 46 | |
65 | #undef isblank | | 47 | #define _CTYPE_TAB(table, i) \ |
66 | int | | 48 | (((*_current_locale())->cache.table + 1)[i]) |
67 | isblank(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 |
74 | int | | | |
75 | iscntrl(c) | | | |
76 | int c; | | | |
77 | { | | | |
78 | return((_ctype_ + 1)[c] & _C); | | | |
79 | } | | | |
80 | | | | |
81 | #undef isdigit | | 53 | #undef isdigit |
82 | int | | | |
83 | isdigit(c) | | | |
84 | int c; | | | |
85 | { | | | |
86 | return((_ctype_ + 1)[c] & _N); | | | |
87 | } | | | |
88 | | | | |
89 | #undef isgraph | | 54 | #undef isgraph |
90 | int | | | |
91 | isgraph(c) | | | |
92 | int c; | | | |
93 | { | | | |
94 | return((_ctype_ + 1)[c] & (_P|_U|_L|_N)); | | | |
95 | } | | | |
96 | | | | |
97 | #undef islower | | 55 | #undef islower |
98 | int | | | |
99 | islower(c) | | | |
100 | int c; | | | |
101 | { | | | |
102 | return((_ctype_ + 1)[c] & _L); | | | |
103 | } | | | |
104 | | | | |
105 | #undef isprint | | 56 | #undef isprint |
106 | int | | | |
107 | isprint(c) | | | |
108 | int c; | | | |
109 | { | | | |
110 | return((_ctype_ + 1)[c] & (_P|_U|_L|_N|_B)); | | | |
111 | } | | | |
112 | | | | |
113 | #undef ispunct | | 57 | #undef ispunct |
114 | int | | | |
115 | ispunct(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) \ |
| | | 63 | int \ |
| | | 64 | is##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 |
122 | int | | 82 | int |
123 | isspace(c) | | 83 | isblank(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 |
130 | int | | 90 | int |
131 | isupper(c) | | 91 | toupper(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 |
138 | int | | 97 | int |
139 | isxdigit(c) | | 98 | tolower(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 |
146 | int | | 104 | int |
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 |
154 | int | | 111 | int |
155 | _tolower(c) | | 112 | _tolower(int c) |
156 | int c; | | | |
157 | { | | 113 | { |
158 | return (c - 'A' + 'a'); | | 114 | return (c - 'A' + 'a'); |
159 | } | | 115 | } |
--- 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 |
35 | static char sccsid[] = "@(#)opendir.c 8.7 (Berkeley) 12/10/94"; | | 35 | static 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 | |
| | | 61 | static 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 | */ |
63 | DIR * | | 68 | DIR * |
64 | opendir(const char *name) | | 69 | opendir(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 | |
72 | DIR * | | 77 | DIR * |
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__ |
| | | 88 | DIR * |
| | | 89 | _fdopendir(int fd) |
| | | 90 | { |
| | | 91 | |
| | | 92 | return __opendir_common(fd, NULL, DTF_HIDEW|DTF_NODUP); |
| | | 93 | } |
| | | 94 | #endif |
| | | 95 | |
| | | 96 | static 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 |
--- 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 |
48 | The | | 48 | The |
| | | 49 | .Fn setmode |
| | | 50 | function accepts a string representation of a file mode change, |
| | | 51 | compiles it to binary form, and returns an abstract representation |
| | | 52 | that may be passed to |
| | | 53 | .Fn getmode . |
| | | 54 | The string may be an numeric (octal) or symbolic string of the form |
| | | 55 | accepted by |
| | | 56 | .Xr chmod 1 , |
| | | 57 | and may represent either an exact mode to set or a change to make to |
| | | 58 | the existing mode. |
| | | 59 | .Pp |
| | | 60 | The |
49 | .Fn getmode | | 61 | .Fn getmode |
50 | function | | 62 | function |
51 | returns a copy of the file permission bits | | 63 | adjusts the file permission bits given by |
52 | .Fa mode | | 64 | .Fa mode |
53 | as altered by the values pointed to by | | 65 | according to the compiled change representation |
54 | .Fa set . | | 66 | .Fa set , |
55 | While only the mode bits are altered, other parts of the file mode | | 67 | and returns the adjusted mode. |
56 | may be examined. | | 68 | While only the permission bits are altered, other parts of the file |
| | | 69 | mode, particularly the type, may be examined. |
57 | .Pp | | 70 | .Pp |
58 | The | | 71 | Because some of the possible symbolic values are defined relative to |
59 | .Fn setmode | | 72 | the file creation mask, |
60 | function | | | |
61 | takes an absolute (octal) or symbolic value, as described in | | | |
62 | .Xr chmod 1 , | | | |
63 | as an argument | | | |
64 | and returns a pointer to mode values to be supplied to | | | |
65 | .Fn getmode . | | | |
66 | Because some of the symbolic values are relative to the file | | | |
67 | creation mask, | | | |
68 | .Fn setmode | | 73 | .Fn setmode |
69 | may call | | 74 | may call |
70 | .Xr umask 2 . | | 75 | .Xr umask 2 , |
| | | 76 | temporarily changing the mask. |
71 | If this occurs, the file creation mask will be restored before | | 77 | If this occurs, the file creation mask will be restored before |
72 | .Fn setmode | | 78 | .Fn setmode |
73 | returns. | | 79 | returns. |
74 | If the calling program changes the value of its file creation mask | | 80 | If the calling program changes the value of its file creation mask |
75 | after calling | | 81 | after calling |
76 | .Fn setmode , | | 82 | .Fn setmode , |
77 | .Fn setmode | | 83 | .Fn setmode |
78 | must be called again if | | 84 | must be called again to recompile the mode string if |
79 | .Fn getmode | | 85 | .Fn getmode |
80 | is to modify future file modes correctly. | | 86 | is to modify future file modes correctly. |
81 | .Pp | | 87 | .Pp |
82 | If the mode passed to | | 88 | If the mode passed to |
83 | .Fn setmode | | 89 | .Fn setmode |
84 | is invalid, | | 90 | is invalid, |
85 | .Fn setmode | | 91 | .Fn setmode |
86 | returns | | 92 | returns |
87 | .Dv NULL . | | 93 | .Dv NULL . |
| | | 94 | .Sh EXAMPLES |
| | | 95 | The effects of the shell command |
| | | 96 | .Ql "chmod a+x myscript.sh" |
| | | 97 | can be duplicated as follows: |
| | | 98 | .Bd -literal -offset indent |
| | | 99 | const char *file = "myscript.sh"; |
| | | 100 | struct stat st; |
| | | 101 | mode_t newmode; |
| | | 102 | |
| | | 103 | stat(file, \*[Am]st); |
| | | 104 | newmode = getmode(setmode("a+x"), st.st_mode); |
| | | 105 | chmod(file, newmode); |
| | | 106 | .Ed |
88 | .Sh ERRORS | | 107 | .Sh ERRORS |
89 | The | | 108 | The |
90 | .Fn setmode | | 109 | .Fn setmode |
91 | function | | 110 | function |
92 | may fail and set | | 111 | may fail and set |
93 | .Va errno | | 112 | .Va errno |
94 | for any of the errors specified for the library routines | | 113 | for any of the errors specified for the library routines |
95 | .Xr malloc 3 | | 114 | .Xr malloc 3 |
96 | or | | 115 | or |
97 | .Xr strtol 3 . | | 116 | .Xr strtol 3 . |
98 | In addition, | | 117 | In addition, |
99 | .Fn setmode | | 118 | .Fn setmode |
100 | will fail and set | | 119 | will 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 |
115 | The | | 134 | The |
116 | .Fn getmode | | 135 | .Fn getmode |
117 | and | | 136 | and |
118 | .Fn setmode | | 137 | .Fn setmode |
119 | functions first appeared in | | 138 | functions first appeared in |
120 | .Bx 4.4 . | | 139 | .Bx 4.4 . |
| | | 140 | .Sh BUGS |
| | | 141 | Each call to |
| | | 142 | .Nm setmode |
| | | 143 | allocates a small amount of memory that there is no correct way to |
| | | 144 | free. |
| | | 145 | .Pp |
| | | 146 | The type of |
| | | 147 | .Fa set |
| | | 148 | should really be some opaque struct type used only by these functions |
| | | 149 | rather than |
| | | 150 | .Ft void * . |
--- 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 | | | |
58 | The | | | |
59 | .Nm | | | |
60 | function retrieves system information and allows processes with | | | |
61 | appropriate privileges to set system information. | | | |
62 | The information available from | | | |
63 | .Nm | | | |
64 | consists of integers, strings, and tables. | | | |
65 | Information may be retrieved and set from the command interface | | | |
66 | using the | | | |
67 | .Xr sysctl 8 | | | |
68 | utility. | | | |
69 | .Pp | | | |
70 | Unless explicitly noted below, | | | |
71 | .Nm | | | |
72 | returns a consistent snapshot of the data requested. | | | |
73 | Consistency is obtained by locking the destination | | | |
74 | buffer into memory so that the data may be copied out without blocking. | | | |
75 | Calls to | | | |
76 | .Nm | | | |
77 | are serialized to avoid deadlock. | | | |
78 | .Pp | | | |
79 | The state is described using a ``Management Information Base'' (MIB) | | | |
80 | style name, listed in | | | |
81 | .Fa name , | | | |
82 | which is a | | | |
83 | .Fa namelen | | | |
84 | length array of integers. | | | |
85 | .Pp | | | |
86 | The | | | |
87 | .Fn sysctlbyname | | | |
88 | function accepts a string representation of a MIB entry and internally | | | |
89 | maps it to the appropriate numeric MIB representation. | | | |
90 | Its semantics are otherwise no different from | | | |
91 | .Fn sysctl . | | | |
92 | .Pp | | | |
93 | The information is copied into the buffer specified by | | | |
94 | .Fa oldp . | | | |
95 | The size of the buffer is given by the location specified by | | | |
96 | .Fa oldlenp | | | |
97 | before the call, | | | |
98 | and that location gives the amount of data copied after a successful call. | | | |
99 | If the amount of data available is greater | | | |
100 | than the size of the buffer supplied, | | | |
101 | the call supplies as much data as fits in the buffer provided | | | |
102 | and returns with the error code ENOMEM. | | | |
103 | If the old value is not desired, | | | |
104 | .Fa oldp | | | |
105 | and | | | |
106 | .Fa oldlenp | | | |
107 | should be set to | | | |
108 | .Dv NULL . | | | |
109 | .Pp | | | |
110 | The size of the available data can be determined by calling | | | |
111 | .Nm | | | |
112 | with a | | | |
113 | .Dv NULL | | | |
114 | parameter for | | | |
115 | .Fa oldp . | | | |
116 | The size of the available data will be returned in the location pointed to by | | | |
117 | .Fa oldlenp . | | | |
118 | For some operations, the amount of space may change often. | | | |
119 | For these operations, | | | |
120 | the system attempts to round up so that the returned size is | | | |
121 | large enough for a call to return the data shortly thereafter. | | | |
122 | .Pp | | | |
123 | To set a new value, | | | |
124 | .Fa newp | | | |
125 | is set to point to a buffer of length | | | |
126 | .Fa newlen | | | |
127 | from which the requested value is to be taken. | | | |
128 | If a new value is not to be set, | | | |
129 | .Fa newp | | | |
130 | should be set to | | | |
131 | .Dv NULL | | | |
132 | and | | | |
133 | .Fa newlen | | | |
134 | set to 0. | | | |
135 | .Pp | | | |
136 | The | | | |
137 | .Fn sysctlnametomib | | | |
138 | function can be used to map the string representation of a MIB entry | | | |
139 | to the numeric version. | | | |
140 | The | | | |
141 | .Fa name | | | |
142 | argument should point to an array of integers large enough to hold the | | | |
143 | MIB, and | | | |
144 | .Fa namelenp | | | |
145 | should indicate the number of integer slots available. | | | |
146 | Following a successful translation, the size_t indicated by | | | |
147 | .Fa namelenp | | | |
148 | will be changed to show the number of slots consumed. | | | |
149 | .Pp | | | |
150 | The | | | |
151 | .Fn sysctlgetmibinfo | | | |
152 | function performs name translation similar to | | | |
153 | .Fn sysctlnametomib , | | | |
154 | but also canonicalizes the name (or returns the first erroneous token | | | |
155 | from the string being parsed) into the space indicated by | | | |
156 | .Fa cname | | | |
157 | and | | | |
158 | .Fa csz . | | | |
159 | .Fa csz | | | |
160 | should indicate the size of the buffer pointed to by | | | |
161 | .Fa cname | | | |
162 | and on return, will indicate the size of the returned string including | | | |
163 | the trailing | | | |
164 | .Sq nul | | | |
165 | character. | | | |
166 | .Pp | | | |
167 | The | | | |
168 | .Fa rnode | | | |
169 | and | | | |
170 | .Fa v | | | |
171 | arguments to | | | |
172 | .Fn sysctlgetmibinfo | | | |
173 | are used to provide a tree for it to parse into, and to get back | | | |
174 | either a pointer to, or a copy of, the terminal node. | | | |
175 | If | | | |
176 | .Fa rnode | | | |
177 | is | | | |
178 | .Dv NULL , | | | |
179 | .Fn sysctlgetmibinfo | | | |
180 | uses its own internal tree for parsing, and checks it against the | | | |
181 | kernel at each call, to make sure that the name-to-number mapping is | | | |
182 | kept up to date. | | | |
183 | The | | | |
184 | .Fa v | | | |
185 | argument is ignored in this case. | | | |
186 | If | | | |
187 | .Fa rnode | | | |
188 | is not | | | |
189 | .Dv NULL | | | |
190 | but the pointer it references is, on a successful return, | | | |
191 | .Fa rnode | | | |
192 | will be adjusted to point to a copy of the terminal node. | | | |
193 | The | | | |
194 | .Fa v | | | |
195 | argument indicates which version of the | | | |
196 | .Nm | | | |
197 | node structure the caller wants. | | | |
198 | The application must later | | | |
199 | .Fn free | | | |
200 | this copy. | | | |
201 | If neither | | | |
202 | .Fa rnode | | | |
203 | nor the pointer it references are | | | |
204 | .Dv NULL , | | | |
205 | the pointer is used as the address of a tree over which the parsing is | | | |
206 | done. | | | |
207 | In this last case, the tree is not checked against the kernel, no | | | |
208 | refreshing of the mappings is performed, and the value given by | | | |
209 | .Fa v | | | |
210 | must agree with the version indicated by the tree. | | | |
211 | It is recommended that applications always use | | | |
212 | .Dv SYSCTL_VERSION | | | |
213 | as the value for | | | |
214 | .Fa v , | | | |
215 | as defined in the include file | | | |
216 | .Pa sys/sysctl.h . | | | |
217 | .Pp | | | |
218 | The numeric and text names of sysctl variables are described in | | | |
219 | .Xr sysctl 7 . | | | |
220 | The numeric names are defined as preprocessor macros. | | | |
221 | The top level names are defined with a CTL_ prefix in | | | |
222 | .Aq Pa sys/sysctl.h . | | | |
223 | The next and subsequent levels down have different prefixes for each | | | |
224 | subtree. | | | |
225 | .Pp | | | |
226 | For example, the following retrieves the maximum number of processes allowed | | | |
227 | in the system - the | | | |
228 | .Li kern.maxproc | | | |
229 | variable: | | | |
230 | .Bd -literal -offset indent -compact | | | |
231 | int mib[2], maxproc; | | | |
232 | size_t len; | | | |
233 | .sp | | | |
234 | mib[0] = CTL_KERN; | | | |
235 | mib[1] = KERN_MAXPROC; | | | |
236 | len = sizeof(maxproc); | | | |
237 | sysctl(mib, 2, \*[Am]maxproc, \*[Am]len, NULL, 0); | | | |
238 | .Ed | | | |
239 | .sp | | | |
240 | To retrieve the standard search path for the system utilities - | | | |
241 | .Li user.cs_path : | | | |
242 | .Bd -literal -offset indent -compact | | | |
243 | int mib[2]; | | | |
244 | size_t len; | | | |
245 | char *p; | | | |
246 | .sp | | | |
247 | mib[0] = CTL_USER; | | | |
248 | mib[1] = USER_CS_PATH; | | | |
249 | sysctl(mib, 2, NULL, \*[Am]len, NULL, 0); | | | |
250 | p = malloc(len); | | | |
251 | sysctl(mib, 2, p, \*[Am]len, NULL, 0); | | | |
252 | .Ed | | | |
253 | .Sh DYNAMIC OPERATIONS | | | |
254 | Several meta-identifiers are provided to perform operations on the | | | |
255 | .Nm | | | |
256 | tree itself, or support alternate means of accessing the data | | | |
257 | instrumented by the | | | |
258 | .Nm | | | |
259 | tree. | | | |
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 | | | |
269 | The core interface to all of these meta-functions is the structure | | | |
270 | that the kernel uses to describe the tree internally, as defined in | | | |
271 | .Aq Pa sys/sysctl.h | | | |
272 | as: | | | |
273 | .Pp | | | |
274 | .Bd -literal | | | |
275 | struct 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 | | | |
311 | Querying the tree to discover the name to number mapping permits | | | |
312 | dynamic discovery of all the data that the tree currently has | | | |
313 | instrumented. | | | |
314 | For example, to discover all the nodes below the | | | |
315 | CTL_VFS node: | | | |
316 | .Pp | | | |
317 | .Bd -literal -offset indent -compact | | | |
318 | struct sysctlnode query, vfs[128]; | | | |
319 | int mib[2]; | | | |
320 | size_t len; | | | |
321 | .sp | | | |
322 | mib[0] = CTL_VFS; | | | |
323 | mib[1] = CTL_QUERY; | | | |
324 | memset(\*[Am]query, 0, sizeof(query)); | | | |
325 | query.sysctl_flags = SYSCTL_VERSION; | | | |
326 | len = sizeof(vfs); | | | |
327 | sysctl(mib, 2, \*[Am]vfs[0], \*[Am]len, \*[Am]query, sizeof(query)); | | | |
328 | .Ed | | | |
329 | .Pp | | | |
330 | Note that a reference to an empty node with | | | |
331 | .Fa sysctl_flags | | | |
332 | set to | | | |
333 | .Dv SYSCTL_VERSION | | | |
334 | is passed to sysctl in order to indicate the version that the program | | | |
335 | is using. | | | |
336 | All dynamic operations passing nodes into sysctl require that the | | | |
337 | version be explicitly specified. | | | |
338 | .Pp | | | |
339 | Creation and destruction of nodes works by constructing part of a new | | | |
340 | node description (or a description of the existing node) and invoking | | | |
341 | CTL_CREATE (or CTL_CREATESYM) or CTL_DESTROY at the parent of the new | | | |
342 | node, with a pointer to the new node passed via the | | | |
343 | .Fa new | | | |
344 | and | | | |
345 | .Fa newlen | | | |
346 | arguments. | | | |
347 | If valid values for | | | |
348 | .Fa old | | | |
349 | and | | | |
350 | .Fa oldlenp | | | |
351 | are passed, a copy of the new node once in the tree will be returned. | | | |
352 | If the create operation fails because a node with the same name or MIB | | | |
353 | number exists, a copy of the conflicting node will be returned. | | | |
354 | .Pp | | | |
355 | The minimum requirements for creating a node are setting the | | | |
356 | .Fa sysctl_flags | | | |
357 | to indicate the new node's type, | | | |
358 | .Fa sysctl_num | | | |
359 | to either the new node's number (or CTL_CREATE or CTL_CREATESYM if a | | | |
360 | dynamically allocated MIB number is acceptable), | | | |
361 | .Fa sysctl_size | | | |
362 | to the size of the data to be instrumented (which must agree with the | | | |
363 | given type), and | | | |
364 | .Fa sysctl_name | | | |
365 | must be set to the new node's name. | | | |
366 | Nodes that are not of type | | | |
367 | .Dq node | | | |
368 | must also have some description of the data to be instrumented, which | | | |
369 | will vary depending on what is to be instrumented. | | | |
370 | .Pp | | | |
371 | If existing kernel data is to be covered by this new node, its address | | | |
372 | should be given in | | | |
373 | .Fa sysctl_data | | | |
374 | or, if CTL_CREATESYM is used, | | | |
375 | .Fa sysctl_data | | | |
376 | should be set to a string containing its name from the kernel's symbol | | | |
377 | table. | | | |
378 | If new data is to be instrumented and an initial value is available, | | | |
379 | the new integer or quad type data should be placed into either | | | |
380 | .Fa sysctl_idata | | | |
381 | or | | | |
382 | .Fa sysctl_qdata , | | | |
383 | respectively, along with the SYSCTL_IMMEDIATE flag being set, or | | | |
384 | .Fa sysctl_data | | | |
385 | should be set to point to a copy of the new data, and the | | | |
386 | SYSCTL_OWNDATA flag must be set. | | | |
387 | This latter method is the only way that new string and struct type | | | |
388 | nodes can be initialized. | | | |
389 | Invalid kernel addresses are accepted, but any attempt to access those | | | |
390 | nodes will return an error. | | | |
391 | .Pp | | | |
392 | The | | | |
393 | .Fa sysctl_csize , | | | |
394 | .Fa sysctl_clen , | | | |
395 | .Fa sysctl_child , | | | |
396 | .Fa sysctl_parent , | | | |
397 | and | | | |
398 | .Fa sysctl_alias | | | |
399 | members are used by the kernel to link the tree together and must be | | | |
400 | .Dv NULL | | | |
401 | or 0. | | | |
402 | Nodes created in this manner cannot have helper functions, so | | | |
403 | .Fa sysctl_func | | | |
404 | must also be | | | |
405 | .Dv NULL . | | | |
406 | If the | | | |
407 | .Fa sysctl_ver | | | |
408 | member is non-zero, it must match either the version of the parent or | | | |
409 | the version at the root of the MIB or an error is returned. | | | |
410 | This can be used to ensure that nodes are only added or removed from a | | | |
411 | known state of the tree. | | | |
412 | Note: It may not be possible to determine the version at the root | | | |
413 | of the tree. | | | |
414 | .Pp | | | |
415 | This example creates a new subtree and adds a node to it that controls the | | | |
416 | .Fa audiodebug | | | |
417 | kernel variable, thereby making it tunable at at any time, without | | | |
418 | needing to use | | | |
419 | .Xr ddb 4 | | | |
420 | or | | | |
421 | .Xr kvm 3 | | | |
422 | to alter the kernel's memory directly. | | | |
423 | .Pp | | | |
424 | .Bd -literal -offset indent -compact | | | |
425 | struct sysctlnode node; | | | |
426 | int mib[2]; | | | |
427 | size_t len; | | | |
428 | .sp | | | |
429 | mib[0] = CTL_CREATE; /* create at top-level */ | | | |
430 | len = sizeof(node); | | | |
431 | memset(\*[Am]node, 0, len); | | | |
432 | node.sysctl_flags = SYSCTL_VERSION|CTLFLAG_READWRITE|CTLTYPE_NODE; | | | |
433 | snprintf(node.sysctl_name, sizeof(node.sysctl_name), "local"); | | | |
434 | node.sysctl_num = CTL_CREATE; /* request dynamic MIB number */ | | | |
435 | sysctl(\*[Am]mib[0], 1, \*[Am]node, \*[Am]len, \*[Am]node, len); | | | |
436 | .sp | | | |
437 | mib[0] = node.sysctl_num; /* use new MIB number */ | | | |
438 | mib[1] = CTL_CREATESYM; /* create at second level */ | | | |
439 | len = sizeof(node); | | | |
440 | memset(\*[Am]node, 0, len); | | | |
441 | node.sysctl_flags = SYSCTL_VERSION|CTLFLAG_READWRITE|CTLTYPE_INT; | | | |
442 | snprintf(node.sysctl_name, sizeof(node.sysctl_name), "audiodebug"); | | | |
443 | node.sysctl_num = CTL_CREATE; | | | |
444 | node.sysctl_data = "audiodebug"; /* kernel symbol to be used */ | | | |
445 | sysctl(\*[Am]mib[0], 2, NULL, NULL, \*[Am]node, len); | | | |
446 | .Ed | | | |
447 | .Pp | | | |
448 | The process for deleting nodes is similar, but less data needs to | | | |
449 | be supplied. | | | |
450 | Only the | | | |
451 | .Fa sysctl_num | | | |
452 | field | | | |
453 | needs to be filled in; almost all other fields must be left blank. | | | |
454 | The | | | |
455 | .Fa sysctl_name | | | |
456 | and/or | | | |
457 | .Fa sysctl_ver | | | |
458 | fields can be filled in with the name and version of the existing node | | | |
459 | as additional checks on what will be deleted. | | | |
460 | If all the given data fail to match any node, nothing will be deleted. | | | |
461 | If valid values for | | | |
462 | .Fa old | | | |
463 | and | | | |
464 | .Fa oldlenp | | | |
465 | are supplied and a node is deleted, a copy of what was in the MIB tree | | | |
466 | will be returned. | | | |
467 | .Pp | | | |
468 | This sample code shows the deletion of the two nodes created in the | | | |
469 | above example: | | | |
470 | .Pp | | | |
471 | .Bd -literal -offset indent -compact | | | |
472 | int mib[2]; | | | |
473 | .sp | | | |
474 | len = sizeof(node); | | | |
475 | memset(\*[Am]node, 0, len); | | | |
476 | node.sysctl_flags = SYSCTL_VERSION; | | | |
477 | .sp | | | |
478 | mib[0] = 3214; /* assumed number for "local" */ | | | |
479 | mib[1] = CTL_DESTROY; | | | |
480 | node.sysctl_num = 3215; /* assumed number for "audiodebug" */ | | | |
481 | sysctl(\*[Am]mib[0], 2, NULL, NULL, \*[Am]node, len); | | | |
482 | .sp | | | |
483 | mib[0] = CTL_DESTROY; | | | |
484 | node.sysctl_num = 3214; /* now deleting "local" */ | | | |
485 | sysctl(\*[Am]mib[0], 1, NULL, NULL, \*[Am]node, len); | | | |
486 | .Ed | | | |
487 | .Pp | | | |
488 | Descriptions of each of the nodes can also be retrieved, if they are | | | |
489 | available. | | | |
490 | Descriptions can be retrieved in bulk at each level or on a per-node | | | |
491 | basis. | | | |
492 | The layout of the buffer into which the descriptions are returned is a | | | |
493 | series of variable length structures, each of which describes its own | | | |
494 | size. | | | |
495 | The length indicated includes the terminating | | | |
496 | .Sq nul | | | |
497 | character. | | | |
498 | Nodes that have no description or where the description is not | | | |
499 | available are indicated by an empty string. | | | |
500 | The | | | |
501 | .Fa descr_ver | | | |
502 | will match the | | | |
503 | .Fa sysctl_ver | | | |
504 | value for a given node, so that descriptions for nodes whose number | | | |
505 | have been recycled can be detected and ignored or discarded. | | | |
506 | .Pp | | | |
507 | .Bd -literal | | | |
508 | struct 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 | | | |
516 | The | | | |
517 | .Fn NEXT_DESCR | | | |
518 | macro can be used to skip to the next description in the retrieved | | | |
519 | list. | | | |
520 | .Pp | | | |
521 | .Bd -literal -offset indent -compact | | | |
522 | struct sysctlnode desc; | | | |
523 | struct sysctldesc *d; | | | |
524 | char buf[1024]; | | | |
525 | int mib[2]; | | | |
526 | size_t len; | | | |
527 | .sp | | | |
528 | /* retrieve kern-level descriptions */ | | | |
529 | mib[0] = CTL_KERN; | | | |
530 | mib[1] = CTL_DESCRIBE; | | | |
531 | d = (struct sysctldesc *)\*[Am]buf[0]; | | | |
532 | len = sizeof(buf); | | | |
533 | sysctl(mib, 2, d, \*[Am]len, NULL, 0); | | | |
534 | while ((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 */ | | | |
541 | memset(\*[Am]desc, 0, sizeof(desc)); | | | |
542 | desc.sysctl_flags = SYSCTL_VERSION; | | | |
543 | desc.sysctl_num = KERN_SECURELEVEL; | | | |
544 | d = (struct sysctldesc *)\*[Am]buf[0]; | | | |
545 | len = sizeof(buf); | | | |
546 | sysctl(mib, 2, d, \*[Am]len, \*[Am]desc, sizeof(desc)); | | | |
547 | printf("kern.securelevel: %.*s\\n", d-\*[Gt]descr_len, d-\*[Gt]descr_str); | | | |
548 | .Ed | | | |
549 | .Pp | | | |
550 | Descriptions can also be set as follows, subject to the following rules: | | | |
551 | .Pp | | | |
552 | .Bl -bullet -compact | | | |
553 | .It | | | |
554 | The kernel securelevel is at zero or lower | | | |
555 | .It | | | |
556 | The caller has super-user privileges | | | |
557 | .It | | | |
558 | The node does not currently have a description | | | |
559 | .It | | | |
560 | The node is not marked as | | | |
561 | .Dq permanent | | | |
562 | .El | | | |
563 | .Pp | | | |
564 | .Bd -literal -offset indent -compact | | | |
565 | struct sysctlnode desc; | | | |
566 | int mib[2]; | | | |
567 | .sp | | | |
568 | /* presuming the given top-level node was just added... */ | | | |
569 | mib[0] = 3214; /* mib numbers taken from previous examples */ | | | |
570 | mib[1] = CTL_DESCRIBE; | | | |
571 | memset(\*[Am]desc, 0, sizeof(desc)); | | | |
572 | desc.sysctl_flags = SYSCTL_VERSION; | | | |
573 | desc.sysctl_num = 3215; | | | |
574 | desc.sysctl_desc = "audio debug control knob"; | | | |
575 | sysctl(mib, 2, NULL, NULL, \*[Am]desc, sizeof(desc)); | | | |
576 | .Ed | | | |
577 | .Pp | | | |
578 | Upon successfully setting a description, the new description will be | | | |
579 | returned in the space indicated by the | | | |
580 | .Fa oldp | | | |
581 | and | | | |
582 | .Fa oldlenp | | | |
583 | arguments. | | | |
584 | .Pp | | | |
585 | The | | | |
586 | .Fa sysctl_flags | | | |
587 | field in the struct sysctlnode contains the sysctl version, node type | | | |
588 | information, and a number of flags. | | | |
589 | The macros | | | |
590 | .Fn SYSCTL_VERS , | | | |
591 | .Fn SYSCTL_TYPE , | | | |
592 | and | | | |
593 | .Fn SYSCTL_FLAGS | | | |
594 | can be used to access the different fields. | | | |
595 | Valid 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 | | | |
605 | processes) | | | |
606 | .It CTLFLAG\_OWNDATA Node owns data and does not instrument | | | |
607 | existing data | | | |
608 | .It CTLFLAG\_IMMEDIATE Node contains instrumented data and does not | | | |
609 | instrument existing data | | | |
610 | .It CTLFLAG\_HEX Node's contents should be displayed in a hexadecimal | | | |
611 | form | | | |
612 | .It CTLFLAG\_ROOT Node is the root of a tree (cannot be set at | | | |
613 | any time) | | | |
614 | .It CTLFLAG\_ANYNUMBER Node matches any MIB number (cannot be set by | | | |
615 | processes) | | | |
616 | .It CTLFLAG\_HIDDEN Node not displayed by default | | | |
617 | .It CTLFLAG\_ALIAS Node refers to a sibling node (cannot be set | | | |
618 | by processes) | | | |
619 | .It CTLFLAG\_OWNDESC Node owns its own description string space | | | |
620 | .El | | | |
621 | .Sh RETURN VALUES | | | |
622 | If the call to | | | |
623 | .Nm | | | |
624 | is successful, 0 is returned. | | | |
625 | Otherwise \-1 is returned and | | | |
626 | .Va errno | | | |
627 | is set appropriately. | | | |
628 | .Sh FILES | | | |
629 | .Bl -tag -width \*[Lt]netinet6/udp6Xvar.h\*[Gt] -compact | | | |
630 | .It Aq Pa sys/sysctl.h | | | |
631 | definitions for top level identifiers, second level kernel and hardware | | | |
632 | identifiers, and user level identifiers | | | |
633 | .It Aq Pa sys/socket.h | | | |
634 | definitions for second level network identifiers | | | |
635 | .It Aq Pa sys/gmon.h | | | |
636 | definitions for third level profiling identifiers | | | |
637 | .It Aq Pa uvm/uvm_param.h | | | |
638 | definitions for second level virtual memory identifiers | | | |
639 | .It Aq Pa netinet/in.h | | | |
640 | definitions for third level IPv4/v6 identifiers and | | | |
641 | fourth level IPv4/v6 identifiers | | | |
642 | .It Aq Pa netinet/icmp_var.h | | | |
643 | definitions for fourth level ICMP identifiers | | | |
644 | .It Aq Pa netinet/icmp6.h | | | |
645 | definitions for fourth level ICMPv6 identifiers | | | |
646 | .It Aq Pa netinet/tcp_var.h | | | |
647 | definitions for fourth level TCP identifiers | | | |
648 | .It Aq Pa netinet/udp_var.h | | | |
649 | definitions for fourth level UDP identifiers | | | |
650 | .It Aq Pa netinet6/udp6_var.h | | | |
651 | definitions for fourth level IPv6 UDP identifiers | | | |
652 | .It Aq Pa netinet6/ipsec.h | | | |
653 | definitions for fourth level IPsec identifiers | | | |
654 | .It Aq Pa netkey/key_var.h | | | |
655 | definitions for third level PF_KEY identifiers | | | |
656 | .It Aq Pa machine/cpu.h | | | |
657 | definitions for second level machdep identifiers | | | |
658 | .El | | | |
659 | .Sh ERRORS | | | |
660 | The following errors may be reported: | | | |
661 | .Bl -tag -width Er | | | |
662 | .It Bq Er EFAULT | | | |
663 | The buffer | | | |
664 | .Fa name , | | | |
665 | .Fa oldp , | | | |
666 | .Fa newp , | | | |
667 | or length pointer | | | |
668 | .Fa oldlenp | | | |
669 | contains an invalid address, or the requested value is temporarily | | | |
670 | unavailable. | | | |
671 | .It Bq Er EINVAL | | | |
672 | The | | | |
673 | .Fa name | | | |
674 | array is zero or greater than CTL_MAXNAME. | | | |
675 | .It Bq Er EINVAL | | | |
676 | A non-null | | | |
677 | .Fa newp | | | |
678 | is given and its specified length in | | | |
679 | .Fa newlen | | | |
680 | is too large or too small, or the given value is not acceptable for | | | |
681 | the given node. | | | |
682 | .It Bq Er EISDIR | | | |
683 | The | | | |
684 | .Fa name | | | |
685 | array specifies an intermediate rather than terminal name. | | | |
686 | .It Bq Er ENOENT | | | |
687 | The | | | |
688 | .Fa name | | | |
689 | array specifies a node that does not exist in the tree. | | | |
690 | .It Bq Er ENOENT | | | |
691 | An attempt was made to destroy a node that does not exist, or to | | | |
692 | create or destroy a node below a node that does not exist. | | | |
693 | .It Bq Er ENOMEM | | | |
694 | The length pointed to by | | | |
695 | .Fa oldlenp | | | |
696 | is too short to hold the requested value. | | | |
697 | .It Bq Er ENOTDIR | | | |
698 | The | | | |
699 | .Fa name | | | |
700 | array specifies a node below a node that addresses data. | | | |
701 | .It Bq Er ENOTEMPTY | | | |
702 | An attempt was made to destroy a node that still has children. | | | |
703 | .It Bq Er EOPNOTSUPP | | | |
704 | The | | | |
705 | .Fa name | | | |
706 | array specifies a value that is unknown or a meta-operation was | | | |
707 | attempted that the requested node does not support. | | | |
708 | .It Bq Er EPERM | | | |
709 | An attempt is made to set a read-only value. | | | |
710 | .It Bq Er EPERM | | | |
711 | A process without appropriate privilege attempts to set a value or to | | | |
712 | create or destroy a node. | | | |
713 | .It Bq Er EPERM | | | |
714 | An attempt to change a value protected by the current kernel security | | | |
715 | level is made. | | | |
716 | .El | | | |
717 | .Sh SEE ALSO | | | |
718 | .Xr sysctl 7 , | | | |
719 | .Xr sysctl 8 | | | |
720 | .\" .Xr sysctl 9 | | | |
721 | .Sh HISTORY | | | |
722 | The | | | |
723 | .Nm | | | |
724 | function first appeared in | | | |
725 | .Bx 4.4 . | | | |
--- 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 |
| | | 35 | static 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 | |
| | | 84 | static struct syslog_data sdata = SYSLOG_DATA_INIT; |
| | | 85 | |
| | | 86 | static void openlog_unlocked_r(const char *, int, int, |
| | | 87 | struct syslog_data *); |
| | | 88 | static void disconnectlog_r(struct syslog_data *); |
| | | 89 | static void connectlog_r(struct syslog_data *); |
| | | 90 | |
| | | 91 | #define LOG_SIGNAL_SAFE (int)0x80000000 |
| | | 92 | |
| | | 93 | |
| | | 94 | #ifdef _REENTRANT |
| | | 95 | static mutex_t syslog_mutex = MUTEX_INITIALIZER; |
| | | 96 | #endif |
| | | 97 | |
| | | 98 | static char hostname[MAXHOSTNAMELEN]; |
| | | 99 | |
| | | 100 | /* |
| | | 101 | * syslog, vsyslog -- |
| | | 102 | * print message on log file; output is intended for syslogd(8). |
| | | 103 | */ |
| | | 104 | void |
| | | 105 | syslog(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 | |
| | | 114 | void |
| | | 115 | vsyslog(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 | */ |
| | | 124 | void |
| | | 125 | syslogp(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 | |
| | | 134 | void |
| | | 135 | vsyslogp(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 | |
| | | 140 | void |
| | | 141 | openlog(const char *ident, int logstat, int logfac) |
| | | 142 | { |
| | | 143 | openlog_r(ident, logstat, logfac, &sdata); |
| | | 144 | } |
| | | 145 | |
| | | 146 | void |
| | | 147 | closelog(void) |
| | | 148 | { |
| | | 149 | closelog_r(&sdata); |
| | | 150 | } |
| | | 151 | |
| | | 152 | /* setlogmask -- set the log mask level */ |
| | | 153 | int |
| | | 154 | setlogmask(int pmask) |
| | | 155 | { |
| | | 156 | return setlogmask_r(pmask, &sdata); |
| | | 157 | } |
| | | 158 | |
| | | 159 | /* Reentrant version of syslog, i.e. syslog_r() */ |
| | | 160 | |
| | | 161 | void |
| | | 162 | syslog_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 | |
| | | 171 | void |
| | | 172 | syslogp_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 | |
| | | 182 | void |
| | | 183 | syslog_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 | |
| | | 192 | void |
| | | 193 | syslogp_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 | |
| | | 203 | void |
| | | 204 | vsyslog_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 | |
| | | 209 | void |
| | | 210 | vsyslogp_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 | |
| | | 217 | void |
| | | 218 | vsyslog_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 | |
| | | 223 | void |
| | | 224 | vsyslogp_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 | |
| | | 447 | static void |
| | | 448 | disconnectlog_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 | |
| | | 462 | static void |
| | | 463 | connectlog_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 | |
| | | 489 | static void |
| | | 490 | init_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 | |
| | | 519 | static void |
| | | 520 | openlog_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 | |
| | | 537 | void |
| | | 538 | openlog_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 | |
| | | 547 | void |
| | | 548 | closelog_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 | |
| | | 560 | int |
| | | 561 | setlogmask_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 | } |
--- 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 | |
20 | const short _C_tolower_[1 + 256] = { | | 20 | const 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 | |
56 | const short *_tolower_tab_ = _C_tolower_; | | 56 | const short *_tolower_tab_ = _C_tolower_; |
57 | | | | |
58 | #undef tolower | | | |
59 | int | | | |
60 | tolower(c) | | | |
61 | int c; | | | |
62 | { | | | |
63 | return((_tolower_tab_ + 1)[c]); | | | |
64 | } | | | |
--- 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 | |
20 | const short _C_toupper_[1 + 256] = { | | 20 | const 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 | |
56 | const short *_toupper_tab_ = _C_toupper_; | | 56 | const short *_toupper_tab_ = _C_toupper_; |
57 | | | | |
58 | #undef toupper | | | |
59 | int | | | |
60 | toupper(c) | | | |
61 | int c; | | | |
62 | { | | | |
63 | return((_toupper_tab_ + 1)[c]); | | | |
64 | } | | | |
--- 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 | |
5 | SRCS+= iconv.c | | 5 | SRCS+= iconv.c |
6 | MAN+= iconv.3 | | 6 | MAN+= iconv.3 |
7 | MLINKS+=iconv.3 iconv_open.3 iconv.3 iconv_close.3 | | 7 | MLINKS+=iconv.3 iconv_open.3 iconv.3 iconv_close.3 |
8 | | | 8 | |
9 | .if ${CITRUS} == "yes" | | 9 | .if ${CITRUS} == "yes" |
10 | CPPFLAGS+= -DCITRUS_ICONV | | 10 | CPPFLAGS.iconv.c+= -DHAVE_CITRUS -I${LIBCDIR}/citrus |
| | | 11 | .else |
| | | 12 | CPPFLAGS.iconv.c+= -UHAVE_CITRUS |
11 | .endif | | 13 | .endif |
--- 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 | |
59 | iconv_t | | 59 | iconv_t |
60 | iconv_open(const char *out, const char *in) | | 60 | iconv_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; |
--- 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 |
--- 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 | | | | |
7 | SRCS+= _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 | | | |
13 | MAN+= nl_langinfo.3 setlocale.3 wcstol.3 wcscoll.3 wcsxfrm.3 | | | |
14 | | | | |
15 | SRCS+= wcstod.c wcstof.c wcstold.c | | | |
16 | MAN+= wcstod.3 | | | |
17 | | | | |
18 | MLINKS+=setlocale.3 localeconv.3 | | | |
19 | | | | |
20 | .if ${CITRUS} == "no" | | | |
21 | RUNE= no | | | |
22 | .endif | | | |
23 | | | | |
24 | RUNE?= yes | | | |
25 | | | | |
26 | .if ${RUNE} == "no" | | | |
27 | # singlebyte locale - dummy | | | |
28 | SRCS+= multibyte_sb.c iswctype_sb.c | | | |
29 | CPPFLAGS+=-UWITH_RUNE | | | |
30 | .else | | | |
31 | # citrus multibyte locale support | | | |
32 | # we have quirk for libc.a - see the last part of lib/libc/Makefile | | | |
33 | CPPFLAGS+=-DWITH_RUNE -I${.CURDIR} | | | |
34 | SRCS+= ___runetype_mb.c _wctrans.c iswctype.c multibyte_c90.c \ | | | |
35 | multibyte_amd1.c rune.c runeglue.c runetable.c setrunelocale.c | | | |
36 | .endif | | | |
37 | MAN+= 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 | | | | |
42 | MLINKS+=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 | | | |
48 | MLINKS+=towlower.3 towupper.3 | | | |
49 | MLINKS+=wcstod.3 wcstof.3 wcstod.3 wcstold.3 | | | |
50 | MLINKS+=wcstol.3 wcstoll.3 wcstol.3 wcstoimax.3 \ | | | |
51 | wcstol.3 wcstoul.3 wcstol.3 wcstoull.3 wcstol.3 wcstoumax.3 | | | |
--- 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 | |
79 | void | | 79 | void |
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 | */ |
94 | wint_t | | 94 | wint_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 | |
--- 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 |
32 | wint_t _towctrans_ext(wint_t, _WCTransEntry *); | | 33 | wint_t _towctrans_ext(wint_t, _WCTransEntry *); |
33 | void _wctrans_init(_RuneLocale *); | | 34 | void _wctrans_init(_RuneLocale *); |
| | | 35 | __END_DECLS |
34 | | | 36 | |
35 | static __inline wint_t | | 37 | static __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 | |
42 | static __inline struct _WCTransEntry * | | 44 | static __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 | |
50 | static __inline struct _WCTransEntry * | | 52 | static __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_*/ |
/* $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;
}
/* $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_*/
/* $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;
/* $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_*/
/* $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;
}
/* $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_);
/* $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_*/
/* $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;
}
/* $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_*/
/* $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_);
/* $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_*/
/* $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_*/
/* $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),
},
};
/* $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;
}
/* $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_);
/* $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_);
/* $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_);
/* $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_);
/* $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_);
/* $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_*/
/* $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_*/
/* $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_*/
/* $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_*/
/* $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_*/
/* $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_*/
/* $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_*/
--- 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 | |
49 | const char * | | 49 | const 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 | |
--- 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 | |
29 | const char *__unaliasname(const char *, const char *, void *, size_t); | | 58 | const char *__unaliasname(const char *, const char *, void *, size_t); |
| | | 59 | |
| | | 60 | static __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_*/ |
--- 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 | |
47 | int | | 50 | int |
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; | | | |
120 | bad: | | | |
121 | free(new_tolower); | | | |
122 | free(new_toupper); | | | |
123 | free(new_ctype); | | | |
124 | (void) fclose(fp); | | | |
125 | return 0; | | | |
126 | } | | | |
127 | | | 113 | |
128 | int | | 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) | | 122 | bad1: |
146 | goto bad; | | 123 | free(data); |
147 | | | 124 | bad0: |
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; | | | |
174 | bad: | | | |
175 | (void) fclose(fp); | | | |
176 | return 0; | | | |
177 | } | | 126 | } |
--- 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 |
33 | int __loadctype __P((const char *)); | | 33 | int __loadctype(const char * __restrict, _BSDCTypeLocale ** __restrict pdata); |
34 | int __savectype __P((const char *, unsigned char *, short *, short *)); | | | |
35 | __END_DECLS | | 34 | __END_DECLS |
--- 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 | | | |
47 | int | | | |
48 | iswalnum(c) | | | |
49 | wint_t c; | | | |
50 | { | | | |
51 | return isalnum((int)c); | | | |
52 | } | | | |
53 | | | | |
54 | #undef iswalpha | | | |
55 | int | | | |
56 | iswalpha(c) | | | |
57 | wint_t c; | | | |
58 | { | | | |
59 | return isalpha((int)c); | | | |
60 | } | | | |
61 | | | | |
62 | #undef iswblank | | | |
63 | int | | | |
64 | iswblank(c) | | | |
65 | wint_t c; | | | |
66 | { | | | |
67 | return isblank((int)c); | | | |
68 | } | | | |
69 | | | | |
70 | #undef iswcntrl | | | |
71 | int | | | |
72 | iswcntrl(c) | | | |
73 | wint_t c; | | | |
74 | { | | | |
75 | return iscntrl((int)c); | | | |
76 | } | | | |
77 | | | | |
78 | #undef iswdigit | | | |
79 | int | | | |
80 | iswdigit(c) | | | |
81 | wint_t c; | | | |
82 | { | | | |
83 | return isdigit((int)c); | | | |
84 | } | | | |
85 | | | | |
86 | #undef iswgraph | | | |
87 | int | | | |
88 | iswgraph(c) | | | |
89 | wint_t c; | | | |
90 | { | | | |
91 | return isgraph((int)c); | | | |
92 | } | | | |
93 | | | | |
94 | #undef iswlower | | | |
95 | int | | | |
96 | iswlower(c) | | | |
97 | wint_t c; | | | |
98 | { | | | |
99 | return islower((int)c); | | | |
100 | } | | | |
101 | | | | |
102 | #undef iswprint | | | |
103 | int | | | |
104 | iswprint(c) | | | |
105 | wint_t c; | | | |
106 | { | | | |
107 | return isprint((int)c); | | | |
108 | } | | | |
109 | | | | |
110 | #undef iswpunct | | | |
111 | int | | | |
112 | iswpunct(c) | | | |
113 | wint_t c; | | | |
114 | { | | | |
115 | return ispunct((int)c); | | | |
116 | } | | | |
117 | | | | |
118 | #undef iswspace | | | |
119 | int | | | |
120 | iswspace(c) | | | |
121 | wint_t c; | | | |
122 | { | | | |
123 | return isspace((int)c); | | | |
124 | } | | | |
125 | | | | |
126 | #undef iswupper | | | |
127 | int | | | |
128 | iswupper(c) | | | |
129 | wint_t c; | | | |
130 | { | | | |
131 | return isupper((int)c); | | | |
132 | } | | | |
133 | | | | |
134 | #undef iswxdigit | | | |
135 | int | | | |
136 | iswxdigit(c) | | | |
137 | wint_t c; | | | |
138 | { | | | |
139 | return isxdigit((int)c); | | | |
140 | } | | | |
141 | | | | |
142 | #undef towupper | | | |
143 | wint_t | | | |
144 | towupper(c) | | | |
145 | wint_t c; | | | |
146 | { | | | |
147 | return toupper((int)c); | | | |
148 | } | | | |
149 | | | | |
150 | #undef towlower | | | |
151 | wint_t | | | |
152 | towlower(c) | | | |
153 | wint_t c; | | | |
154 | { | | | |
155 | return tolower((int)c); | | | |
156 | } | | | |
157 | | | | |
158 | #undef wcwidth | | | |
159 | int | | | |
160 | /*ARGSUSED*/ | | | |
161 | wcwidth(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 | } | | | |
--- 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 | */ | | | |
25 | int __mlocale_changed = 1; | | | |
26 | int __nlocale_changed = 1; | | | |
27 | | | 40 | |
28 | /* | | | |
29 | * Return the current locale conversion. | | | |
30 | */ | | | |
31 | struct lconv * | | 41 | struct lconv * |
32 | localeconv() | | 42 | localeconv() |
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 | } |
--- 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 | | | | |
53 | int | | | |
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 | | | | |
114 | error2: | | | |
115 | free(buf); | | | |
116 | error1: | | | |
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 | | | | |
129 | static const char nogrouping[] = { CHAR_MAX, '\0' }; | | | |
130 | | | | |
131 | const 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 | } | | | |
--- 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 | | | |
32 | int __loadlocale(const char *, size_t, size_t, size_t, void *, const void *); | | | |
33 | const char * __convertgrouping(const char *); | | | |
34 | __END_DECLS | | | |
--- 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 | |
115 | static __inline void | | 115 | static __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_*/ |
--- 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 | |
43 | size_t | | 55 | size_t |
44 | mbrlen(const char *s, size_t n, mbstate_t *ps) | | 56 | mbrlen(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 | |
59 | int | | 71 | int |
60 | mbsinit(const mbstate_t *ps) | | 72 | mbsinit(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 | |
83 | size_t | | 95 | size_t |
84 | mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) | | 96 | mbrtowc(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 | |
99 | size_t | | 111 | size_t |
100 | mbsrtowcs(wchar_t *pwcs, const char **s, size_t n, mbstate_t *ps) | | 112 | mbsrtowcs(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 | |
115 | size_t | | 127 | size_t |
116 | wcrtomb(char *s, wchar_t wc, mbstate_t *ps) | | 128 | wcrtomb(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 | |
131 | size_t | | 143 | size_t |
132 | wcsrtombs(char *s, const wchar_t **ppwcs, size_t n, mbstate_t *ps) | | 144 | wcsrtombs(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 | |
147 | wint_t | | 159 | wint_t |
148 | btowc(int c) | | 160 | btowc(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 | |
160 | int | | 172 | int |
161 | wctob(wint_t wc) | | 173 | wctob(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 | } |
--- 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 | |
44 | int | | 55 | int |
45 | mblen(const char *s, size_t n) | | 56 | mblen(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 | |
57 | size_t | | 68 | size_t |
58 | mbstowcs(wchar_t *pwcs, const char *s, size_t n) | | 69 | mbstowcs(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 | |
70 | int | | 81 | int |
71 | mbtowc(wchar_t *pw, const char *s, size_t n) | | 82 | mbtowc(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 | |
83 | size_t | | 94 | size_t |
84 | wcstombs(char *s, const wchar_t *wcs, size_t n) | | 95 | wcstombs(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 | |
96 | int | | 107 | int |
97 | wctomb(char *s, wchar_t wc) | | 108 | wctomb(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 | } |
--- 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 | |
20 | char * | | 42 | char * |
21 | nl_langinfo(item) | | 43 | nl_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 | } |
--- 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 |
64 | static char sccsid[] = "@(#)rune.c 8.1 (Berkeley) 6/4/93"; | | 64 | static 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 | |
84 | static int readrange __P((_RuneLocale *, _RuneRange *, _FileRuneRange *, void *, FILE *)); | | 87 | static int readrange __P((_RuneLocale *, _RuneRange *, _FileRuneRange *, void *, FILE *)); |
85 | static void _freeentry __P((_RuneRange *)); | | 88 | static void _freeentry __P((_RuneRange *)); |
86 | static void _wctype_init __P((_RuneLocale *rl)); | | 89 | static void _wctype_init __P((_RuneLocale *rl)); |
87 | | | 90 | |
88 | static int | | 91 | static int |
89 | readrange(_RuneLocale *rl, _RuneRange *rr, _FileRuneRange *frr, void *lastp, | | 92 | readrange(_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; |
--- 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 | */ |
89 | extern size_t __mb_len_max_runtime; | | 89 | extern 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 | |
92 | extern _RuneLocale _DefaultRuneLocale; | | 92 | extern const _RuneLocale _DefaultRuneLocale; |
93 | extern _RuneLocale *_CurrentRuneLocale; | | 93 | extern const _RuneLocale *_CurrentRuneLocale; |
94 | extern const char *_PathLocale; | | | |
95 | | | | |
96 | #define _LOCALE_ALIAS_NAME "locale.alias" | | | |
97 | | | 94 | |
98 | #endif /*! _RUNE_H_ */ | | 95 | #endif /*! _RUNE_H_ */ |
--- 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 */ | | | |
33 | extern _RuneLocale *_Read_RuneMagi __P((FILE *fp)); | | | |
34 | extern _RuneLocale *_Read_CTypeAsRune __P((FILE *fp)); | | | |
35 | extern void _NukeRune __P((_RuneLocale *)); | | | |
36 | | | | |
37 | /* setrunelocale.c */ | | | |
38 | extern int _xpg4_setrunelocale __P((const char *)); | | | |
39 | extern _RuneLocale *_findrunelocale __P((char *)); | | | |
40 | extern int _newrunelocale __P((char *)); | | | |
41 | | | | |
42 | /* runeglue.c */ | | | |
43 | extern int __runetable_to_netbsd_ctype __P((_RuneLocale *)); | | | |
44 | | | | |
45 | /* ___runetype_mb.c */ | | | |
46 | extern _RuneType ___runetype_mb __P((wint_t)); | | | |
47 | | | | |
48 | #endif | | | |
--- 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 | | | | |
62 | int | | | |
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 | } | | | |
--- 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 | | | |
40 | static 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 | | | | |
354 | const char *_PathLocale; | | | |
--- 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 | | | |
38 | static 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 | */ | | | |
87 | static 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 | */ | | | |
100 | static 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 | */ | | | |
113 | static char new_categories[_LC_LAST][32]; | | | |
114 | | | | |
115 | static char current_locale_string[_LC_LAST * 33]; | | | |
116 | | | | |
117 | static char *currentlocale __P((void)); | | | |
118 | static void revert_to_default __P((int)); | | | |
119 | static int force_locale_enable __P((int)); | | | |
120 | static int load_locale_sub __P((int, const char *, int)); | | | |
121 | static char *loadlocale __P((int)); | | | |
122 | static const char *__get_locale_env __P((int)); | | | |
123 | | | | |
124 | char * | | | |
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 | | | | |
224 | static char * | | | |
225 | currentlocale() | | | |
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 | | | | |
244 | static void | | | |
245 | revert_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 | | | | |
299 | static int | | | |
300 | force_locale_enable(category) | | | |
301 | int category; | | | |
302 | { | | | |
303 | revert_to_default(category); | | | |
304 | | | | |
305 | return 0; | | | |
306 | } | | | |
307 | | | | |
308 | static int | | | |
309 | load_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 | | | | |
395 | static char * | | | |
396 | loadlocale(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 | | | | |
429 | success: | | | |
430 | (void)strlcpy(current_categories[category], | | | |
431 | new_categories[category], | | | |
432 | sizeof(current_categories[category])); | | | |
433 | return current_categories[category]; | | | |
434 | } | | | |
435 | | | | |
436 | static 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 | } | | | |
--- 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 | |
5 | SRCS+= catclose.c catgets.c catopen.c | | 5 | SRCS+= catclose.c catgets.c catopen.c |
6 | MAN+= catclose.3 catgets.3 catopen.3 | | 6 | MAN+= catclose.3 catgets.3 catopen.3 |
7 | | | 7 | |
8 | # indirect reference stubs, to be removed soon. | | 8 | # indirect reference stubs, to be removed soon. |
9 | SRCS+= _catclose.c _catgets.c _catopen.c | | 9 | SRCS+= _catclose.c _catgets.c _catopen.c |
| | | 10 | |
| | | 11 | .if ${CITRUS} == "yes" |
| | | 12 | CPPFLAGS.catopen.c+= -DHAVE_CITRUS -I${LIBCDIR}/citrus |
| | | 13 | .else |
| | | 14 | CPPFLAGS.catopen.c+= -UHAVE_CITRUS -I${LIBCDIR}/locale |
| | | 15 | .endif |
| | | 16 | |
--- 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 | | | | |
71 | static nl_catd load_msgcat __P((const char *)); | | | |
72 | | | | |
73 | nl_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 | | | | |
151 | static nl_catd | | | |
152 | load_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 | } | | | |
--- 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 | | | | |
43 | struct __res_state _nres | | | |
44 | # if defined(__BIND_RES_TEXT) | | | |
45 | = { .retrans = RES_TIMEOUT, } /*%< Motorola, et al. */ | | | |
46 | # endif | | | |
47 | ; | | | |
48 | | | | |
49 | res_state __res_get_state_nothread(void); | | | |
50 | void __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 | | | | |
59 | res_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 | | | | |
69 | void | | | |
70 | /*ARGSUSED*/ | | | |
71 | __res_put_state_nothread(res_state res) | | | |
72 | { | | | |
73 | } | | | |
--- 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 |
782 | This routine returns 1 if the results were successfully freed, | | 785 | This routine returns 1 if the results were successfully freed, |
783 | and zero otherwise. | | 786 | and zero otherwise. |
784 | .It Fn svc_getargs | | 787 | .It Fn svc_getargs |
785 | A macro that decodes the arguments of an RPC request associated with | | 788 | A macro that decodes the arguments of an RPC request associated with |
786 | the RPC service transport handle, | | 789 | the RPC service transport handle, |
787 | .Fa xprt . | | 790 | .Fa xprt . |
788 | The parameter | | 791 | The parameter |
789 | .Fa in | | 792 | .Fa in |
790 | is the address where the arguments will be placed; | | 793 | is the address where the arguments will be placed; |
791 | .Fa inproc | | 794 | .Fa inproc |
792 | is the XDR routine used to decode the arguments. | | 795 | is the XDR routine used to decode the arguments. |
793 | This routine returns one if decoding succeeds, and zero otherwise. | | 796 | This routine returns one if decoding succeeds, and zero otherwise. |
794 | .It Fn svc_getcaller | | 797 | .It Fn svc_getcaller |
795 | The approved way of getting the network address of the caller | | 798 | The obsolete way of getting the network address of the caller |
796 | of a procedure associated with the RPC service transport handle, | | 799 | of a procedure associated with the RPC service transport handle, |
797 | .Fa xprt . | | 800 | .Fa xprt , |
| | | 801 | use |
| | | 802 | .Fn svc_getrpccaller . |
798 | .It Fn svc_getreqset | | 803 | .It Fn svc_getreqset |
799 | This routine is only of interest if a service implementor | | 804 | This routine is only of interest if a service implementor |
800 | does not call | | 805 | does not call |
801 | .Fn svc_run , | | 806 | .Fn svc_run , |
802 | but instead implements custom asynchronous event processing. | | 807 | but instead implements custom asynchronous event processing. |
803 | It is called when the | | 808 | It is called when the |
804 | .Xr select 2 | | 809 | .Xr select 2 |
805 | system call has determined that an RPC request has arrived on some | | 810 | system call has determined that an RPC request has arrived on some |
806 | RPC socket(s) ; | | 811 | RPC socket(s) ; |
807 | .Fa rdfds | | 812 | .Fa rdfds |
808 | is the resultant read file descriptor bit mask. | | 813 | is the resultant read file descriptor bit mask. |
809 | The routine returns when all sockets associated with the | | 814 | The routine returns when all sockets associated with the |
810 | value of | | 815 | value of |
811 | .Fa rdfds | | 816 | .Fa rdfds |
812 | have been serviced. | | 817 | have been serviced. |
813 | .It Fn svc_getreq | | 818 | .It Fn svc_getreq |
814 | Similar to | | 819 | Similar to |
815 | .Fn svc_getreqset , | | 820 | .Fn svc_getreqset , |
816 | but limited to 32 descriptors. | | 821 | but limited to 32 descriptors. |
817 | This interface is obsoleted by | | 822 | This interface is obsoleted by |
818 | .Fn svc_getreqset . | | 823 | .Fn svc_getreqset . |
| | | 824 | .It Fn svc_getrpccaller |
| | | 825 | The approved way of getting the network address of the caller |
| | | 826 | of a procedure associated with the RPC service transport handle, |
| | | 827 | .Fa xprt . |
819 | .It Fn svc_register | | 828 | .It Fn svc_register |
820 | Associates | | 829 | Associates |
821 | .Fa prognum | | 830 | .Fa prognum |
822 | and | | 831 | and |
823 | .Fa versnum | | 832 | .Fa versnum |
824 | with the service dispatch procedure, | | 833 | with the service dispatch procedure, |
825 | .Fa dispatch . | | 834 | .Fa dispatch . |
826 | If | | 835 | If |
827 | .Fa protocol | | 836 | .Fa protocol |
828 | is zero, the service is not registered with the | | 837 | is zero, the service is not registered with the |
829 | .Xr rpcbind 8 | | 838 | .Xr rpcbind 8 |
830 | service. | | 839 | service. |
831 | If | | 840 | If |
--- 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 |
60 | storing them at the location given by | | 60 | storing them at the location given by |
61 | .Fa ptr . | | 61 | .Fa ptr . |
62 | .Pp | | 62 | .Pp |
63 | The function | | 63 | The function |
64 | .Fn fwrite | | 64 | .Fn fwrite |
65 | writes | | 65 | writes |
66 | .Fa nmemb | | 66 | .Fa nmemb |
67 | objects, each | | 67 | objects, each |
68 | .Fa size | | 68 | .Fa size |
69 | bytes long, to the stream pointed to by | | 69 | bytes long, to the stream pointed to by |
70 | .Fa stream , | | 70 | .Fa stream , |
71 | obtaining them from the location given by | | 71 | obtaining them from the location given by |
72 | .Fa ptr . | | 72 | .Fa ptr . |
| | | 73 | .Pp |
| | | 74 | Mixing |
| | | 75 | .Fn fread |
| | | 76 | and |
| | | 77 | .Fn fwrite |
| | | 78 | calls without setting the file position explicitly using |
| | | 79 | .Fn fsetpos |
| | | 80 | between read and write or write and read operations will lead to unexpected |
| | | 81 | results because of buffering the file pointer not being set to the |
| | | 82 | expected position after each operation completes. |
| | | 83 | This behavior is allowed by ANSI C for efficiency and it will not be changed. |
73 | .Sh RETURN VALUES | | 84 | .Sh RETURN VALUES |
74 | The functions | | 85 | The functions |
75 | .Fn fread | | 86 | .Fn fread |
76 | and | | 87 | and |
77 | .Fn fwrite | | 88 | .Fn fwrite |
78 | advance the file position indicator for the stream | | 89 | advance the file position indicator for the stream |
79 | by the number of bytes read or written. | | 90 | by the number of bytes read or written. |
80 | They return the number of objects read or written. | | 91 | They return the number of objects read or written. |
81 | If | | 92 | If |
82 | .Fa size | | 93 | .Fa size |
83 | or | | 94 | or |
84 | .Fa nmemb | | 95 | .Fa nmemb |
85 | is 0, the functions return 0 and the state of | | 96 | is 0, the functions return 0 and the state of |
--- 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 |
104 | and | | 104 | and |
105 | .Fn vasprintf | | 105 | .Fn vasprintf |
106 | write to a dynamically allocated string that is stored in | | 106 | write to a dynamically allocated string that is stored in |
107 | .Fa ret . | | 107 | .Fa ret . |
108 | .Pp | | 108 | .Pp |
109 | These functions write the output under the control of a | | 109 | These functions write the output under the control of a |
110 | .Fa format | | 110 | .Fa format |
111 | string that specifies how subsequent arguments | | 111 | string 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 ) |
114 | are converted for output. | | 114 | are converted for output. |
115 | .Pp | | 115 | .Pp |
116 | These functions return | | | |
117 | the number of characters printed | | | |
118 | (not including the trailing | | | |
119 | .Ql \e0 | | | |
120 | used to end output to strings). | | | |
121 | If an output error was encountered, these functions shall return a | | | |
122 | negative value. | | | |
123 | .Pp | | | |
124 | .Fn asprintf | | 116 | .Fn asprintf |
125 | and | | 117 | and |
126 | .Fn vasprintf | | 118 | .Fn vasprintf |
127 | return a pointer to a buffer sufficiently large to hold the | | 119 | return a pointer to a buffer sufficiently large to hold the |
128 | string in the | | 120 | string in the |
129 | .Fa ret | | 121 | .Fa ret |
130 | argument. | | 122 | argument. |
131 | This pointer should be passed to | | 123 | This pointer should be passed to |
132 | .Xr free 3 | | 124 | .Xr free 3 |
133 | to release the allocated storage when it is no longer needed. | | 125 | to release the allocated storage when it is no longer needed. |
134 | If sufficient space cannot be allocated, these functions | | 126 | If sufficient space cannot be allocated, these functions |
135 | will return \-1 and set | | 127 | will 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 |
385 | conversion, indicates that the argument is of a signed type equivalent in | | 377 | conversion, indicates that the argument is of a signed type equivalent in |
386 | size to a | | 378 | size to a |
387 | .Vt size_t . | | 379 | .Vt size_t . |
388 | Similarly, when applied to an | | 380 | Similarly, when applied to an |
389 | .Cm n | | 381 | .Cm n |
390 | conversion, it indicates that the argument is a pointer to a signed type | | 382 | conversion, it indicates that the argument is a pointer to a signed type |
391 | equivalent in size to a | | 383 | equivalent in size to a |
392 | .Vt size_t . | | 384 | .Vt size_t . |
393 | .Pp | | 385 | .Pp |
394 | The following length modifier is valid for the | | 386 | The 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 , |
402 | or | | 394 | or |
403 | .Cm G | | 395 | .Cm G |
404 | conversion: | | 396 | conversion: |
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 |
412 | The following length modifier is valid for the | | 404 | The 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. |
700 | No argument is converted. | | 692 | No argument is converted. |
701 | The complete conversion specification is | | 693 | The complete conversion specification is |
702 | .Ql %% . | | 694 | .Ql %% . |
703 | .El | | 695 | .El |
704 | .Pp | | 696 | .Pp |
705 | The decimal point | | 697 | The decimal point |
706 | character is defined in the program's locale (category | | 698 | character is defined in the program's locale (category |
707 | .Dv LC_NUMERIC ) . | | 699 | .Dv LC_NUMERIC ) . |
708 | .Pp | | 700 | .Pp |
709 | In no case does a non-existent or small field width cause truncation of | | 701 | In no case does a non-existent or small field width cause truncation of |
710 | a numeric field; if the result of a conversion is wider than the field | | 702 | a numeric field; if the result of a conversion is wider than the field |
711 | width, the | | 703 | width, the |
712 | field is expanded to contain the conversion result. | | 704 | field is expanded to contain the conversion result. |
| | | 705 | .Sh RETURN VALUES |
| | | 706 | These functions return |
| | | 707 | the number of characters printed, or that would be printed if there |
| | | 708 | was adequate space in case of |
| | | 709 | .Fn snprintf |
| | | 710 | and |
| | | 711 | .Fn vsnprintf , |
| | | 712 | (not including the trailing |
| | | 713 | .Ql \e0 |
| | | 714 | used to end output to strings). |
| | | 715 | If an output error was encountered, these functions shall return a |
| | | 716 | negative value. |
713 | .Sh EXAMPLES | | 717 | .Sh EXAMPLES |
714 | .br | | 718 | .br |
715 | To print a date and time in the form | | 719 | To print a date and time in the form |
716 | .Dq Li "Sunday, July 3, 10:02" , | | 720 | .Dq Li "Sunday, July 3, 10:02" , |
717 | where | | 721 | where |
718 | .Fa weekday | | 722 | .Fa weekday |
719 | and | | 723 | and |
720 | .Fa month | | 724 | .Fa month |
721 | are pointers to strings: | | 725 | are 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] |
724 | fprintf(stdout, "%s, %s %d, %.2d:%.2d\en", | | 728 | fprintf(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 |
728 | To print \*(Pi | | 732 | To 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] |
741 | char *newfmt(const char *fmt, ...) | | 745 | char *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 | | | |
754 | The | | | |
755 | .Fn sprintf | | | |
756 | and | | | |
757 | .Fn vsprintf | | | |
758 | functions are easily misused in a manner which enables malicious users | | | |
759 | to arbitrarily change a running program's functionality through | | | |
760 | a buffer overflow attack. | | | |
761 | Because | | | |
762 | .Fn sprintf | | | |
763 | and | | | |
764 | .Fn vsprintf | | | |
765 | assume an infinitely long string, | | | |
766 | callers must be careful not to overflow the actual space; | | | |
767 | this is often hard to assure. | | | |
768 | For safety, programmers should use the | | | |
769 | .Fn snprintf | | | |
770 | interface instead. | | | |
771 | For example: | | | |
772 | .Bd -literal | | | |
773 | void | | | |
774 | foo(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 | | | |
794 | The | | | |
795 | .Fn printf | | | |
796 | and | | | |
797 | .Fn sprintf | | | |
798 | family of functions are also easily misused in a manner | | | |
799 | allowing malicious users to arbitrarily change a running program's | | | |
800 | functionality by either causing the program | | | |
801 | to print potentially sensitive data | | | |
802 | .Dq "left on the stack" , | | | |
803 | or causing it to generate a memory fault or bus error | | | |
804 | by dereferencing an invalid pointer. | | | |
805 | .Pp | | | |
806 | .Cm %n | | | |
807 | can be used to write arbitrary data to potentially carefully-selected | | | |
808 | addresses. | | | |
809 | Programmers are therefore strongly advised to never pass untrusted strings | | | |
810 | as the | | | |
811 | .Fa format | | | |
812 | argument, as an attacker can put format specifiers in the string | | | |
813 | to mangle your stack, | | | |
814 | leading to a possible security hole. | | | |
815 | This holds true even if the string was built using a function like | | | |
816 | .Fn snprintf , | | | |
817 | as the resulting string may still contain user-supplied conversion specifiers | | | |
818 | for later interpolation by | | | |
819 | .Fn printf . | | | |
820 | .Pp | | | |
821 | Always use the proper secure idiom: | | | |
822 | .Pp | | | |
823 | .Dl "snprintf(buffer, sizeof(buffer), \*q%s\*q, string);" | | | |
824 | .Sh ERRORS | | 757 | .Sh ERRORS |
825 | In addition to the errors documented for the | | 758 | In addition to the errors documented for the |
826 | .Xr write 2 | | 759 | .Xr write 2 |
827 | system call, the | | 760 | system call, the |
828 | .Fn printf | | 761 | .Fn printf |
829 | family of functions may fail if: | | 762 | family 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 |
832 | An invalid wide character code was encountered. | | 765 | An invalid wide character code was encountered. |
833 | .It Bq Er ENOMEM | | 766 | .It Bq Er ENOMEM |
834 | Insufficient storage space is available. | | 767 | Insufficient 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 |
844 | Subject to the caveats noted in the | | 777 | Subject to the caveats noted in the |
845 | .Sx BUGS | | 778 | .Sx BUGS |
846 | section below, the | | 779 | section 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 , |
852 | and | | 785 | and |
853 | .Fn vsprintf | | 786 | .Fn vsprintf |
854 | functions | | 787 | functions |
855 | conform to | | 788 | conform to |
| @@ -944,13 +877,84 @@ of the | | | @@ -944,13 +877,84 @@ of the |
944 | flag on | | 877 | flag on |
945 | .Cm %n | | 878 | .Cm %n |
946 | and | | 879 | and |
947 | .Cm %p | | 880 | .Cm %p |
948 | conversions, as well as other nonsensical combinations such as | | 881 | conversions, as well as other nonsensical combinations such as |
949 | .Cm %Ld , | | 882 | .Cm %Ld , |
950 | are not standard; such combinations should be avoided. | | 883 | are not standard; such combinations should be avoided. |
951 | .Pp | | 884 | .Pp |
952 | The | | 885 | The |
953 | .Nm | | 886 | .Nm |
954 | family of functions do not correctly handle multibyte characters in the | | 887 | family of functions do not correctly handle multibyte characters in the |
955 | .Fa format | | 888 | .Fa format |
956 | argument. | | 889 | argument. |
| | | 890 | .Sh SECURITY CONSIDERATIONS |
| | | 891 | The |
| | | 892 | .Fn sprintf |
| | | 893 | and |
| | | 894 | .Fn vsprintf |
| | | 895 | functions are easily misused in a manner which enables malicious users |
| | | 896 | to arbitrarily change a running program's functionality through |
| | | 897 | a buffer overflow attack. |
| | | 898 | Because |
| | | 899 | .Fn sprintf |
| | | 900 | and |
| | | 901 | .Fn vsprintf |
| | | 902 | assume an infinitely long string, |
| | | 903 | callers must be careful not to overflow the actual space; |
| | | 904 | this is often hard to assure. |
| | | 905 | For safety, programmers should use the |
| | | 906 | .Fn snprintf |
| | | 907 | interface instead. |
| | | 908 | For example: |
| | | 909 | .Bd -literal |
| | | 910 | void |
| | | 911 | foo(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 |
| | | 931 | The |
| | | 932 | .Fn printf |
| | | 933 | and |
| | | 934 | .Fn sprintf |
| | | 935 | family of functions are also easily misused in a manner |
| | | 936 | allowing malicious users to arbitrarily change a running program's |
| | | 937 | functionality by either causing the program |
| | | 938 | to print potentially sensitive data |
| | | 939 | .Dq "left on the stack" , |
| | | 940 | or causing it to generate a memory fault or bus error |
| | | 941 | by dereferencing an invalid pointer. |
| | | 942 | .Pp |
| | | 943 | .Cm %n |
| | | 944 | can be used to write arbitrary data to potentially carefully-selected |
| | | 945 | addresses. |
| | | 946 | Programmers are therefore strongly advised to never pass untrusted strings |
| | | 947 | as the |
| | | 948 | .Fa format |
| | | 949 | argument, as an attacker can put format specifiers in the string |
| | | 950 | to mangle your stack, |
| | | 951 | leading to a possible security hole. |
| | | 952 | This holds true even if the string was built using a function like |
| | | 953 | .Fn snprintf , |
| | | 954 | as the resulting string may still contain user-supplied conversion specifiers |
| | | 955 | for later interpolation by |
| | | 956 | .Fn printf . |
| | | 957 | .Pp |
| | | 958 | Always use the proper secure idiom: |
| | | 959 | .Pp |
| | | 960 | .Dl "snprintf(buffer, sizeof(buffer), \*q%s\*q, string);" |
--- 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 | | | |
42 | static 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 | | | | |
105 | static 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 | */ | | | |
114 | int | | | |
115 | vfwscanf(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() \ | | | |
127 | do { \ | | | |
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 | */ | | | |
139 | int | | | |
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 | */ | | | |
194 | again: c = *fmt++; | | | |
195 | switch (c) { | | | |
196 | case '%': | | | |
197 | SCANF_SKIP_SPACE(); | | | |
198 | literal: | | | |
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 | } | | | |
742 | input_failure: | | | |
743 | return (nconversions != 0 ? nassigned : EOF); | | | |
744 | match_failure: | | | |
745 | return (nassigned); | | | |
746 | } | | | |
747 | | | | |
748 | #ifndef NO_FLOATING_POINT | | | |
749 | static int | | | |
750 | parsefloat(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; | | | |
776 | reswitch: | | | |
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 | | | | |
892 | parsedone: | | | |
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 | | | |
--- 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 |
42 | static char sccsid[] = "@(#)vsscanf.c 8.1 (Berkeley) 6/4/93"; | | 42 | static 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 | |
58 | static int eofread(void *, char *, int); | | 58 | static 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 | } |
--- 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 |
86 | and | | 86 | and |
87 | .Fn vswprintf | | 87 | .Fn vswprintf |
88 | write to the wide character string | | 88 | write to the wide character string |
89 | .Fa ws . | | 89 | .Fa ws . |
90 | .Pp | | 90 | .Pp |
91 | These functions write the output under the control of a | | 91 | These functions write the output under the control of a |
92 | .Fa format | | 92 | .Fa format |
93 | string that specifies how subsequent arguments | | 93 | string 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 ) |
96 | are converted for output. | | 96 | are converted for output. |
97 | .Pp | | 97 | .Pp |
98 | These functions return the number of characters printed | | | |
99 | (not including the trailing | | | |
100 | .Ql \e0 | | | |
101 | used to end output to strings). | | | |
102 | .Pp | | | |
103 | The | | 98 | The |
104 | .Fn swprintf | | 99 | .Fn swprintf |
105 | and | | 100 | and |
106 | .Fn vswprintf | | 101 | .Fn vswprintf |
107 | functions will fail if | | 102 | functions will fail if |
108 | .Fa n | | 103 | .Fa n |
109 | or more wide characters were requested to be written, | | 104 | or more wide characters were requested to be written, |
110 | .Pp | | 105 | .Pp |
111 | The format string is composed of zero or more directives: | | 106 | The format string is composed of zero or more directives: |
112 | ordinary | | 107 | ordinary |
113 | characters (not | | 108 | characters (not |
114 | .Cm % ) , | | 109 | .Cm % ) , |
115 | which are copied unchanged to the output stream; | | 110 | which are copied unchanged to the output stream; |
| @@ -583,26 +578,31 @@ No argument is converted. | | | @@ -583,26 +578,31 @@ No argument is converted. |
583 | The complete conversion specification | | 578 | The complete conversion specification |
584 | is | | 579 | is |
585 | .Ql %% . | | 580 | .Ql %% . |
586 | .El | | 581 | .El |
587 | .Pp | | 582 | .Pp |
588 | The decimal point | | 583 | The decimal point |
589 | character is defined in the program's locale (category | | 584 | character is defined in the program's locale (category |
590 | .Dv LC_NUMERIC ) . | | 585 | .Dv LC_NUMERIC ) . |
591 | .Pp | | 586 | .Pp |
592 | In no case does a non-existent or small field width cause truncation of | | 587 | In no case does a non-existent or small field width cause truncation of |
593 | a numeric field; if the result of a conversion is wider than the field | | 588 | a numeric field; if the result of a conversion is wider than the field |
594 | width, the | | 589 | width, the |
595 | field is expanded to contain the conversion result. | | 590 | field is expanded to contain the conversion result. |
| | | 591 | .Sh RETURN VALUES |
| | | 592 | These functions return the number of characters printed |
| | | 593 | (not including the trailing |
| | | 594 | .Ql \e0 |
| | | 595 | used 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 |
605 | Subject to the caveats noted in the | | 605 | Subject to the caveats noted in the |
606 | .Sh SECURITY CONSIDERATIONS | | 606 | .Sh SECURITY CONSIDERATIONS |
607 | Refer to | | 607 | Refer to |
608 | .Xr printf 3 . | | 608 | .Xr printf 3 . |
--- 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 |
35 | static char sccsid[] = "@(#)qsort.c 8.1 (Berkeley) 6/4/93"; | | 35 | static 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 | |
47 | static inline char *med3 __P((char *, char *, char *, | | 47 | static inline char *med3 __P((char *, char *, char *, |
48 | int (*)(const void *, const void *))); | | 48 | int (*)(const void *, const void *))); |
49 | static inline void swapfunc __P((char *, char *, size_t, int)); | | 49 | static inline void swapfunc __P((char *, char *, size_t, int)); |
50 | | | 50 | |
--- 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 | |
7 | SRCS+= bm.c strcasecmp.c strncasecmp.c strcasestr.c strcoll.c strdup.c \ | | 7 | SRCS+= 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 |
13 | SRCS+= wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c wcslcat.c wcslcpy.c \ | | 13 | SRCS+= 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 | | 17 | CPPFLAGS.wcscmp.c+= -I${LIBCDIR}/locale |
| | | 18 | CPPFLAGS.wcsncmp.c+= -I${LIBCDIR}/locale |
| | | 19 | CPPFLAGS.wmemcmp.c+= -I${LIBCDIR}/locale |
18 | | | 20 | |
19 | # namespace protection wrappers | | 21 | # namespace protection wrappers |
20 | SRCS+= _strlcat.c _strlcpy.c _strerror_r.c | | 22 | SRCS+= _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 | |
--- 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 |
38 | static char sccsid[] = "@(#)strcmp.c 8.1 (Berkeley) 6/4/93"; | | 38 | static 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 | */ |
51 | int | | 51 | int |
52 | wcscmp(s1, s2) | | 52 | wcscmp(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++) |
--- 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 |
35 | static char sccsid[] = "@(#)strncmp.c 8.1 (Berkeley) 6/4/93"; | | 35 | static 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 | |
45 | int | | 45 | int |
46 | wcsncmp(s1, s2, n) | | 46 | wcsncmp(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 { |
--- 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 | |
40 | int | | 40 | int |
41 | wmemcmp(s1, s2, n) | | 41 | wmemcmp(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++) { |
--- 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 | | | |
51 | The function | | | |
52 | .Fn chmod | | | |
53 | sets the file permission bits | | | |
54 | of the file | | | |
55 | specified by the pathname | | | |
56 | .Fa path | | | |
57 | to | | | |
58 | .Fa mode . | | | |
59 | .Fn fchmod | | | |
60 | sets the permission bits of the specified | | | |
61 | file descriptor | | | |
62 | .Fa fd . | | | |
63 | .Fn lchmod | | | |
64 | is like | | | |
65 | .Fn chmod | | | |
66 | except in the case where the named file is a symbolic link, | | | |
67 | in which case | | | |
68 | .Fn lchmod | | | |
69 | sets the permission bits of the link, | | | |
70 | while | | | |
71 | .Fn chmod | | | |
72 | sets the bits of the file the link references. | | | |
73 | .Fn chmod | | | |
74 | verifies that the process owner (user) either owns | | | |
75 | the file specified by | | | |
76 | .Fa path | | | |
77 | (or | | | |
78 | .Fa fd ) , | | | |
79 | or | | | |
80 | is the super-user. | | | |
81 | A mode is created from | | | |
82 | .Em or'd | | | |
83 | permission bit masks | | | |
84 | defined 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 | | | |
107 | If mode | | | |
108 | .Dv ISVTX | | | |
109 | (the | | | |
110 | .Sq sticky bit ) | | | |
111 | is set on a regular file, it historically meant that the system should | | | |
112 | save a shareable copy of the program text in the swap area. | | | |
113 | When applied to commonly used programs like the shell or editor, this | | | |
114 | would decrease memory usage and startup time. | | | |
115 | In | | | |
116 | .Nx , | | | |
117 | the sticky bit may still be set on regular files by the super-user, | | | |
118 | but has no effect. | | | |
119 | The historical meaning became obsolete in the 1980s with the advent of | | | |
120 | memory-mapped executables, and is only documented as a matter of | | | |
121 | historical interest. | | | |
122 | .Pp | | | |
123 | If mode | | | |
124 | .Dv ISVTX | | | |
125 | (the | | | |
126 | .Sq sticky bit ) | | | |
127 | is set on a directory, | | | |
128 | an unprivileged user may not delete or rename | | | |
129 | files of other users in that directory. | | | |
130 | The sticky bit may be set by any user on a directory which the user | | | |
131 | owns or has appropriate permissions. | | | |
132 | .Pp | | | |
133 | For more information about the properties of the sticky bit, see | | | |
134 | .Xr sticky 7 . | | | |
135 | .Pp | | | |
136 | Changing the owner of a file | | | |
137 | turns off the set-user-id and set-group-id bits; | | | |
138 | writing to a file | | | |
139 | turns off the set-user-id and set-group-id bits | | | |
140 | unless the user is the super-user. | | | |
141 | This makes the system somewhat more secure | | | |
142 | by protecting set-user-id (set-group-id) files | | | |
143 | from remaining set-user-id (set-group-id) if they are modified, | | | |
144 | at the expense of a degree of compatibility. | | | |
145 | .Sh RETURN VALUES | | | |
146 | Upon successful completion, a value of 0 is returned. | | | |
147 | Otherwise, a value of \-1 is returned and | | | |
148 | .Va errno | | | |
149 | is set to indicate the error. | | | |
150 | .Sh ERRORS | | | |
151 | .Fn chmod | | | |
152 | and | | | |
153 | .Fn lchmod | | | |
154 | will fail and the file mode will be unchanged if: | | | |
155 | .Bl -tag -width Er | | | |
156 | .It Bq Er ENOTDIR | | | |
157 | A component of the path prefix is not a directory. | | | |
158 | .It Bq Er ENAMETOOLONG | | | |
159 | A component of a pathname exceeded | | | |
160 | .Dv {NAME_MAX} | | | |
161 | characters, or an entire path name exceeded | | | |
162 | .Dv {PATH_MAX} | | | |
163 | characters. | | | |
164 | .It Bq Er ENOENT | | | |
165 | The named file does not exist. | | | |
166 | .It Bq Er EACCES | | | |
167 | Search permission is denied for a component of the path prefix. | | | |
168 | .It Bq Er ELOOP | | | |
169 | Too many symbolic links were encountered in translating the pathname. | | | |
170 | .It Bq Er EPERM | | | |
171 | The effective user ID does not match the owner of the file and | | | |
172 | the effective user ID is not the super-user. | | | |
173 | .It Bq Er EPERM | | | |
174 | The mode includes the setgid bit | | | |
175 | .Pq Dv S_ISGID | | | |
176 | but the file's group is neither the effective group ID nor is it in the | | | |
177 | group access list. | | | |
178 | .It Bq Er EROFS | | | |
179 | The named file resides on a read-only file system. | | | |
180 | .It Bq Er EFAULT | | | |
181 | .Fa path | | | |
182 | points outside the process's allocated address space. | | | |
183 | .It Bq Er EIO | | | |
184 | An I/O error occurred while reading from or writing to the file system. | | | |
185 | .It Bq Er EFTYPE | | | |
186 | The effective user ID is not the super-user, the | | | |
187 | .Fa mode | | | |
188 | includes the sticky bit | | | |
189 | .Pq Dv S_ISVTX , | | | |
190 | and | | | |
191 | .Fa path | | | |
192 | does not refer to a directory. | | | |
193 | .El | | | |
194 | .Pp | | | |
195 | .Fn fchmod | | | |
196 | will fail if: | | | |
197 | .Bl -tag -width Er | | | |
198 | .It Bq Er EBADF | | | |
199 | The descriptor is not valid. | | | |
200 | .It Bq Er EINVAL | | | |
201 | .Fa fd | | | |
202 | refers to a socket, not to a file. | | | |
203 | .It Bq Er EPERM | | | |
204 | The effective user ID does not match the owner of the file and | | | |
205 | the effective user ID is not the super-user. | | | |
206 | .It Bq Er EPERM | | | |
207 | The mode includes the setgid bit | | | |
208 | .Pq Dv S_ISGID | | | |
209 | but the file's group is neither the effective group ID nor is it in the | | | |
210 | group access list. | | | |
211 | .It Bq Er EROFS | | | |
212 | The file resides on a read-only file system. | | | |
213 | .It Bq Er EIO | | | |
214 | An I/O error occurred while reading from or writing to the file system. | | | |
215 | .It Bq Er EFTYPE | | | |
216 | The effective user ID is not the super-user, the | | | |
217 | .Fa mode | | | |
218 | includes the sticky bit | | | |
219 | .Pq Dv S_ISVTX , | | | |
220 | and | | | |
221 | .Fa fd | | | |
222 | does 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 | | | |
233 | The | | | |
234 | .Fn chmod | | | |
235 | function conforms to | | | |
236 | .St -p1003.1-90 . | | | |
237 | .Sh HISTORY | | | |
238 | The | | | |
239 | .Fn fchmod | | | |
240 | function call | | | |
241 | appeared in | | | |
242 | .Bx 4.2 . | | | |
243 | The | | | |
244 | .Fn lchmod | | | |
245 | function call appeared in | | | |
246 | .Nx 1.3 . | | | |
--- 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 |
104 | The value \-1 is returned if an error occurs in either call. | | 104 | The value \-1 is returned if an error occurs in either call. |
105 | The external variable | | 105 | The external variable |
106 | .Va errno | | 106 | .Va errno |
107 | indicates the cause of the error. | | 107 | indicates the cause of the error. |
108 | .Sh ERRORS | | 108 | .Sh ERRORS |
109 | .Fn dup | | 109 | .Fn dup |
110 | and | | 110 | and |
111 | .Fn dup2 | | 111 | .Fn dup2 |
112 | fail if: | | 112 | fail 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 |
| | | 116 | is not a valid active descriptor |
116 | or | | 117 | or |
117 | .Fa newd | | 118 | .Fa newd |
118 | is not a valid active descriptor | | 119 | is not in the range of valid file descriptors. |
119 | .It Bq Er EMFILE | | 120 | .It Bq Er EMFILE |
120 | Too many descriptors are active. | | 121 | Too 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 |
--- 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 |
42 | This section provides an overview of the system calls, | | 42 | This section provides an overview of the system calls, |
43 | their error returns, and other common definitions and concepts. | | 43 | their 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 |
565 | of the process that created it. | | 565 | of 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" |
567 | Access to system resources is governed by two values: | | 567 | Access to system resources is governed by two values: |
568 | the effective user ID, and the group access list. | | 568 | the effective user ID, and the group access list. |
569 | The first member of the group access list is also known as the | | 569 | The first member of the group access list is also known as the |
570 | effective group ID. | | 570 | effective 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 |
572 | group IDs, and it is unspecified whether the effective group ID is | | 572 | group IDs, and it is unspecified whether the effective group ID is |
573 | a member of the list.) | | 573 | a member of the list.) |
574 | .Pp | | 574 | .Pp |
575 | The effective user ID and effective group ID are initially the | | 575 | The effective user ID and effective group ID are initially the |
576 | process's real user ID and real group ID respectively. | | 576 | process's real user ID and real group ID respectively. |
577 | Either may be modified through execution of a set-user-ID or | | 577 | Either may be modified through execution of a set-user-ID or |
578 | set-group-ID file (possibly by one its ancestors) (see | | 578 | set-group-ID file (possibly by one of its ancestors) (see |
579 | .Xr execve 2 ) . | | 579 | .Xr execve 2 ) . |
580 | By convention, the effective group ID (the first member of the group access | | 580 | By convention, the effective group ID (the first member of the group access |
581 | list) is duplicated, so that the execution of a set-group-ID program | | 581 | list) is duplicated, so that the execution of a set-group-ID program |
582 | does not result in the loss of the original (real) group ID. | | 582 | does not result in the loss of the original (real) group ID. |
583 | .Pp | | 583 | .Pp |
584 | The group access list is a set of group IDs | | 584 | The group access list is a set of group IDs |
585 | used only in determining resource accessibility. | | 585 | used only in determining resource accessibility. |
586 | Access checks are performed as described below in | | 586 | Access 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" |
589 | When a process executes a new file, the effective user ID is set | | 589 | When a process executes a new file, the effective user ID is set |
590 | to the owner of the file if the file is set-user-ID, and the effective | | 590 | to the owner of the file if the file is set-user-ID, and the effective |
591 | group ID (first element of the group access list) is set to the group | | 591 | group ID (first element of the group access list) is set to the group |
--- 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 |
76 | The | | 76 | Currently |
77 | .Fn undelete | | 77 | .Nm |
78 | function attempts to recover the deleted file named by | | 78 | works only when the named object |
79 | .Fa path . | | | |
80 | Currently, this works only when the named object | | | |
81 | is a whiteout in a union filesystem. | | 79 | is a whiteout in a union filesystem. |
82 | The system call removes the whiteout causing | | 80 | The system call removes the whiteout causing |
83 | any objects in a lower layer of the | | 81 | any objects in a lower layer of the |
84 | union stack to become visible once more. | | 82 | union stack to become visible once more. |
85 | .Pp | | | |
86 | Eventually, the | | | |
87 | .Nm undelete | | | |
88 | functionality may be expanded to other filesystems able to recover | | | |
89 | deleted files such as the log-structured filesystem. | | | |
90 | .Sh RETURN VALUES | | 83 | .Sh RETURN VALUES |
91 | Upon successful completion, a value of 0 is returned. | | 84 | Upon successful completion, a value of 0 is returned. |
92 | Otherwise, a value of \-1 is returned and | | 85 | Otherwise, a value of \-1 is returned and |
93 | .Va errno | | 86 | .Va errno |
94 | is set to indicate the error. | | 87 | is set to indicate the error. |
95 | .Sh ERRORS | | 88 | .Sh ERRORS |
96 | The | | 89 | The |
97 | .Fn undelete | | 90 | .Fn undelete |
98 | succeeds unless: | | 91 | succeeds unless: |
99 | .Bl -tag -width ENAMETOOLONGAA | | 92 | .Bl -tag -width ENAMETOOLONGAA |
100 | .It Bq Er ENOTDIR | | 93 | .It Bq Er EACCES |
101 | A component of the path prefix is not a directory. | | 94 | Search permission is denied for a component of the path prefix, or |
| | | 95 | write permission is denied on the directory containing the name |
| | | 96 | to be undeleted. |
| | | 97 | .It Bq Er EEXIST |
| | | 98 | The path does not reference a whiteout. |
| | | 99 | .It Bq Er EFAULT |
| | | 100 | .Fa path |
| | | 101 | points outside the process's allocated address space. |
102 | .It Bq Er EINVAL | | 102 | .It Bq Er EINVAL |
103 | The pathname contains a character with the high-order bit set. | | 103 | The pathname contains a character with the high-order bit set. |
| | | 104 | .It Bq Er EIO |
| | | 105 | An I/O error occurred while updating the directory entry. |
| | | 106 | .It Bq Er ELOOP |
| | | 107 | Too many symbolic links were encountered in translating the pathname. |
104 | .It Bq Er ENAMETOOLONG | | 108 | .It Bq Er ENAMETOOLONG |
105 | A component of a pathname exceeded 255 characters, | | 109 | A component of a pathname exceeded 255 characters, |
106 | or an entire path name exceeded 1023 characters. | | 110 | or an entire path name exceeded 1023 characters. |
107 | .It Bq Er EEXIST | | | |
108 | The path does not reference a whiteout. | | | |
109 | .It Bq Er ENOENT | | 111 | .It Bq Er ENOENT |
110 | The named whiteout does not exist. | | 112 | The named whiteout does not exist. |
111 | .It Bq Er EACCES | | 113 | .It Bq Er ENOTDIR |
112 | Search permission is denied for a component of the path prefix, or | | 114 | A component of the path prefix is not a directory. |
113 | write permission is denied on the directory containing the name | | | |
114 | to be undeleted. | | | |
115 | .It Bq Er ELOOP | | | |
116 | Too many symbolic links were encountered in translating the pathname. | | | |
117 | .It Bq Er EPERM | | 115 | .It Bq Er EPERM |
118 | The directory containing the name is marked sticky, | | 116 | The directory containing the name is marked sticky, |
119 | and the containing directory is not owned by the effective user ID. | | 117 | and the containing directory is not owned by the effective user ID. |
120 | .It Bq Er EIO | | | |
121 | An I/O error occurred while updating the directory entry. | | | |
122 | .It Bq Er EROFS | | 118 | .It Bq Er EROFS |
123 | The name resides on a read-only file system. | | 119 | The name resides on a read-only file system. |
124 | .It Bq Er EFAULT | | | |
125 | .Fa path | | | |
126 | points 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 |
132 | An | | 125 | An |
133 | .Nm undelete | | 126 | .Nm undelete |
134 | function call first appeared in | | 127 | function call first appeared in |
135 | .Bx 4.4 -Lite . | | 128 | .Bx 4.4 -Lite . |