summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-09-07 20:57:01 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:30:32 -0500
commit132ee3990af5d31573978f5a3abf43db2303880b (patch)
tree2ce69566fb9a4ecb0f8ce19261c60e4ad3d8593a /source3/lib
parentc5d8fd3772706a469484df8a16abf10547d1c7a4 (diff)
downloadsamba-132ee3990af5d31573978f5a3abf43db2303880b.tar.gz
samba-132ee3990af5d31573978f5a3abf43db2303880b.tar.bz2
samba-132ee3990af5d31573978f5a3abf43db2303880b.zip
r25009: Large patch discussed with Volker. Move unix_convert to a talloc-based
interface. More development will come on top of this. Remove the "mangled map" parameter. Jeremy. (This used to be commit dee8beba7a92b8a3f68bbcc59fd0a827f68c7736)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/charcnv.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index 349fbff850..dd03a56233 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -804,6 +804,71 @@ char *strdup_upper(const char *s)
return SMB_STRDUP(out_buffer);
}
+/**
+ talloc_strdup() a unix string to upper case.
+**/
+
+char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s)
+{
+ char *out_buffer = talloc_strdup(ctx,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) {
+ if (*p & 0x80)
+ break;
+ *q++ = toupper_ascii(*p);
+ if (!*p)
+ break;
+ p++;
+ }
+
+ if (*p) {
+ /* MB case. */
+ size_t size;
+ smb_ucs2_t *ubuf = NULL;
+
+ /* We're not using the ascii buffer above. */
+ TALLOC_FREE(out_buffer);
+
+ size = convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE,
+ s, strlen(s),
+ (void *)&ubuf,
+ True);
+ if (size == (size_t)-1) {
+ return NULL;
+ }
+
+ strupper_w(ubuf);
+
+ size = convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX,
+ ubuf, size,
+ (void *)&out_buffer,
+ True);
+
+ /* Don't need the intermediate buffer
+ * anymore.
+ */
+
+ TALLOC_FREE(ubuf);
+
+ if (size == (size_t)-1) {
+ return NULL;
+ }
+ }
+
+ return out_buffer;
+}
+
size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
{
size_t size;