patch-2.4.4 linux/fs/nls/nls_cp932.c
Next file: linux/fs/nls/nls_euc-jp.c
Previous file: linux/fs/nls/nls_cp1255.c
Back to the patch index
Back to the overall index
- Lines: 92
- Date:
Fri Apr 6 10:51:19 2001
- Orig file:
v2.4.3/linux/fs/nls/nls_cp932.c
- Orig date:
Fri Jul 21 15:19:51 2000
diff -u --recursive --new-file v2.4.3/linux/fs/nls/nls_cp932.c linux/fs/nls/nls_cp932.c
@@ -7819,73 +7819,68 @@
};
static int uni2char(const wchar_t uni,
- unsigned char *out, int boundlen)
+ unsigned char *out, int boundlen)
{
unsigned char *uni2charset;
unsigned char cl = uni&0xFF;
unsigned char ch = (uni>>8)&0xFF;
- int n;
if (boundlen <= 0)
return -ENAMETOOLONG;
if (ch == 0xFF && 0x61 <= cl && cl <= 0x9F) {
out[0] = cl + 0x40;
- n = 1;
- return n;
+ return 1;
}
uni2charset = page_uni2charset[ch];
if (uni2charset) {
- if (boundlen <= 1)
+ if (boundlen < 2)
return -ENAMETOOLONG;
+
out[0] = uni2charset[cl*2];
out[1] = uni2charset[cl*2+1];
if (out[0] == 0x00 && out[1] == 0x00)
return -EINVAL;
- n = 2;
- } else if (ch==0 && cl) {
+ return 2;
+ } else if ((ch == 0) && (cl <= 0x7F)) {
out[0] = cl;
- n = 1;
+ return 1;
}
else
return -EINVAL;
-
- return n;
}
static int char2uni(const unsigned char *rawstring, int boundlen,
- wchar_t *uni)
+ wchar_t *uni)
{
unsigned char ch, cl;
wchar_t *charset2uni;
- int n;
if (boundlen <= 0)
return -ENAMETOOLONG;
- if (boundlen == 1) {
+ if (rawstring[0] <= 0x7F) {
*uni = rawstring[0];
return 1;
}
+ if (0xA1 <= rawstring[0] && rawstring[0] <= 0xDF) {
+ *uni = 0xFF00 | (rawstring[0] - 0x40);
+ return 1;
+ }
+ if (boundlen < 2)
+ return -ENAMETOOLONG;
ch = rawstring[0];
cl = rawstring[1];
- if (0xA1 <= ch && ch <= 0xDF) {
- *uni = 0xFF00 | (ch - 0x40);
- n = 1;
- return n;
- }
charset2uni = page_charset2uni[ch];
if (charset2uni && cl) {
*uni = charset2uni[cl];
if (*uni == 0x0000)
return -EINVAL;
- n = 2;
- } else{
- *uni = ch;
- n = 1;
+ return 2;
}
- return n;
+ else
+ return -EINVAL;
}
static struct nls_table table = {
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)