aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cifs/cifs_unicode.c
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2009-04-30 06:46:32 -0400
committerSteve French <sfrench@us.ibm.com>2009-04-30 11:45:00 -0400
commit69f801fcaa03be83d58c564f00913b7c172808e4 (patch)
tree35e359acc85bef8669b001ccb412afb96d256a82 /fs/cifs/cifs_unicode.c
parent7fabf0c9479fef9fdb9528a5fbdb1cb744a744a4 (diff)
cifs: add new function to get unicode string length in bytes
Working in units of words means we do a lot of unnecessary conversion back and forth. Standardize on bytes instead since that's more useful for allocating buffers and such. Also, remove hostlen_fromUCS since the new function has a similar purpose. Signed-off-by: Jeff Layton <jlayton@redhat.com> Acked-by: Suresh Jayaraman <sjayaraman@suse.de> Signed-off-by: Steve French <sfrench@us.ibm.com>
Diffstat (limited to 'fs/cifs/cifs_unicode.c')
-rw-r--r--fs/cifs/cifs_unicode.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c
index 8389f359b03d..614512573c67 100644
--- a/fs/cifs/cifs_unicode.c
+++ b/fs/cifs/cifs_unicode.c
@@ -26,6 +26,37 @@
26#include "cifs_debug.h" 26#include "cifs_debug.h"
27 27
28/* 28/*
29 * cifs_ucs2_bytes - how long will a string be after conversion?
30 * @ucs - pointer to input string
31 * @maxbytes - don't go past this many bytes of input string
32 * @codepage - destination codepage
33 *
34 * Walk a ucs2le string and return the number of bytes that the string will
35 * be after being converted to the given charset, not including any null
36 * termination required. Don't walk past maxbytes in the source buffer.
37 */
38int
39cifs_ucs2_bytes(const __le16 *from, int maxbytes,
40 const struct nls_table *codepage)
41{
42 int i;
43 int charlen, outlen = 0;
44 int maxwords = maxbytes / 2;
45 char tmp[NLS_MAX_CHARSET_SIZE];
46
47 for (i = 0; from[i] && i < maxwords; i++) {
48 charlen = codepage->uni2char(le16_to_cpu(from[i]), tmp,
49 NLS_MAX_CHARSET_SIZE);
50 if (charlen > 0)
51 outlen += charlen;
52 else
53 outlen++;
54 }
55
56 return outlen;
57}
58
59/*
29 * cifs_mapchar - convert a little-endian char to proper char in codepage 60 * cifs_mapchar - convert a little-endian char to proper char in codepage
30 * @target - where converted character should be copied 61 * @target - where converted character should be copied
31 * @src_char - 2 byte little-endian source character 62 * @src_char - 2 byte little-endian source character