diff options
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, | |||
243 | return i; | 243 | return i; |
244 | } | 244 | } |
245 | 245 | ||
246 | /* | ||
247 | * cifs_strndup - copy a string from wire format to the local codepage | ||
248 | * @src - source string | ||
249 | * @maxlen - don't walk past this many bytes in the source string | ||
250 | * @is_unicode - is this a unicode string? | ||
251 | * @codepage - destination codepage | ||
252 | * | ||
253 | * Take a string given by the server, convert it to the local codepage and | ||
254 | * put it in a new buffer. Returns a pointer to the new string or NULL on | ||
255 | * error. | ||
256 | */ | ||
257 | char * | ||
258 | cifs_strndup(const char *src, const int maxlen, const bool is_unicode, | ||
259 | const struct nls_table *codepage) | ||
260 | { | ||
261 | int len; | ||
262 | char *dst; | ||
263 | |||
264 | if (is_unicode) { | ||
265 | len = cifs_ucs2_bytes((__le16 *) src, maxlen, codepage); | ||
266 | len += nls_nullsize(codepage); | ||
267 | dst = kmalloc(len, GFP_KERNEL); | ||
268 | if (!dst) | ||
269 | return NULL; | ||
270 | cifs_from_ucs2(dst, (__le16 *) src, len, maxlen, codepage, | ||
271 | false); | ||
272 | } else { | ||
273 | len = strnlen(src, maxlen); | ||
274 | len++; | ||
275 | dst = kmalloc(len, GFP_KERNEL); | ||
276 | if (!dst) | ||
277 | return NULL; | ||
278 | strlcpy(dst, src, len); | ||
279 | } | ||
280 | |||
281 | return dst; | ||
282 | } | ||
283 | |||