aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cifs/cifs_unicode.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /fs/cifs/cifs_unicode.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'fs/cifs/cifs_unicode.c')
-rw-r--r--fs/cifs/cifs_unicode.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c
new file mode 100644
index 000000000000..a17adf4cb9ba
--- /dev/null
+++ b/fs/cifs/cifs_unicode.c
@@ -0,0 +1,87 @@
1/*
2 * fs/cifs/cifs_unicode.c
3 *
4 * Copyright (c) International Business Machines Corp., 2000,2002
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 */
33int
34cifs_strfromUCS_le(char *to, const wchar_t * from, /* LITTLE ENDIAN */
35 int len, const struct nls_table *codepage)
36{
37 int i;
38 int outlen = 0;
39
40 for (i = 0; (i < len) && from[i]; i++) {
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);
46 if (charlen > 0) {
47 outlen += charlen;
48 } else {
49 to[outlen++] = '?';
50 }
51 }
52 to[outlen] = 0;
53 return outlen;
54}
55
56/*
57 * NAME: cifs_strtoUCS()
58 *
59 * FUNCTION: Convert character string to unicode string
60 *
61 */
62int
63cifs_strtoUCS(wchar_t * to, const char *from, int len,
64 const struct nls_table *codepage)
65{
66 int charlen;
67 int i;
68
69 for (i = 0; len && *from; i++, from += charlen, len -= charlen) {
70
71 /* works for 2.4.0 kernel or later */
72 charlen = codepage->char2uni(from, len, &to[i]);
73 if (charlen < 1) {
74 cERROR(1,
75 ("cifs_strtoUCS: char2uni returned %d",
76 charlen));
77 to[i] = cpu_to_le16(0x003f); /* a question mark */
78 charlen = 1;
79 }
80 to[i] = cpu_to_le16(to[i]);
81
82 }
83
84 to[i] = 0;
85 return i;
86}
87