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
22 #include "cifs_unicode.h"
23 #include "cifs_uniupr.h"
26 #include "cifs_debug.h"
29 * NAME: cifs_strfromUCS()
31 * FUNCTION: Convert little-endian unicode string to character string
35 cifs_strfromUCS_le(char *to
, const __le16
* from
,
36 int len
, const struct nls_table
*codepage
)
41 for (i
= 0; (i
< len
) && from
[i
]; i
++) {
43 /* 2.4.0 kernel or greater */
45 codepage
->uni2char(le16_to_cpu(from
[i
]), &to
[outlen
],
46 NLS_MAX_CHARSET_SIZE
);
58 * NAME: cifs_strtoUCS()
60 * FUNCTION: Convert character string to unicode string
64 cifs_strtoUCS(__le16
* to
, const char *from
, int len
,
65 const struct nls_table
*codepage
)
69 wchar_t * wchar_to
= (wchar_t *)to
; /* needed to quiet sparse */
71 for (i
= 0; len
&& *from
; i
++, from
+= charlen
, len
-= charlen
) {
73 /* works for 2.4.0 kernel or later */
74 charlen
= codepage
->char2uni(from
, len
, &wchar_to
[i
]);
77 ("cifs_strtoUCS: char2uni returned %d",
80 to
[i
] = cpu_to_le16(0x003f);
83 to
[i
] = cpu_to_le16(wchar_to
[i
]);