From 84244244710790f2058ee90b2dc80e9c252841dd Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 12 Nov 2001 00:53:34 +0000 Subject: some bugfix and new functions, modified mangle.c to use mosltly acnv_????() functions. this should make also build farm happy (This used to be commit 8bb5cb27c2012b8967482255d48a1b48d3acd9db) --- source3/lib/util_unistr.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'source3/lib/util_unistr.c') diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index 08281fec4f..58ecc19723 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -230,6 +230,18 @@ size_t strlen_w(const smb_ucs2_t *src) return len; } +/******************************************************************* + Count up to max number of characters in a smb_ucs2_t string. +********************************************************************/ +size_t strnlen_w(const smb_ucs2_t *src, size_t max) +{ + size_t len; + + for(len = 0; *src++ && (len < max); len++) ; + + return len; +} + /******************************************************************* wide strchr() ********************************************************************/ @@ -440,8 +452,7 @@ smb_ucs2_t *strncat_w(smb_ucs2_t *dest, const smb_ucs2_t *src, const size_t max) if (!dest || !src) return NULL; start = strlen_w(dest); - len = strlen_w(src); - if (len > max) len = max; + len = strnlen_w(src, max); memcpy(&dest[start], src, len*sizeof(smb_ucs2_t)); dest[start+len] = 0; @@ -465,7 +476,6 @@ smb_ucs2_t *strcat_w(smb_ucs2_t *dest, const smb_ucs2_t *src) return dest; } - /******************************************************************* replace any occurence of oldc with newc in unicode string ********************************************************************/ @@ -594,6 +604,35 @@ smb_ucs2_t *strncpy_wa(smb_ucs2_t *dest, const char *src, const size_t max) return dest; } +/******************************************************************* +convert and duplicate an ascii string +********************************************************************/ +smb_ucs2_t *strdup_wa(const char *src) +{ + return strndup_wa(src, 0); +} + +/* if len == 0 then duplicate the whole string */ +smb_ucs2_t *strndup_wa(const char *src, size_t len) +{ + smb_ucs2_t *dest, *s; + + s = acnv_dosu2(src); + if (!len) len = strlen_w(s); + dest = (smb_ucs2_t *)malloc((len + 1) * sizeof(smb_ucs2_t)); + if (!dest) { + DEBUG(0,("strdup_w: out of memory!\n")); + SAFE_FREE(s); + return NULL; + } + + memcpy(dest, src, len * sizeof(smb_ucs2_t)); + dest[len] = 0; + + SAFE_FREE(s); + return dest; +} + /******************************************************************* append a string of len bytes and add a terminator ********************************************************************/ -- cgit