]> Pileus Git - ~andy/linux/blobdiff - fs/cifs/cifs_unicode.c
Merge branch 'for-linus' of git://oss.sgi.com/xfs/xfs
[~andy/linux] / fs / cifs / cifs_unicode.c
index 614512573c67dc1d55de9d2cb6e4c5e65cd17743..60e3c4253de0b9774cb79767966847779c6d92b5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *   fs/cifs/cifs_unicode.c
  *
- *   Copyright (c) International Business Machines  Corp., 2000,2005
+ *   Copyright (c) International Business Machines  Corp., 2000,2009
  *   Modified by Steve French (sfrench@us.ibm.com)
  *
  *   This program is free software;  you can redistribute it and/or modify
@@ -180,35 +180,6 @@ cifs_from_ucs2(char *to, const __le16 *from, int tolen, int fromlen,
        return outlen;
 }
 
-/*
- * NAME:       cifs_strfromUCS()
- *
- * FUNCTION:   Convert little-endian unicode string to character string
- *
- */
-int
-cifs_strfromUCS_le(char *to, const __le16 *from,
-                  int len, const struct nls_table *codepage)
-{
-       int i;
-       int outlen = 0;
-
-       for (i = 0; (i < len) && from[i]; i++) {
-               int charlen;
-               /* 2.4.0 kernel or greater */
-               charlen =
-                   codepage->uni2char(le16_to_cpu(from[i]), &to[outlen],
-                                      NLS_MAX_CHARSET_SIZE);
-               if (charlen > 0) {
-                       outlen += charlen;
-               } else {
-                       to[outlen++] = '?';
-               }
-       }
-       to[outlen] = 0;
-       return outlen;
-}
-
 /*
  * NAME:       cifs_strtoUCS()
  *
@@ -243,3 +214,41 @@ cifs_strtoUCS(__le16 *to, const char *from, int len,
        return i;
 }
 
+/*
+ * cifs_strndup_from_ucs - 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_from_ucs(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;
+}
+