diff options
author | Jeremy Allison <jra@samba.org> | 2007-09-13 22:08:59 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:30:44 -0500 |
commit | eacd3140573d1122a3785823e4003bfc6352c431 (patch) | |
tree | a1ee9d9e59da4c44e0484d895eb78a8c8e1f0de2 /source3/lib/charcnv.c | |
parent | d0de93ca762e8b59f09c2179448188c9952f68fc (diff) | |
download | samba-eacd3140573d1122a3785823e4003bfc6352c431.tar.gz samba-eacd3140573d1122a3785823e4003bfc6352c431.tar.bz2 samba-eacd3140573d1122a3785823e4003bfc6352c431.zip |
r25138: More pstring elimination. Add a TALLOC_CTX parameter
to unix_convert().
Jeremy.
(This used to be commit 39c211a702e91c34c1a5a689e1b0c4530ea8a1ac)
Diffstat (limited to 'source3/lib/charcnv.c')
-rw-r--r-- | source3/lib/charcnv.c | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index c481c9a7e2..26581ba305 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -935,27 +935,40 @@ static size_t ucs2_align(const void *base_ptr, const void *p, int flags) * </dl> * * @param dest_len the maximum length in bytes allowed in the - * destination. If @p dest_len is -1 then no maximum is used. + * destination. **/ size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags) { size_t src_len = strlen(src); - pstring tmpbuf; + char *tmpbuf = NULL; + size_t ret; - /* treat a pstring as "unlimited" length */ - if (dest_len == (size_t)-1) - dest_len = sizeof(pstring); + /* No longer allow a length of -1. */ + if (dest_len == (size_t)-1) { + smb_panic("push_ascii - dest_len == -1"); + return (size_t)0; + } if (flags & STR_UPPER) { - pstrcpy(tmpbuf, src); + tmpbuf = SMB_STRDUP(src); + if (!tmpbuf) { + smb_panic("malloc fail"); + return (size_t)0; + } strupper_m(tmpbuf); src = tmpbuf; } - if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) + if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) { src_len++; + } - return convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len, True); + ret = convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len, True); + SAFE_FREE(tmpbuf); + if (ret == (size_t)-1) { + return 0; + } + return ret; } size_t push_ascii_fstring(void *dest, const char *src) @@ -1007,6 +1020,18 @@ size_t push_ascii_nstring(void *dest, const char *src) return dest_len; } +/******************************************************************** + Push and malloc an ascii string. src and dest null terminated. +********************************************************************/ + +size_t push_ascii_allocate(char **dest, const char *src) +{ + size_t src_len = strlen(src)+1; + + *dest = NULL; + return convert_string_allocate(NULL, CH_UNIX, CH_DOS, src, src_len, (void **)dest, True); +} + /** * Copy a string from a dos codepage source to a unix char* destination. * |