Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_NLS_H |
| 2 | #define _LINUX_NLS_H |
| 3 | |
| 4 | #include <linux/init.h> |
| 5 | |
| 6 | /* unicode character */ |
| 7 | typedef __u16 wchar_t; |
| 8 | |
| 9 | struct nls_table { |
Denys Vlasenko | b9ec033 | 2007-10-16 23:29:54 -0700 | [diff] [blame] | 10 | const char *charset; |
| 11 | const char *alias; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | int (*uni2char) (wchar_t uni, unsigned char *out, int boundlen); |
| 13 | int (*char2uni) (const unsigned char *rawstring, int boundlen, |
| 14 | wchar_t *uni); |
Denys Vlasenko | b9ec033 | 2007-10-16 23:29:54 -0700 | [diff] [blame] | 15 | const unsigned char *charset2lower; |
| 16 | const unsigned char *charset2upper; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | struct module *owner; |
| 18 | struct nls_table *next; |
| 19 | }; |
| 20 | |
| 21 | /* this value hold the maximum octet of charset */ |
| 22 | #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */ |
| 23 | |
| 24 | /* nls.c */ |
| 25 | extern int register_nls(struct nls_table *); |
| 26 | extern int unregister_nls(struct nls_table *); |
| 27 | extern struct nls_table *load_nls(char *); |
| 28 | extern void unload_nls(struct nls_table *); |
| 29 | extern struct nls_table *load_nls_default(void); |
| 30 | |
| 31 | extern int utf8_mbtowc(wchar_t *, const __u8 *, int); |
| 32 | extern int utf8_mbstowcs(wchar_t *, const __u8 *, int); |
| 33 | extern int utf8_wctomb(__u8 *, wchar_t, int); |
| 34 | extern int utf8_wcstombs(__u8 *, const wchar_t *, int); |
| 35 | |
| 36 | static inline unsigned char nls_tolower(struct nls_table *t, unsigned char c) |
| 37 | { |
| 38 | unsigned char nc = t->charset2lower[c]; |
| 39 | |
| 40 | return nc ? nc : c; |
| 41 | } |
| 42 | |
| 43 | static inline unsigned char nls_toupper(struct nls_table *t, unsigned char c) |
| 44 | { |
| 45 | unsigned char nc = t->charset2upper[c]; |
| 46 | |
| 47 | return nc ? nc : c; |
| 48 | } |
| 49 | |
| 50 | static inline int nls_strnicmp(struct nls_table *t, const unsigned char *s1, |
| 51 | const unsigned char *s2, int len) |
| 52 | { |
| 53 | while (len--) { |
| 54 | if (nls_tolower(t, *s1++) != nls_tolower(t, *s2++)) |
| 55 | return 1; |
| 56 | } |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
Jeff Layton | d37dc42 | 2009-04-30 06:45:08 -0400 | [diff] [blame] | 61 | /* |
| 62 | * nls_nullsize - return length of null character for codepage |
| 63 | * @codepage - codepage for which to return length of NULL terminator |
| 64 | * |
| 65 | * Since we can't guarantee that the null terminator will be a particular |
| 66 | * length, we have to check against the codepage. If there's a problem |
| 67 | * determining it, assume a single-byte NULL terminator. |
| 68 | */ |
| 69 | static inline int |
| 70 | nls_nullsize(const struct nls_table *codepage) |
| 71 | { |
| 72 | int charlen; |
| 73 | char tmp[NLS_MAX_CHARSET_SIZE]; |
| 74 | |
| 75 | charlen = codepage->uni2char(0, tmp, NLS_MAX_CHARSET_SIZE); |
| 76 | |
| 77 | return charlen > 0 ? charlen : 1; |
| 78 | } |
| 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | #define MODULE_ALIAS_NLS(name) MODULE_ALIAS("nls_" __stringify(name)) |
| 81 | |
| 82 | #endif /* _LINUX_NLS_H */ |
| 83 | |