summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/charcnv.c1
-rw-r--r--source4/lib/iconv.c37
2 files changed, 33 insertions, 5 deletions
diff --git a/source4/lib/charcnv.c b/source4/lib/charcnv.c
index 72277b4f2e..11b0e64dce 100644
--- a/source4/lib/charcnv.c
+++ b/source4/lib/charcnv.c
@@ -52,6 +52,7 @@ static const char *charset_name(charset_t ch)
else if (ch == CH_DOS) ret = lp_dos_charset();
else if (ch == CH_DISPLAY) ret = lp_display_charset();
else if (ch == CH_UTF8) ret = "UTF8";
+ else if (ch == CH_UCS2BE) ret = "UCS-2BE";
if (!ret || !*ret) ret = "ASCII";
return ret;
diff --git a/source4/lib/iconv.c b/source4/lib/iconv.c
index 2a0b013257..3f37583e39 100644
--- a/source4/lib/iconv.c
+++ b/source4/lib/iconv.c
@@ -45,16 +45,18 @@
* @sa Samba Developers Guide
**/
-static size_t ascii_pull(void *,const char **, size_t *, char **, size_t *);
-static size_t ascii_push(void *,const char **, size_t *, char **, size_t *);
-static size_t utf8_pull(void *,const char **, size_t *, char **, size_t *);
-static size_t utf8_push(void *,const char **, size_t *, char **, size_t *);
+static size_t ascii_pull (void *,const char **, size_t *, char **, size_t *);
+static size_t ascii_push (void *,const char **, size_t *, char **, size_t *);
+static size_t utf8_pull (void *,const char **, size_t *, char **, size_t *);
+static size_t utf8_push (void *,const char **, size_t *, char **, size_t *);
static size_t ucs2hex_pull(void *,const char **, size_t *, char **, size_t *);
static size_t ucs2hex_push(void *,const char **, size_t *, char **, size_t *);
-static size_t iconv_copy(void *,const char **, size_t *, char **, size_t *);
+static size_t iconv_copy (void *,const char **, size_t *, char **, size_t *);
+static size_t iconv_swab (void *,const char **, size_t *, char **, size_t *);
static struct charset_functions builtin_functions[] = {
{"UCS-2LE", iconv_copy, iconv_copy},
+ {"UCS-2BE", iconv_swab, iconv_swab},
{"UTF8", utf8_pull, utf8_push},
{"ASCII", ascii_pull, ascii_push},
{"UCS2-HEX", ucs2hex_pull, ucs2hex_push},
@@ -404,6 +406,31 @@ static size_t ucs2hex_push(void *cd, const char **inbuf, size_t *inbytesleft,
return 0;
}
+static size_t iconv_swab(void *cd, const char **inbuf, size_t *inbytesleft,
+ char **outbuf, size_t *outbytesleft)
+{
+ int n;
+
+ n = MIN(*inbytesleft, *outbytesleft);
+
+ swab(*inbuf, *outbuf, (n&~1));
+ if (n&1) {
+ (*outbuf)[n-1] = 0;
+ }
+
+ (*inbytesleft) -= n;
+ (*outbytesleft) -= n;
+ (*inbuf) += n;
+ (*outbuf) += n;
+
+ if (*inbytesleft > 0) {
+ errno = E2BIG;
+ return -1;
+ }
+
+ return 0;
+}
+
static size_t iconv_copy(void *cd, const char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft)