1#ifndef _LINUX_NLS_H
2#define _LINUX_NLS_H
3
4#include <linux/init.h>
5
6
7
8
9
10
11
12
13
14
15
16
17
18typedef u16 wchar_t;
19#define MAX_WCHAR_T 0xffff
20
21
22typedef u32 unicode_t;
23
24struct nls_table {
25 const char *charset;
26 const char *alias;
27 int (*uni2char) (wchar_t uni, unsigned char *out, int boundlen);
28 int (*char2uni) (const unsigned char *rawstring, int boundlen,
29 wchar_t *uni);
30 const unsigned char *charset2lower;
31 const unsigned char *charset2upper;
32 struct module *owner;
33 struct nls_table *next;
34};
35
36
37#define NLS_MAX_CHARSET_SIZE 6
38
39
40enum utf16_endian {
41 UTF16_HOST_ENDIAN,
42 UTF16_LITTLE_ENDIAN,
43 UTF16_BIG_ENDIAN
44};
45
46
47extern int register_nls(struct nls_table *);
48extern int unregister_nls(struct nls_table *);
49extern struct nls_table *load_nls(char *);
50extern void unload_nls(struct nls_table *);
51extern struct nls_table *load_nls_default(void);
52
53extern int utf8_to_utf32(const u8 *s, int len, unicode_t *pu);
54extern int utf32_to_utf8(unicode_t u, u8 *s, int maxlen);
55extern int utf8s_to_utf16s(const u8 *s, int len, wchar_t *pwcs);
56extern int utf16s_to_utf8s(const wchar_t *pwcs, int len,
57 enum utf16_endian endian, u8 *s, int maxlen);
58
59static inline unsigned char nls_tolower(struct nls_table *t, unsigned char c)
60{
61 unsigned char nc = t->charset2lower[c];
62
63 return nc ? nc : c;
64}
65
66static inline unsigned char nls_toupper(struct nls_table *t, unsigned char c)
67{
68 unsigned char nc = t->charset2upper[c];
69
70 return nc ? nc : c;
71}
72
73static inline int nls_strnicmp(struct nls_table *t, const unsigned char *s1,
74 const unsigned char *s2, int len)
75{
76 while (len--) {
77 if (nls_tolower(t, *s1++) != nls_tolower(t, *s2++))
78 return 1;
79 }
80
81 return 0;
82}
83
84
85
86
87
88
89
90
91
92static inline int
93nls_nullsize(const struct nls_table *codepage)
94{
95 int charlen;
96 char tmp[NLS_MAX_CHARSET_SIZE];
97
98 charlen = codepage->uni2char(0, tmp, NLS_MAX_CHARSET_SIZE);
99
100 return charlen > 0 ? charlen : 1;
101}
102
103#define MODULE_ALIAS_NLS(name) MODULE_ALIAS("nls_" __stringify(name))
104
105#endif
106
107