summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2001-09-25 09:57:06 +0000
committerSimo Sorce <idra@samba.org>2001-09-25 09:57:06 +0000
commitdeed36e40fcf5ca643afe896f2235dbec82e6c7d (patch)
tree4d5f090cca1ec01649725a576e49e11b47833fff /source3/lib
parent666f8a09b2701d01e67d711eaccff599b036de9b (diff)
downloadsamba-deed36e40fcf5ca643afe896f2235dbec82e6c7d.tar.gz
samba-deed36e40fcf5ca643afe896f2235dbec82e6c7d.tar.bz2
samba-deed36e40fcf5ca643afe896f2235dbec82e6c7d.zip
- the inactive core of the new mangling code that use tdb
- some more utils for unicode string manipulation (This used to be commit 4ade36446e7dee1c3828d8c822f047c6e891a644)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/util_unistr.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c
index d4c71ae13f..8248ac073c 100644
--- a/source3/lib/util_unistr.c
+++ b/source3/lib/util_unistr.c
@@ -280,6 +280,67 @@ int strcasecmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b)
}
+/*******************************************************************
+duplicate string
+********************************************************************/
+smb_ucs2_t *strdup_w(const smb_ucs2_t *src)
+{
+ smb_ucs2_t *dest;
+ uint32 len;
+
+ len = strlen_w(src);
+ dest = (smb_ucs2_t *)malloc((len+1)*sizeof(smb_ucs2_t));
+ if (!dest) {
+ DEBUG(0,("strdup_w: out of memory!\n"));
+ return NULL;
+ }
+
+ memcpy(dest, src, (len+1)*sizeof(smb_ucs2_t));
+
+ return dest;
+}
+
+/*******************************************************************
+copy a string with max len
+********************************************************************/
+
+smb_ucs2_t *strncpy_w(smb_ucs2_t *dest, const smb_ucs2_t *src, const size_t max)
+{
+ size_t len;
+
+ if (!dest || !src) return NULL;
+
+ for (len = 0; (src[len] != 0) && (len < max); len++)
+ dest[len] = src[len];
+ while (len < max)
+ dest[len++] = 0;
+
+ return dest;
+}
+
+
+/*******************************************************************
+append a string of len bytes and add a terminator
+********************************************************************/
+
+smb_ucs2_t *strncat_w(smb_ucs2_t *dest, const smb_ucs2_t *src, const size_t max)
+{
+ size_t start;
+ size_t len;
+
+ if (!dest || !src) return NULL;
+
+ start = strlen_w(dest);
+ len = strlen_w(src);
+ if (len > max) len = max;
+
+ memcpy(&dest[start], src, len);
+ dest[start+len+1] = 0;
+
+ return dest;
+}
+
+
/*
The *_wa() functions take a combination of 7 bit ascii
and wide characters They are used so that you can use string
@@ -304,6 +365,8 @@ int strcmp_wa(const smb_ucs2_t *a, const char *b)
return (*a - UCS2_CHAR(*b));
}
+
+
smb_ucs2_t *strchr_wa(const smb_ucs2_t *s, char c)
{
while (*s != 0) {
@@ -337,3 +400,47 @@ smb_ucs2_t *strpbrk_wa(const smb_ucs2_t *s, const char *p)
return NULL;
}
+
+/*******************************************************************
+copy a string with max len
+********************************************************************/
+
+smb_ucs2_t *strncpy_wa(smb_ucs2_t *dest, const char *src, const size_t max)
+{
+ smb_ucs2_t *ucs2_src;
+
+ if (!dest || !src) return NULL;
+ ucs2_src = (smb_ucs2_t *)malloc((strlen(src)+1)*sizeof(smb_ucs2_t));
+ if (!ucs2_src) {
+ DEBUG(0,("strncpy_wa: out of memory!\n"));
+ return NULL;
+ }
+ push_ucs2(NULL, ucs2_src, src, -1, STR_TERMINATE|STR_NOALIGN);
+
+ strncpy_w(dest, ucs2_src, max);
+ SAFE_FREE(ucs2_src);
+ return dest;
+}
+
+
+/*******************************************************************
+append a string of len bytes and add a terminator
+********************************************************************/
+
+smb_ucs2_t *strncat_wa(smb_ucs2_t *dest, const char *src, const size_t max)
+{
+ smb_ucs2_t *ucs2_src;
+
+ if (!dest || !src) return NULL;
+ ucs2_src = (smb_ucs2_t *)malloc((strlen(src)+1)*sizeof(smb_ucs2_t));
+ if (!ucs2_src) {
+ DEBUG(0,("strncat_wa: out of memory!\n"));
+ return NULL;
+ }
+ push_ucs2(NULL, ucs2_src, src, -1, STR_TERMINATE|STR_NOALIGN);
+
+ strncat_w(dest, ucs2_src, max);
+ SAFE_FREE(ucs2_src);
+ return dest;
+}
+