2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Andrew Tridgell 1992-2001
5 Copyright (C) Simo Sorce 2001
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "system/locale.h"
23 #include "dynconfig/dynconfig.h"
27 * @brief Unicode string manipulation
30 /* these 2 tables define the unicode case handling. They are loaded
31 at startup either via mmap() or read() from the lib directory */
32 static void *upcase_table
;
33 static void *lowcase_table
;
36 /*******************************************************************
37 load the case handling tables
38 ********************************************************************/
39 void load_case_tables(void)
43 mem_ctx
= talloc_init("load_case_tables");
45 smb_panic("No memory for case_tables");
47 upcase_table
= map_file(talloc_asprintf(mem_ctx
, "%s/upcase.dat", dyn_DATADIR
), 0x20000);
48 lowcase_table
= map_file(talloc_asprintf(mem_ctx
, "%s/lowcase.dat", dyn_DATADIR
), 0x20000);
50 if (upcase_table
== NULL
) {
51 /* try also under codepages for testing purposes */
52 upcase_table
= map_file("codepages/upcase.dat", 0x20000);
53 if (upcase_table
== NULL
) {
54 upcase_table
= (void *)-1;
57 if (lowcase_table
== NULL
) {
58 /* try also under codepages for testing purposes */
59 lowcase_table
= map_file("codepages/lowcase.dat", 0x20000);
60 if (lowcase_table
== NULL
) {
61 lowcase_table
= (void *)-1;
67 Convert a codepoint_t to upper case.
69 _PUBLIC_ codepoint_t
toupper_m(codepoint_t val
)
74 if (upcase_table
== NULL
) {
77 if (upcase_table
== (void *)-1) {
80 if (val
& 0xFFFF0000) {
83 return SVAL(upcase_table
, val
*2);
87 Convert a codepoint_t to lower case.
89 _PUBLIC_ codepoint_t
tolower_m(codepoint_t val
)
94 if (lowcase_table
== NULL
) {
97 if (lowcase_table
== (void *)-1) {
100 if (val
& 0xFFFF0000) {
103 return SVAL(lowcase_table
, val
*2);
107 compare two codepoints case insensitively
109 _PUBLIC_
int codepoint_cmpi(codepoint_t c1
, codepoint_t c2
)
112 toupper_m(c1
) == toupper_m(c2
)) {