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 | 5d152d24a39386a7b595f9fc157d86dff38c39dc (patch) | |
tree | c85957ecebf7d74b82b9c79d0938e4ed35c4eecd /source3/lib/charcnv.c | |
parent | 461641d0de74fbf0317079c3a91aaa55f2e91796 (diff) | |
download | samba-5d152d24a39386a7b595f9fc157d86dff38c39dc.tar.gz samba-5d152d24a39386a7b595f9fc157d86dff38c39dc.tar.bz2 samba-5d152d24a39386a7b595f9fc157d86dff38c39dc.zip |
fixed, moved and added some functions
note the useful acnv_uxu2 and acnv_u2ux functions in charcnv.c
(This used to be commit 64dde3b64fc091cda95fc4ed145595b5d79b2e01)
Diffstat (limited to 'source3/lib/charcnv.c')
-rw-r--r-- | source3/lib/charcnv.c | 46 |
1 files changed, 41 insertions, 5 deletions
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; +} |