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 | |
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')
-rw-r--r-- | source3/lib/charcnv.c | 48 | ||||
-rw-r--r-- | source3/lib/util.c | 5 | ||||
-rw-r--r-- | source3/lib/util_unistr.c | 45 |
3 files changed, 88 insertions, 10 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 59a2af72a4..5ed31d2a4c 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -4,6 +4,7 @@ Character set conversion Extensions Copyright (C) Igor Vergeichik <iverg@mail.ru> 2001 Copyright (C) Andrew Tridgell 2001 + Copyright (C) Simo Sorce 2001 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -150,7 +151,7 @@ size_t convert_string_allocate(charset_t from, charset_t to, { size_t i_len, o_len, destlen; size_t retval; - char* inbuf = (char *)src; + char *inbuf = (char *)src; char *outbuf, *ob; smb_iconv_t descriptor; @@ -178,7 +179,7 @@ convert: ob = (char *)realloc(outbuf, destlen); if (!ob) { DEBUG(0, ("convert_string_allocate: realloc failed!\n")); - free(outbuf); + SAFE_FREE(outbuf); return -1; } else outbuf = ob; @@ -208,10 +209,11 @@ convert: } destlen = destlen - o_len; + *dest = (char *)realloc(ob,destlen); *dest = (char *)realloc(outbuf,destlen); if (!*dest) { DEBUG(0, ("convert_string_allocate: out of memory!\n")); - free(outbuf); + SAFE_FREE(ob); return -1; } @@ -491,14 +493,14 @@ char *acnv_u2ux(const smb_ucs2_t *src) size_t dlen; void *dest; - slen = strlen_w(src) + 1; + slen = (strlen_w(src) + 1) * sizeof(smb_ucs2_t); dlen = convert_string_allocate(CH_UCS2, CH_UNIX, src, slen, &dest); if (dlen == -1) return NULL; else return dest; } /**************************************************************************** -convert from ucs2 to unix charset and return the +convert from unix to ucs2 charset and return the allocated and converted string or NULL if an error occurred. you must provide a zero terminated string. the returning string will be zero terminated. @@ -514,3 +516,39 @@ smb_ucs2_t *acnv_uxu2(const char *src) if (dlen == -1) return NULL; else return dest; } + +/**************************************************************************** +convert from ucs2 to dos charset and return the +allocated and converted string or NULL if an error occurred. +you must provide a zero terminated string. +the returning string will be zero terminated. +****************************************************************************/ +char *acnv_u2dos(const smb_ucs2_t *src) +{ + size_t slen; + size_t dlen; + void *dest; + + slen = (strlen_w(src) + 1) * sizeof(smb_ucs2_t); + dlen = convert_string_allocate(CH_UCS2, CH_DOS, src, slen, &dest); + if (dlen == -1) return NULL; + else return dest; +} + +/**************************************************************************** +convert from dos to ucs2 charset and return the +allocated and converted string or NULL if an error occurred. +you must provide a zero terminated string. +the returning string will be zero terminated. +****************************************************************************/ +smb_ucs2_t *acnv_dosu2(const char *src) +{ + size_t slen; + size_t dlen; + void *dest; + + slen = strlen(src) + 1; + dlen = convert_string_allocate(CH_DOS, CH_UCS2, src, slen, &dest); + if (dlen == -1) return NULL; + else return dest; +} diff --git a/source3/lib/util.c b/source3/lib/util.c index e2a5fe10d0..02397dd4c4 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -4,6 +4,7 @@ Samba utility functions Copyright (C) Andrew Tridgell 1992-1998 Copyright (C) Jeremy Allison 2001 + Copyright (C) Simo Sorce 2001 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -429,7 +430,7 @@ smb_ucs2_t *unix_clean_path(const smb_ucs2_t *s) smb_ucs2_t *ns; smb_ucs2_t *p, *r, *t; - DEBUG(3, ("unix_clean_name_w\n")); /* [%unicode]\n")); */ + DEBUG(3, ("unix_clean_path\n")); /* [%unicode]\n")); */ /* convert '\' to '/' */ ns = strdup_w(s); @@ -450,7 +451,7 @@ smb_ucs2_t *unix_clean_path(const smb_ucs2_t *s) /* reduce any /../ */ t = ns; - while ((r = strstr_wa(t, "/..")) != NULL) { + while ((r = strstr_wa(t, "/.."))) { t = &(r[3]); if (*t == UCS2_CHAR('/') || *t == 0) { *r = 0; 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 ********************************************************************/ |