diff options
author | Jeff Layton <jlayton@redhat.com> | 2009-04-30 07:16:14 -0400 |
---|---|---|
committer | Steve French <sfrench@us.ibm.com> | 2009-04-30 15:45:00 +0000 |
commit | 066ce6899484d9026acd6ba3a8dbbedb33d7ae1b (patch) | |
tree | e052f744476e4043ae183d3731138354a1ab307a /fs/cifs/cifs_unicode.c | |
parent | 69f801fcaa03be83d58c564f00913b7c172808e4 (diff) | |
download | linux-stable-066ce6899484d9026acd6ba3a8dbbedb33d7ae1b.tar.gz linux-stable-066ce6899484d9026acd6ba3a8dbbedb33d7ae1b.tar.bz2 linux-stable-066ce6899484d9026acd6ba3a8dbbedb33d7ae1b.zip |
cifs: rename cifs_strlcpy_to_host and make it use new functions
Rename cifs_strlcpy_to_host to cifs_strndup since that better describes
what this function really does. Then, convert it to use the new string
conversion and measurement functions that work in units of bytes rather
than wide chars.
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.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c index 614512573c67..2a879cff3a40 100644 --- a/fs/cifs/cifs_unicode.c +++ b/fs/cifs/cifs_unicode.c @@ -243,3 +243,41 @@ cifs_strtoUCS(__le16 *to, const char *from, int len, return i; } +/* + * cifs_strndup - copy a string from wire format to the local codepage + * @src - source string + * @maxlen - don't walk past this many bytes in the source string + * @is_unicode - is this a unicode string? + * @codepage - destination codepage + * + * Take a string given by the server, convert it to the local codepage and + * put it in a new buffer. Returns a pointer to the new string or NULL on + * error. + */ +char * +cifs_strndup(const char *src, const int maxlen, const bool is_unicode, + const struct nls_table *codepage) +{ + int len; + char *dst; + + if (is_unicode) { + len = cifs_ucs2_bytes((__le16 *) src, maxlen, codepage); + len += nls_nullsize(codepage); + dst = kmalloc(len, GFP_KERNEL); + if (!dst) + return NULL; + cifs_from_ucs2(dst, (__le16 *) src, len, maxlen, codepage, + false); + } else { + len = strnlen(src, maxlen); + len++; + dst = kmalloc(len, GFP_KERNEL); + if (!dst) + return NULL; + strlcpy(dst, src, len); + } + + return dst; +} + |