summaryrefslogtreecommitdiffstats
path: root/source3/lib/charcnv.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2003-03-18 01:48:11 +0000
committerJeremy Allison <jra@samba.org>2003-03-18 01:48:11 +0000
commitd332200c254b4bbf27461a37f9655bf42faa2b3a (patch)
treef749eb110346913b8cb63cb07f4616bb32288f65 /source3/lib/charcnv.c
parenta8eaea53ed70ef998a510b6dcf0288462207f9a0 (diff)
downloadsamba-d332200c254b4bbf27461a37f9655bf42faa2b3a.tar.gz
samba-d332200c254b4bbf27461a37f9655bf42faa2b3a.tar.xz
samba-d332200c254b4bbf27461a37f9655bf42faa2b3a.zip
Merge in the developer string options from HEAD. We need to ensure 3.0
is as stable as possible in the string department and some pain now will help later :-). Jeremy. (This used to be commit 86e3eddac698d90f4666b8492b4603a4efbbd67b)
Diffstat (limited to 'source3/lib/charcnv.c')
-rw-r--r--source3/lib/charcnv.c115
1 files changed, 12 insertions, 103 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index a8df003f8bc..fa646573d89 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -186,7 +186,7 @@ size_t convert_string(charset_t from, charset_t to,
* @returns Size in bytes of the converted string; or -1 in case of error.
**/
-size_t convert_string_allocate(charset_t from, charset_t to,
+static size_t convert_string_allocate(charset_t from, charset_t to,
void const *src, size_t srclen, void **dest)
{
size_t i_len, o_len, destlen;
@@ -265,7 +265,7 @@ convert:
*
* @returns Size in bytes of the converted string; or -1 in case of error.
**/
-size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to,
+static size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to,
void const *src, size_t srclen, void **dest)
{
void *alloced_string;
@@ -303,7 +303,7 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
}
-size_t ucs2_align(const void *base_ptr, const void *p, int flags)
+static size_t ucs2_align(const void *base_ptr, const void *p, int flags)
{
if (flags & (STR_NOALIGN|STR_ASCII))
return 0;
@@ -356,11 +356,6 @@ size_t push_ascii_pstring(void *dest, const char *src)
return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE);
}
-size_t push_pstring(void *dest, const char *src)
-{
- return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE);
-}
-
/**
* Copy a string from a dos codepage source to a unix char* destination.
*
@@ -507,7 +502,7 @@ size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src)
is -1 then no maxiumum is used.
**/
-size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags)
+static size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags)
{
size_t src_len = strlen(src);
pstring tmpbuf;
@@ -533,11 +528,6 @@ size_t push_utf8_fstring(void *dest, const char *src)
return push_utf8(dest, src, sizeof(fstring), STR_TERMINATE);
}
-size_t push_utf8_pstring(void *dest, const char *src)
-{
- return push_utf8(dest, src, sizeof(pstring), STR_TERMINATE);
-}
-
/**
* Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer using talloc
*
@@ -657,51 +647,6 @@ size_t pull_ucs2_allocate(void **dest, const smb_ucs2_t *src)
}
/**
- Copy a string from a utf-8 source to a unix char* destination.
- Flags can have:
- STR_TERMINATE means the string in src is null terminated.
- if STR_TERMINATE is set then src_len is ignored.
- src_len is the length of the source area in bytes
- Return the number of bytes occupied by the string in src.
- The resulting string in "dest" is always null terminated.
-**/
-
-size_t pull_utf8(char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
-{
- size_t ret;
-
- if (dest_len == (size_t)-1)
- dest_len = sizeof(pstring);
-
- if (flags & STR_TERMINATE) {
- if (src_len == (size_t)-1) {
- src_len = strlen(src) + 1;
- } else {
- size_t len = strnlen(src, src_len);
- if (len < src_len)
- len++;
- src_len = len;
- }
- }
-
- ret = convert_string(CH_UTF8, CH_UNIX, src, src_len, dest, dest_len);
- if (dest_len)
- dest[MIN(ret, dest_len-1)] = 0;
-
- return src_len;
-}
-
-size_t pull_utf8_pstring(char *dest, const void *src)
-{
- return pull_utf8(dest, src, sizeof(pstring), -1, STR_TERMINATE);
-}
-
-size_t pull_utf8_fstring(char *dest, const void *src)
-{
- return pull_utf8(dest, src, sizeof(fstring), -1, STR_TERMINATE);
-}
-
-/**
* Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer using talloc
*
* @param dest always set at least to NULL
@@ -745,8 +690,11 @@ size_t pull_utf8_allocate(void **dest, const char *src)
is -1 then no maxiumum is used.
**/
-size_t push_string(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags)
+size_t push_string_fn(const char *function, unsigned int line, const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags)
{
+ if (dest_len != (size_t)-1)
+ clobber_region(function, line, dest, dest_len);
+
if (!(flags & STR_ASCII) && \
((flags & STR_UNICODE || \
(SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) {
@@ -770,8 +718,11 @@ size_t push_string(const void *base_ptr, void *dest, const char *src, size_t des
The resulting string in "dest" is always null terminated.
**/
-size_t pull_string(const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
+size_t pull_string_fn(const char *function, unsigned int line, const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
{
+ if (dest_len != (size_t)-1)
+ clobber_region(function, line, dest, dest_len);
+
if (!(flags & STR_ASCII) && \
((flags & STR_UNICODE || \
(SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) {
@@ -791,27 +742,6 @@ size_t align_string(const void *base_ptr, const char *p, int flags)
}
/**
- 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) * sizeof(smb_ucs2_t);
- dlen = convert_string_allocate(CH_UCS2, CH_UNIX, src, slen, &dest);
- if (dlen == (size_t)-1)
- return NULL;
- else
- return dest;
-}
-
-/**
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.
@@ -833,27 +763,6 @@ smb_ucs2_t *acnv_uxu2(const char *src)
}
/**
- 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 == (size_t)-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.