~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/nls.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _LINUX_NLS_H
  3 #define _LINUX_NLS_H
  4 
  5 #include <linux/init.h>
  6 
  7 /* Unicode has changed over the years.  Unicode code points no longer
  8  * fit into 16 bits; as of Unicode 5 valid code points range from 0
  9  * to 0x10ffff (17 planes, where each plane holds 65536 code points).
 10  *
 11  * The original decision to represent Unicode characters as 16-bit
 12  * wchar_t values is now outdated.  But plane 0 still includes the
 13  * most commonly used characters, so we will retain it.  The newer
 14  * 32-bit unicode_t type can be used when it is necessary to
 15  * represent the full Unicode character set.
 16  */
 17 
 18 /* Plane-0 Unicode character */
 19 typedef u16 wchar_t;
 20 #define MAX_WCHAR_T     0xffff
 21 
 22 /* Arbitrary Unicode character */
 23 typedef u32 unicode_t;
 24 
 25 struct nls_table {
 26         const char *charset;
 27         const char *alias;
 28         int (*uni2char) (wchar_t uni, unsigned char *out, int boundlen);
 29         int (*char2uni) (const unsigned char *rawstring, int boundlen,
 30                          wchar_t *uni);
 31         const unsigned char *charset2lower;
 32         const unsigned char *charset2upper;
 33         struct module *owner;
 34         struct nls_table *next;
 35 };
 36 
 37 /* this value hold the maximum octet of charset */
 38 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
 39 
 40 /* Byte order for UTF-16 strings */
 41 enum utf16_endian {
 42         UTF16_HOST_ENDIAN,
 43         UTF16_LITTLE_ENDIAN,
 44         UTF16_BIG_ENDIAN
 45 };
 46 
 47 /* nls_base.c */
 48 extern int __register_nls(struct nls_table *, struct module *);
 49 extern int unregister_nls(struct nls_table *);
 50 extern struct nls_table *load_nls(const char *charset);
 51 extern void unload_nls(struct nls_table *);
 52 extern struct nls_table *load_nls_default(void);
 53 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
 54 
 55 extern int utf8_to_utf32(const u8 *s, int len, unicode_t *pu);
 56 extern int utf32_to_utf8(unicode_t u, u8 *s, int maxlen);
 57 extern int utf8s_to_utf16s(const u8 *s, int len,
 58                 enum utf16_endian endian, wchar_t *pwcs, int maxlen);
 59 extern int utf16s_to_utf8s(const wchar_t *pwcs, int len,
 60                 enum utf16_endian endian, u8 *s, int maxlen);
 61 
 62 static inline unsigned char nls_tolower(struct nls_table *t, unsigned char c)
 63 {
 64         unsigned char nc = t->charset2lower[c];
 65 
 66         return nc ? nc : c;
 67 }
 68 
 69 static inline unsigned char nls_toupper(struct nls_table *t, unsigned char c)
 70 {
 71         unsigned char nc = t->charset2upper[c];
 72 
 73         return nc ? nc : c;
 74 }
 75 
 76 static inline int nls_strnicmp(struct nls_table *t, const unsigned char *s1,
 77                 const unsigned char *s2, int len)
 78 {
 79         while (len--) {
 80                 if (nls_tolower(t, *s1++) != nls_tolower(t, *s2++))
 81                         return 1;
 82         }
 83 
 84         return 0;
 85 }
 86 
 87 /*
 88  * nls_nullsize - return length of null character for codepage
 89  * @codepage - codepage for which to return length of NULL terminator
 90  *
 91  * Since we can't guarantee that the null terminator will be a particular
 92  * length, we have to check against the codepage. If there's a problem
 93  * determining it, assume a single-byte NULL terminator.
 94  */
 95 static inline int
 96 nls_nullsize(const struct nls_table *codepage)
 97 {
 98         int charlen;
 99         char tmp[NLS_MAX_CHARSET_SIZE];
100 
101         charlen = codepage->uni2char(0, tmp, NLS_MAX_CHARSET_SIZE);
102 
103         return charlen > 0 ? charlen : 1;
104 }
105 
106 #define MODULE_ALIAS_NLS(name)  MODULE_ALIAS("nls_" __stringify(name))
107 
108 #endif /* _LINUX_NLS_H */
109 
110 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php