summaryrefslogtreecommitdiffstats
path: root/source/lib/charcnv.c
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
commitdee8beba7a92b8a3f68bbcc59fd0a827f68c7736 (patch)
tree507bac2ea372f213afd7d963c2d37b91859bdee6 /source/lib/charcnv.c
parent6026d132537f2fb2a963fa54377a926fa99eeb35 (diff)
downloadsamba-dee8beba7a92b8a3f68bbcc59fd0a827f68c7736.tar.gz
samba-dee8beba7a92b8a3f68bbcc59fd0a827f68c7736.tar.xz
samba-dee8beba7a92b8a3f68bbcc59fd0a827f68c7736.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.
Diffstat (limited to 'source/lib/charcnv.c')
-rw-r--r--source/lib/charcnv.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/source/lib/charcnv.c b/source/lib/charcnv.c
index 349fbff8506..dd03a562330 100644
--- a/source/lib/charcnv.c
+++ b/source/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;