| Start/ | End/ | |||
| True | False | - | Line | Source |
| 1 | /* | |||
| 2 | * fs/cifs/cifs_unicode.c | |||
| 3 | * | |||
| 4 | * Copyright (c) International Business Machines Corp., 2000,2005 | |||
| 5 | * Modified by Steve French (sfrench@us.ibm.com) | |||
| 6 | * | |||
| 7 | * This program is free software; you can redistribute it and/or modify | |||
| 8 | * it under the terms of the GNU General Public License as published by | |||
| 9 | * the Free Software Foundation; either version 2 of the License, or | |||
| 10 | * (at your option) any later version. | |||
| 11 | * | |||
| 12 | * This program is distributed in the hope that it will be useful, | |||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | |||
| 15 | * the GNU General Public License for more details. | |||
| 16 | * | |||
| 17 | * You should have received a copy of the GNU General Public License | |||
| 18 | * along with this program; if not, write to the Free Software | |||
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
| 20 | */ | |||
| 21 | #include <linux/fs.h> | |||
| 22 | #include "cifs_unicode.h" | |||
| 23 | #include "cifs_uniupr.h" | |||
| 24 | #include "cifspdu.h" | |||
| 25 | #include "cifs_debug.h" | |||
| 26 | ||||
| 27 | /* | |||
| 28 | * NAME: cifs_strfromUCS() | |||
| 29 | * | |||
| 30 | * FUNCTION: Convert little-endian unicode string to character string | |||
| 31 | * | |||
| 32 | */ | |||
| 33 | int | |||
| 0 | 0 | - | 34 | cifs_strfromUCS_le(char *to, const __le16 * from, |
| 35 | int len, const struct nls_table *codepage) | |||
| 36 | { | |||
| 37 | int i; | |||
| 38 | int outlen = 0; | |||
| 39 | ||||
| 0 | 0 | - | 40 | for (i = 0; (i < len) && from[i]; i++) { |
| 0 | - | 40 | (T) && T | |
| 0 | - | 40 | (T) && F | |
| 0 | - | 40 | (F) && _ | |
| 41 | int charlen; | |||
| 42 | /* 2.4.0 kernel or greater */ | |||
| 43 | charlen = | |||
| 44 | codepage->uni2char(le16_to_cpu(from[i]), &to[outlen], | |||
| 45 | NLS_MAX_CHARSET_SIZE); | |||
| 0 | 0 | - | 46 | if (charlen > 0) { |
| 47 | outlen += charlen; | |||
| 48 | } else { | |||
| 49 | to[outlen++] = '?'; | |||
| 50 | } | |||
| 51 | } | |||
| 52 | to[outlen] = 0; | |||
| 0 | - | 53 | return outlen; | |
| 54 | } | |||
| 55 | ||||
| 56 | /* | |||
| 57 | * NAME: cifs_strtoUCS() | |||
| 58 | * | |||
| 59 | * FUNCTION: Convert character string to unicode string | |||
| 60 | * | |||
| 61 | */ | |||
| 62 | int | |||
| 0 | 0 | - | 63 | cifs_strtoUCS(__le16 * to, const char *from, int len, |
| 64 | const struct nls_table *codepage) | |||
| 65 | { | |||
| 66 | int charlen; | |||
| 67 | int i; | |||
| 68 | wchar_t * wchar_to = (wchar_t *)to; /* needed to quiet sparse */ | |||
| 69 | ||||
| 0 | 0 | - | 70 | for (i = 0; len && *from; i++, from += charlen, len -= charlen) { |
| 0 | - | 70 | T && T | |
| 0 | - | 70 | T && F | |
| 0 | - | 70 | F && _ | |
| 71 | ||||
| 72 | /* works for 2.4.0 kernel or later */ | |||
| 73 | charlen = codepage->char2uni(from, len, &wchar_to[i]); | |||
| 0 | 0 | - | 74 | if (charlen < 1) { |
| 0 | 0 | - | 75 | cERROR(1, |
| 0 | 0 | - | 75 | if (cifsERROR) |
| 76 | ("cifs_strtoUCS: char2uni returned %d", | |||
| 77 | charlen)); | |||
| 78 | /* A question mark */ | |||
| 79 | to[i] = cpu_to_le16(0x003f); | |||
| 80 | charlen = 1; | |||
| 81 | } else | |||
| 82 | to[i] = cpu_to_le16(wchar_to[i]); | |||
| 83 | ||||
| 84 | } | |||
| 85 | ||||
| 86 | to[i] = 0; | |||
| 0 | - | 87 | return i; | |
| 88 | } | |||
| 89 | ||||
| ***TER 0% (0/22) of SOURCE FILE cifs_unicode.c | ||||