summaryrefslogtreecommitdiff
path: root/source3/lib/util_unistr.c
diff options
context:
space:
mode:
authorJean-François Micouleau <jfm@samba.org>2000-02-07 16:22:16 +0000
committerJean-François Micouleau <jfm@samba.org>2000-02-07 16:22:16 +0000
commit59ac32c2556e970ea1fe171e7b76cfee2142fbf0 (patch)
tree9af57449a0e2b38f82d46f16f6c00e2effb6f3e8 /source3/lib/util_unistr.c
parent6a6749d81e892bb06bfdc0fefdc428e5e6599f71 (diff)
downloadsamba-59ac32c2556e970ea1fe171e7b76cfee2142fbf0.tar.gz
samba-59ac32c2556e970ea1fe171e7b76cfee2142fbf0.tar.bz2
samba-59ac32c2556e970ea1fe171e7b76cfee2142fbf0.zip
Jeremy can you check lib/util_unistr.c for codepages support ?
I added 2 UNICODE <-> ASCII functions which _don't_ honor codepage support. J.F. (This used to be commit b81dc7b7f832cae2e66076398a134fbb6c1f78ca)
Diffstat (limited to 'source3/lib/util_unistr.c')
-rw-r--r--source3/lib/util_unistr.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c
index a512f68acc..2c721aeb47 100644
--- a/source3/lib/util_unistr.c
+++ b/source3/lib/util_unistr.c
@@ -79,6 +79,61 @@ int dos_PutUniCode(char *dst,const char *src, ssize_t len)
}
/*******************************************************************
+ Put an ASCII string into a UNICODE array (uint16's).
+
+ Warning: doesn't do any codepage !!! BAD !!!
+
+ Help ! Fix Me ! Fix Me !
+********************************************************************/
+
+void ascii_to_unistr(uint16 *dest, const char *src, int maxlen)
+{
+ uint16 *destend = dest + maxlen;
+ register char c;
+
+ while (dest < destend)
+ {
+ c = *(src++);
+ if (c == 0)
+ {
+ break;
+ }
+
+ *(dest++) = (uint16)c;
+ }
+
+ *dest = 0;
+}
+
+/*******************************************************************
+ Pull an ASCII string out of a UNICODE array (uint16's).
+
+ Warning: doesn't do any codepage !!! BAD !!!
+
+ Help ! Fix Me ! Fix Me !
+********************************************************************/
+
+void unistr_to_ascii(char *dest, const uint16 *src, int len)
+{
+ char *destend = dest + len;
+ register uint16 c;
+
+ while (dest < destend)
+ {
+ c = *(src++);
+ if (c == 0)
+ {
+ break;
+ }
+
+ *(dest++) = (char)c;
+ }
+
+ *dest = 0;
+}
+
+
+/*******************************************************************
Skip past some unicode strings in a buffer.
********************************************************************/
@@ -183,6 +238,48 @@ char *dos_unistr2_to_str(UNISTR2 *str)
}
/*******************************************************************
+ Convert a UNISTR2 structure to an ASCII string
+ Warning: this version does DOS codepage.
+********************************************************************/
+
+void unistr2_to_ascii(char *dest, const UNISTR2 *str, size_t maxlen)
+{
+ char *destend;
+ const uint16 *src;
+ size_t len;
+ register uint16 c;
+
+ src = str->buffer;
+ len = MIN(str->uni_str_len, maxlen);
+ destend = dest + len;
+
+ while (dest < destend)
+ {
+ uint16 ucs2_val;
+ uint16 cp_val;
+
+ c = *(src++);
+ if (c == 0)
+ {
+ break;
+ }
+
+ ucs2_val = SVAL(src,0);
+ cp_val = ucs2_to_doscp[ucs2_val];
+
+ if (cp_val < 256)
+ *(dest++) = (char)cp_val;
+ else {
+ *dest= (cp_val >> 8) & 0xff;
+ *(dest++) = (cp_val & 0xff);
+ }
+ }
+
+ *dest = 0;
+}
+
+
+/*******************************************************************
Return a number stored in a buffer
********************************************************************/