From 5d152d24a39386a7b595f9fc157d86dff38c39dc Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 10 Nov 2001 15:21:54 +0000 Subject: fixed, moved and added some functions note the useful acnv_uxu2 and acnv_u2ux functions in charcnv.c (This used to be commit 64dde3b64fc091cda95fc4ed145595b5d79b2e01) --- source3/lib/charcnv.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 2929233388..59a2af72a4 100644 --- a/source3/lib/charcnv.c +++ b/source3/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; +} -- cgit