Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / fs / cifs / cifs_unicode.c
bloba511d6d15756649184e6c451420853c660f51a87
1 /*
2 * fs/cifs/cifs_unicode.c
4 * Copyright (c) International Business Machines Corp., 2000,2005
5 * Modified by Steve French (sfrench@us.ibm.com)
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.
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.
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
21 #include <linux/fs.h>
22 #include "cifs_unicode.h"
23 #include "cifs_uniupr.h"
24 #include "cifspdu.h"
25 #include "cifsglob.h"
26 #include "cifs_debug.h"
29 * NAME: cifs_strfromUCS()
31 * FUNCTION: Convert little-endian unicode string to character string
34 int
35 <<<<<<< HEAD:fs/cifs/cifs_unicode.c
36 cifs_strfromUCS_le(char *to, const __le16 * from,
37 =======
38 cifs_strfromUCS_le(char *to, const __le16 *from,
39 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/cifs_unicode.c
40 int len, const struct nls_table *codepage)
42 int i;
43 int outlen = 0;
45 for (i = 0; (i < len) && from[i]; i++) {
46 int charlen;
47 /* 2.4.0 kernel or greater */
48 charlen =
49 codepage->uni2char(le16_to_cpu(from[i]), &to[outlen],
50 NLS_MAX_CHARSET_SIZE);
51 if (charlen > 0) {
52 outlen += charlen;
53 } else {
54 to[outlen++] = '?';
57 to[outlen] = 0;
58 return outlen;
62 * NAME: cifs_strtoUCS()
64 * FUNCTION: Convert character string to unicode string
67 int
68 <<<<<<< HEAD:fs/cifs/cifs_unicode.c
69 cifs_strtoUCS(__le16 * to, const char *from, int len,
70 =======
71 cifs_strtoUCS(__le16 *to, const char *from, int len,
72 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/cifs_unicode.c
73 const struct nls_table *codepage)
75 int charlen;
76 int i;
77 wchar_t *wchar_to = (wchar_t *)to; /* needed to quiet sparse */
79 for (i = 0; len && *from; i++, from += charlen, len -= charlen) {
81 /* works for 2.4.0 kernel or later */
82 charlen = codepage->char2uni(from, len, &wchar_to[i]);
83 if (charlen < 1) {
84 cERROR(1,
85 ("strtoUCS: char2uni of %d returned %d",
86 (int)*from, charlen));
87 /* A question mark */
88 to[i] = cpu_to_le16(0x003f);
89 charlen = 1;
90 } else
91 to[i] = cpu_to_le16(wchar_to[i]);
95 to[i] = 0;
96 return i;