xref: /minix/lib/libc/citrus/citrus_lc_ctype.c (revision 84d9c625)
1 /* $NetBSD: citrus_lc_ctype.c,v 1.15 2013/09/13 13:13:32 joerg Exp $ */
2 
3 /*-
4  * Copyright (c)2008 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 #include <sys/cdefs.h>
30 #if defined(LIBC_SCCS) && !defined(lint)
31 __RCSID("$NetBSD: citrus_lc_ctype.c,v 1.15 2013/09/13 13:13:32 joerg Exp $");
32 #endif /* LIBC_SCCS and not lint */
33 
34 #include "reentrant.h"
35 #include <sys/types.h>
36 #include <sys/ctype_bits.h>
37 #include <sys/queue.h>
38 #include <assert.h>
39 #include <errno.h>
40 #include <langinfo.h>
41 #include <limits.h>
42 #define __SETLOCALE_SOURCE__
43 #include <locale.h>
44 #include <stddef.h>
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <wchar.h>
49 
50 #include "setlocale_local.h"
51 
52 #include "citrus_namespace.h"
53 #include "citrus_bcs.h"
54 #include "citrus_region.h"
55 #include "citrus_lookup.h"
56 #include "citrus_aliasname_local.h"
57 #include "citrus_module.h"
58 #include "citrus_ctype.h"
59 #include "citrus_mmap.h"
60 
61 #include "runetype_local.h"
62 #include "multibyte.h"
63 
64 /*
65  * macro required by all template headers
66  */
67 #define _PREFIX(name)		__CONCAT(_citrus_LC_CTYPE_, name)
68 
69 /*
70  * macro required by nb_lc_template(_decl).h
71  */
72 #define _CATEGORY_TYPE          _RuneLocale
73 
74 #include "nb_lc_template_decl.h"
75 
76 static int
_citrus_LC_CTYPE_create_impl(const char * __restrict root,const char * __restrict name,_RuneLocale ** __restrict pdata)77 _citrus_LC_CTYPE_create_impl(const char * __restrict root,
78     const char * __restrict name, _RuneLocale ** __restrict pdata)
79 {
80 	char path[PATH_MAX + 1];
81 	int ret;
82 	struct _region r;
83 
84 	_DIAGASSERT(root != NULL);
85 	_DIAGASSERT(name != NULL);
86 	_DIAGASSERT(pdata != NULL);
87 
88 	snprintf(path, sizeof(path),
89 	    "%s/%s/LC_CTYPE", root, name);
90 	ret = _citrus_map_file(&r, path);
91 	if (!ret) {
92 		ret = _rune_load((const char *)r.r_head, r.r_size, pdata);
93 		_citrus_unmap_file(&r);
94 	}
95 	return ret;
96 }
97 
98 static __inline void
_PREFIX(update_global)99 _PREFIX(update_global)(_RuneLocale *data)
100 {
101 	_DIAGASSERT(data != NULL);
102 
103 	__mb_cur_max = _citrus_ctype_get_mb_cur_max(data->rl_citrus_ctype);
104 	_ctype_tab_ = data->rl_ctype_tab;
105 	_tolower_tab_ = data->rl_tolower_tab;
106 	_toupper_tab_ = data->rl_toupper_tab;
107 
108 #ifdef __BUILD_LEGACY
109 	_ctype_ = data->rl_compat_bsdctype;
110 #endif
111 }
112 
113 /*
114  * macro required by nb_lc_template.h
115  */
116 #define _CATEGORY_ID		LC_CTYPE
117 #define _CATEGORY_NAME		"LC_CTYPE"
118 
119 #include "nb_lc_template.h"
120