0001
0002 #ifndef _LINUX_NLS_H
0003 #define _LINUX_NLS_H
0004
0005 #include <linux/init.h>
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 typedef u16 wchar_t;
0020 #define MAX_WCHAR_T 0xffff
0021
0022
0023 typedef u32 unicode_t;
0024
0025 struct nls_table {
0026 const char *charset;
0027 const char *alias;
0028 int (*uni2char) (wchar_t uni, unsigned char *out, int boundlen);
0029 int (*char2uni) (const unsigned char *rawstring, int boundlen,
0030 wchar_t *uni);
0031 const unsigned char *charset2lower;
0032 const unsigned char *charset2upper;
0033 struct module *owner;
0034 struct nls_table *next;
0035 };
0036
0037
0038 #define NLS_MAX_CHARSET_SIZE 6
0039
0040
0041 enum utf16_endian {
0042 UTF16_HOST_ENDIAN,
0043 UTF16_LITTLE_ENDIAN,
0044 UTF16_BIG_ENDIAN
0045 };
0046
0047
0048 extern int __register_nls(struct nls_table *, struct module *);
0049 extern int unregister_nls(struct nls_table *);
0050 extern struct nls_table *load_nls(char *);
0051 extern void unload_nls(struct nls_table *);
0052 extern struct nls_table *load_nls_default(void);
0053 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
0054
0055 extern int utf8_to_utf32(const u8 *s, int len, unicode_t *pu);
0056 extern int utf32_to_utf8(unicode_t u, u8 *s, int maxlen);
0057 extern int utf8s_to_utf16s(const u8 *s, int len,
0058 enum utf16_endian endian, wchar_t *pwcs, int maxlen);
0059 extern int utf16s_to_utf8s(const wchar_t *pwcs, int len,
0060 enum utf16_endian endian, u8 *s, int maxlen);
0061
0062 static inline unsigned char nls_tolower(struct nls_table *t, unsigned char c)
0063 {
0064 unsigned char nc = t->charset2lower[c];
0065
0066 return nc ? nc : c;
0067 }
0068
0069 static inline unsigned char nls_toupper(struct nls_table *t, unsigned char c)
0070 {
0071 unsigned char nc = t->charset2upper[c];
0072
0073 return nc ? nc : c;
0074 }
0075
0076 static inline int nls_strnicmp(struct nls_table *t, const unsigned char *s1,
0077 const unsigned char *s2, int len)
0078 {
0079 while (len--) {
0080 if (nls_tolower(t, *s1++) != nls_tolower(t, *s2++))
0081 return 1;
0082 }
0083
0084 return 0;
0085 }
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095 static inline int
0096 nls_nullsize(const struct nls_table *codepage)
0097 {
0098 int charlen;
0099 char tmp[NLS_MAX_CHARSET_SIZE];
0100
0101 charlen = codepage->uni2char(0, tmp, NLS_MAX_CHARSET_SIZE);
0102
0103 return charlen > 0 ? charlen : 1;
0104 }
0105
0106 #define MODULE_ALIAS_NLS(name) MODULE_ALIAS("nls_" __stringify(name))
0107
0108 #endif
0109