summaryrefslogtreecommitdiffstats
path: root/source/lib/util_unistr.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2002-04-30 13:28:41 +0000
committerJeremy Allison <jra@samba.org>2002-04-30 13:28:41 +0000
commitd04b55f2186fb8af998cf61c576771a5f72f4892 (patch)
tree9ff8c3a7cf34cefc0ee9a550a3bb1236a9e77595 /source/lib/util_unistr.c
parent73267ca42d9eddabb71b31b4c5068ebbe7bc9f7c (diff)
downloadsamba-d04b55f2186fb8af998cf61c576771a5f72f4892.tar.gz
samba-d04b55f2186fb8af998cf61c576771a5f72f4892.tar.xz
samba-d04b55f2186fb8af998cf61c576771a5f72f4892.zip
Start of merge to 2_2_RELEASE branch for release.
Jeremy.
Diffstat (limited to 'source/lib/util_unistr.c')
-rw-r--r--source/lib/util_unistr.c46
1 files changed, 39 insertions, 7 deletions
diff --git a/source/lib/util_unistr.c b/source/lib/util_unistr.c
index c044e8f248c..a2bd0cf4913 100644
--- a/source/lib/util_unistr.c
+++ b/source/lib/util_unistr.c
@@ -348,6 +348,20 @@ void unistr2_to_ascii(char *dest, const UNISTR2 *str, size_t maxlen)
*p = 0;
}
+/*******************************************************************
+ duplicate a UNISTR2 string into a null terminated char*
+ using a talloc context
+********************************************************************/
+char *unistr2_tdup(TALLOC_CTX *ctx, const UNISTR2 *str)
+{
+ char *s;
+ int maxlen = (str->uni_str_len+1)*4;
+ if (!str->buffer) return NULL;
+ s = (char *)talloc(ctx, maxlen); /* convervative */
+ if (!s) return NULL;
+ unistr2_to_ascii(s, str, maxlen);
+ return s;
+}
/*******************************************************************
Return a number stored in a buffer
@@ -492,20 +506,33 @@ char *dos_unistr(char *buf)
}
/*******************************************************************
+ returns the length in number of wide characters
+ ******************************************************************/
+int unistrlen(uint16 *s)
+{
+ int len;
+
+ if (!s)
+ return -1;
+
+ for (len=0; *s; s++,len++);
+
+ return len;
+}
+
+/*******************************************************************
Strcpy for unicode strings. returns length (in num of wide chars)
********************************************************************/
-int unistrcpy(char *dst, char *src)
+int unistrcpy(uint16 *dst, uint16 *src)
{
int num_wchars = 0;
- uint16 *wsrc = (uint16 *)src;
- uint16 *wdst = (uint16 *)dst;
- while (*wsrc) {
- *wdst++ = *wsrc++;
+ while (*src) {
+ *dst++ = *src++;
num_wchars++;
}
- *wdst = 0;
+ *dst = 0;
return num_wchars;
}
@@ -2053,6 +2080,11 @@ int rpcstr_pull(char* dest, void *src, int dest_len, int src_len, int flags)
{
if(dest_len==-1)
dest_len=MAXUNI-3;
- unistr_to_ascii(dest, src, dest_len - 1);
+
+ if (flags & STR_TERMINATE)
+ src_len = strlen_w(src)*2+2;
+
+ dest_len = MIN((src_len/2), (dest_len-1));
+ unistr_to_ascii(dest, src, dest_len);
return src_len;
}