summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-09-17 19:43:06 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:30:51 -0500
commit38ffbd2893ceac2a45cef3694364c34262ef5fa9 (patch)
treeab503148191ec13f0a333785904e22cea18759ef /source3
parent4dc265d6a0fe799006ac5be79114a145b3a114c5 (diff)
downloadsamba-38ffbd2893ceac2a45cef3694364c34262ef5fa9.tar.gz
samba-38ffbd2893ceac2a45cef3694364c34262ef5fa9.tar.bz2
samba-38ffbd2893ceac2a45cef3694364c34262ef5fa9.zip
r25199: Remove pstring from strdup_upper - make it the
same as talloc_strdup_upper. Jeremy. (This used to be commit db1b6293771755f20660b071aac0284638dbed46)
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/charcnv.c45
1 files changed, 31 insertions, 14 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index 9e669a1c9c..26c50c1391 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -759,49 +759,68 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen)
/**
strdup() a unix string to upper case.
- Max size is pstring.
**/
char *strdup_upper(const char *s)
{
- pstring out_buffer;
+ char *out_buffer = SMB_STRDUP(s);
const unsigned char *p = (const unsigned char *)s;
unsigned char *q = (unsigned char *)out_buffer;
+ if (!q) {
+ return NULL;
+ }
+
/* this is quite a common operation, so we want it to be
fast. We optimise for the ascii case, knowing that all our
supported multi-byte character sets are ascii-compatible
(ie. they match for the first 128 chars) */
- while (1) {
+ while (*p) {
if (*p & 0x80)
break;
*q++ = toupper_ascii(*p);
- if (!*p)
- break;
p++;
- if (p - ( const unsigned char *)s >= sizeof(pstring))
- break;
}
if (*p) {
/* MB case. */
size_t size;
- wpstring buffer;
- size = convert_string(CH_UNIX, CH_UTF16LE, s, -1, buffer, sizeof(buffer), True);
+ smb_ucs2_t *buffer = NULL;
+
+ SAFE_FREE(out_buffer);
+ size = convert_string_allocate(NULL,
+ CH_UNIX,
+ CH_UTF16LE,
+ s,
+ strlen(s) + 1,
+ (void **)(void *)&buffer,
+ True);
if (size == (size_t)-1) {
return NULL;
}
strupper_w(buffer);
- size = convert_string(CH_UTF16LE, CH_UNIX, buffer, -1, out_buffer, sizeof(out_buffer), True);
+ size = convert_string_allocate(NULL,
+ CH_UTF16LE,
+ CH_UNIX,
+ buffer,
+ size,
+ (void **)(void *)&out_buffer,
+ True);
+
+ /* Don't need the intermediate buffer
+ * anymore.
+ */
+
+ TALLOC_FREE(buffer);
if (size == (size_t)-1) {
return NULL;
}
}
- return SMB_STRDUP(out_buffer);
+ return out_buffer;
}
/**
@@ -823,12 +842,10 @@ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s)
supported multi-byte character sets are ascii-compatible
(ie. they match for the first 128 chars) */
- while (1) {
+ while (*p) {
if (*p & 0x80)
break;
*q++ = toupper_ascii(*p);
- if (!*p)
- break;
p++;
}