diff options
author | Simo Sorce <idra@samba.org> | 2001-11-12 00:53:34 +0000 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2001-11-12 00:53:34 +0000 |
commit | 84244244710790f2058ee90b2dc80e9c252841dd (patch) | |
tree | 34900507eeb6721b52d3a02ab9a7673c8615bec8 /source3/lib/util_unistr.c | |
parent | 5abe3932cc9211263b2a93d58cdddb8de2d6f677 (diff) | |
download | samba-84244244710790f2058ee90b2dc80e9c252841dd.tar.gz samba-84244244710790f2058ee90b2dc80e9c252841dd.tar.bz2 samba-84244244710790f2058ee90b2dc80e9c252841dd.zip |
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)
Diffstat (limited to 'source3/lib/util_unistr.c')
-rw-r--r-- | source3/lib/util_unistr.c | 45 |
1 files changed, 42 insertions, 3 deletions
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 @@ -231,6 +231,18 @@ size_t strlen_w(const smb_ucs2_t *src) } /******************************************************************* + 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() ********************************************************************/ smb_ucs2_t *strchr_w(const smb_ucs2_t *s, smb_ucs2_t c) @@ -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 ********************************************************************/ @@ -595,6 +605,35 @@ smb_ucs2_t *strncpy_wa(smb_ucs2_t *dest, const char *src, const size_t max) } /******************************************************************* +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 ********************************************************************/ |