2 * Copyright 2013 Garrett D'Amore <garrett@damore.org>
3 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Paul Borman at Krystal Technologies.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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 * 4. 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.
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
47 #include "setlocale.h"
50 #include "localeimpl.h"
52 extern _RuneLocale
*_Read_RuneMagi(const char *);
54 struct lc_ctype lc_ctype_posix
= {
55 .lc_mbrtowc
= __mbrtowc_ascii
,
56 .lc_mbsinit
= __mbsinit_ascii
,
57 .lc_mbsnrtowcs
= __mbsnrtowcs_ascii
,
58 .lc_wcrtomb
= __wcrtomb_ascii
,
59 .lc_wcsnrtombs
= __wcsnrtombs_ascii
,
62 .lc_trans_upper
= _DefaultRuneLocale
.__mapupper
,
63 .lc_trans_lower
= _DefaultRuneLocale
.__maplower
,
64 .lc_ctype_mask
= _DefaultRuneLocale
.__runetype
,
67 struct locdata __posix_ctype_locdata
= {
69 .l_data
= { &lc_ctype_posix
, &_DefaultRuneLocale
}
74 * Table of initializers for encodings. When you add a new encoding type,
75 * this table should be updated.
79 void (*e_init
)(struct lc_ctype
*);
81 { "NONE", _none_init
},
82 { "UTF-8", _UTF8_init
},
83 { "EUC-CN", _EUC_CN_init
},
84 { "EUC-JP", _EUC_JP_init
},
85 { "EUC-KR", _EUC_KR_init
},
86 { "EUC-TW", _EUC_TW_init
},
87 { "GB18030", _GB18030_init
},
88 { "GB2312", _GB2312_init
},
90 { "BIG5", _BIG5_init
},
91 { "MSKanji", _MSKanji_init
},
97 __lc_ctype_load(const char *name
)
99 struct locdata
*ldata
;
100 struct lc_ctype
*lct
;
105 if ((ldata
= __locdata_alloc(name
, sizeof (*lct
))) == NULL
)
107 lct
= ldata
->l_data
[0];
109 * Slurp the locale file into the cache.
112 (void) snprintf(path
, sizeof (path
), "%s/%s/LC_CTYPE/LCL_DATA",
115 if ((rl
= _Read_RuneMagi(path
)) == NULL
) {
116 __locdata_free(ldata
);
120 ldata
->l_data
[1] = rl
;
122 lct
->lc_mbrtowc
= NULL
;
123 lct
->lc_mbsinit
= NULL
;
124 lct
->lc_mbsnrtowcs
= NULL
;
125 lct
->lc_wcrtomb
= NULL
;
126 lct
->lc_wcsnrtombs
= NULL
;
127 lct
->lc_ctype_mask
= rl
->__runetype
;
128 lct
->lc_trans_upper
= rl
->__mapupper
;
129 lct
->lc_trans_lower
= rl
->__maplower
;
131 /* set up the function pointers */
132 for (i
= 0; encodings
[i
].e_name
!= NULL
; i
++) {
133 int l
= strlen(encodings
[i
].e_name
);
134 if ((strncmp(rl
->__encoding
, encodings
[i
].e_name
, l
) == 0) &&
135 (rl
->__encoding
[l
] == '\0' || rl
->__encoding
[l
] == '@')) {
136 encodings
[i
].e_init(lct
);
140 if (encodings
[i
].e_name
== NULL
) {
141 __locdata_free(ldata
);