| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #ifndef _LINUX_NLS_H
 | 
					
						
							|  |  |  | #define _LINUX_NLS_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/init.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-30 10:08:18 -04:00
										 |  |  | /* Unicode has changed over the years.  Unicode code points no longer
 | 
					
						
							|  |  |  |  * fit into 16 bits; as of Unicode 5 valid code points range from 0 | 
					
						
							|  |  |  |  * to 0x10ffff (17 planes, where each plane holds 65536 code points). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The original decision to represent Unicode characters as 16-bit | 
					
						
							|  |  |  |  * wchar_t values is now outdated.  But plane 0 still includes the | 
					
						
							|  |  |  |  * most commonly used characters, so we will retain it.  The newer | 
					
						
							|  |  |  |  * 32-bit unicode_t type can be used when it is necessary to | 
					
						
							|  |  |  |  * represent the full Unicode character set. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Plane-0 Unicode character */ | 
					
						
							|  |  |  | typedef u16 wchar_t; | 
					
						
							|  |  |  | #define MAX_WCHAR_T	0xffff
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Arbitrary Unicode character */ | 
					
						
							|  |  |  | typedef u32 unicode_t; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | struct nls_table { | 
					
						
							| 
									
										
										
										
											2007-10-16 23:29:54 -07:00
										 |  |  | 	const char *charset; | 
					
						
							|  |  |  | 	const char *alias; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	int (*uni2char) (wchar_t uni, unsigned char *out, int boundlen); | 
					
						
							|  |  |  | 	int (*char2uni) (const unsigned char *rawstring, int boundlen, | 
					
						
							|  |  |  | 			 wchar_t *uni); | 
					
						
							| 
									
										
										
										
											2007-10-16 23:29:54 -07:00
										 |  |  | 	const unsigned char *charset2lower; | 
					
						
							|  |  |  | 	const unsigned char *charset2upper; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	struct module *owner; | 
					
						
							|  |  |  | 	struct nls_table *next; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* this value hold the maximum octet of charset */ | 
					
						
							|  |  |  | #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-30 10:08:18 -04:00
										 |  |  | /* Byte order for UTF-16 strings */ | 
					
						
							|  |  |  | enum utf16_endian { | 
					
						
							|  |  |  | 	UTF16_HOST_ENDIAN, | 
					
						
							|  |  |  | 	UTF16_LITTLE_ENDIAN, | 
					
						
							|  |  |  | 	UTF16_BIG_ENDIAN | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-17 16:42:19 -05:00
										 |  |  | /* nls_base.c */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | extern int register_nls(struct nls_table *); | 
					
						
							|  |  |  | extern int unregister_nls(struct nls_table *); | 
					
						
							|  |  |  | extern struct nls_table *load_nls(char *); | 
					
						
							|  |  |  | extern void unload_nls(struct nls_table *); | 
					
						
							|  |  |  | extern struct nls_table *load_nls_default(void); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-30 10:08:18 -04:00
										 |  |  | extern int utf8_to_utf32(const u8 *s, int len, unicode_t *pu); | 
					
						
							|  |  |  | extern int utf32_to_utf8(unicode_t u, u8 *s, int maxlen); | 
					
						
							| 
									
										
										
										
											2011-11-17 16:42:19 -05:00
										 |  |  | extern int utf8s_to_utf16s(const u8 *s, int len, | 
					
						
							|  |  |  | 		enum utf16_endian endian, wchar_t *pwcs, int maxlen); | 
					
						
							| 
									
										
										
										
											2009-04-30 10:08:18 -04:00
										 |  |  | extern int utf16s_to_utf8s(const wchar_t *pwcs, int len, | 
					
						
							|  |  |  | 		enum utf16_endian endian, u8 *s, int maxlen); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | static inline unsigned char nls_tolower(struct nls_table *t, unsigned char c) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned char nc = t->charset2lower[c]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nc ? nc : c; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline unsigned char nls_toupper(struct nls_table *t, unsigned char c) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned char nc = t->charset2upper[c]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nc ? nc : c; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline int nls_strnicmp(struct nls_table *t, const unsigned char *s1, | 
					
						
							|  |  |  | 		const unsigned char *s2, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	while (len--) { | 
					
						
							|  |  |  | 		if (nls_tolower(t, *s1++) != nls_tolower(t, *s2++)) | 
					
						
							|  |  |  | 			return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-30 06:45:08 -04:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * nls_nullsize - return length of null character for codepage | 
					
						
							|  |  |  |  * @codepage - codepage for which to return length of NULL terminator | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Since we can't guarantee that the null terminator will be a particular | 
					
						
							|  |  |  |  * length, we have to check against the codepage. If there's a problem | 
					
						
							|  |  |  |  * determining it, assume a single-byte NULL terminator. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static inline int | 
					
						
							|  |  |  | nls_nullsize(const struct nls_table *codepage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int charlen; | 
					
						
							|  |  |  | 	char tmp[NLS_MAX_CHARSET_SIZE]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	charlen = codepage->uni2char(0, tmp, NLS_MAX_CHARSET_SIZE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return charlen > 0 ? charlen : 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #define MODULE_ALIAS_NLS(name)	MODULE_ALIAS("nls_" __stringify(name))
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* _LINUX_NLS_H */
 | 
					
						
							|  |  |  | 
 |