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

TOMOYO Linux Cross Reference
Linux/fs/nls/nls_koi8-ru.c

Version: ~ [ linux-5.16 ] ~ [ linux-5.15.13 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.90 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.170 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.224 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.261 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.296 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.298 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ 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.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * linux/fs/nls/nls_koi8-ru.c
  3  *
  4  * Charset koi8-ru translation based on charset koi8-u.
  5  * The Unicode to charset table has only exact mappings.
  6  */
  7 
  8 #include <linux/module.h>
  9 #include <linux/kernel.h>
 10 #include <linux/string.h>
 11 #include <linux/nls.h>
 12 #include <linux/errno.h>
 13 
 14 static struct nls_table *p_nls;
 15 
 16 static int uni2char(const wchar_t uni,
 17                     unsigned char *out, int boundlen)
 18 {
 19         if (boundlen <= 0)
 20                 return -ENAMETOOLONG;
 21 
 22         if ((uni & 0xffaf) == 0x040e || (uni & 0xffce) == 0x254c) {
 23                 /* koi8-ru and koi8-u differ only on two characters */
 24                 if (uni == 0x040e)
 25                         out[0] = 0xbe;
 26                 else if (uni == 0x045e)
 27                         out[0] = 0xae;
 28                 else if (uni == 0x255d || uni == 0x256c)
 29                         return 0;
 30                 else
 31                         return p_nls->uni2char(uni, out, boundlen);
 32                 return 1;
 33         }
 34         else
 35                 /* fast path */
 36                 return p_nls->uni2char(uni, out, boundlen);
 37 }
 38 
 39 static int char2uni(const unsigned char *rawstring, int boundlen,
 40                     wchar_t *uni)
 41 {
 42         int n;
 43 
 44         if ((*rawstring & 0xef) != 0xae) {
 45                 /* koi8-ru and koi8-u differ only on two characters */
 46                 *uni = (*rawstring & 0x10) ? 0x040e : 0x045e;
 47                 return 1;
 48         }
 49 
 50         n = p_nls->char2uni(rawstring, boundlen, uni);
 51         return n;
 52 }
 53 
 54 static struct nls_table table = {
 55         .charset        = "koi8-ru",
 56         .uni2char       = uni2char,
 57         .char2uni       = char2uni,
 58 };
 59 
 60 static int __init init_nls_koi8_ru(void)
 61 {
 62         p_nls = load_nls("koi8-u");
 63 
 64         if (p_nls) {
 65                 table.charset2upper = p_nls->charset2upper;
 66                 table.charset2lower = p_nls->charset2lower;
 67                 return register_nls(&table);
 68         }
 69 
 70         return -EINVAL;
 71 }
 72 
 73 static void __exit exit_nls_koi8_ru(void)
 74 {
 75         unregister_nls(&table);
 76         unload_nls(p_nls);
 77 }
 78 
 79 module_init(init_nls_koi8_ru)
 80 module_exit(exit_nls_koi8_ru)
 81 
 82 MODULE_LICENSE("Dual BSD/GPL");
 83 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp