diff options
author | Simo Sorce <idra@samba.org> | 2001-11-10 15:21:54 +0000 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2001-11-10 15:21:54 +0000 |
commit | 64dde3b64fc091cda95fc4ed145595b5d79b2e01 (patch) | |
tree | b012f85b7b0a52180fbe1e294f01e6b00897a90a /source/lib/charcnv.c | |
parent | d20949fe509c1496bc434f0fbf403f0b69ab9954 (diff) | |
download | samba-64dde3b64fc091cda95fc4ed145595b5d79b2e01.tar.gz samba-64dde3b64fc091cda95fc4ed145595b5d79b2e01.tar.xz samba-64dde3b64fc091cda95fc4ed145595b5d79b2e01.zip |
fixed, moved and added some functions
note the useful acnv_uxu2 and acnv_u2ux functions in charcnv.c
Diffstat (limited to 'source/lib/charcnv.c')
-rw-r--r-- | source/lib/charcnv.c | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/source/lib/charcnv.c b/source/lib/charcnv.c index 2929233388a..59a2af72a49 100644 --- a/source/lib/charcnv.c +++ b/source/lib/charcnv.c @@ -171,7 +171,7 @@ size_t convert_string_allocate(charset_t from, charset_t to, return -1; } - destlen = MAX(srclen, 1024); + destlen = MAX(srclen, 512); outbuf = NULL; convert: destlen = destlen * 2; @@ -208,15 +208,13 @@ convert: } destlen = destlen - o_len; - *dest = (char *)malloc(destlen); + *dest = (char *)realloc(outbuf,destlen); if (!*dest) { DEBUG(0, ("convert_string_allocate: out of memory!\n")); free(outbuf); return -1; } - memcpy(*dest, outbuf, destlen); - free(outbuf); - + return destlen; } @@ -478,3 +476,41 @@ int align_string(const void *base_ptr, const char *p, int flags) } return 0; } + + + +/**************************************************************************** +convert from ucs2 to unix 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_u2ux(const smb_ucs2_t *src) +{ + size_t slen; + size_t dlen; + void *dest; + + slen = strlen_w(src) + 1; + 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 +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_uxu2(const char *src) +{ + size_t slen; + size_t dlen; + void *dest; + + slen = strlen(src) + 1; + dlen = convert_string_allocate(CH_UNIX, CH_UCS2, src, slen, &dest); + if (dlen == -1) return NULL; + else return dest; +} |