Merge branch 'master' of git://git.samba.org/samba into convenience
authorJelmer Vernooij <jelmer@samba.org>
Mon, 2 Mar 2009 03:15:11 +0000 (04:15 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Mon, 2 Mar 2009 03:15:11 +0000 (04:15 +0100)
lib/util/charset/iconv.c

index 98284ce9bd5b7d85cbfa26b15d4ce156b2d8edd4..9825e4be016019360d013217a59a617658b4c218 100644 (file)
@@ -50,6 +50,7 @@
 
 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 latin1_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 utf16_munged_pull(void *,const char **, size_t *, char **, size_t *);
@@ -73,6 +74,8 @@ static const struct charset_functions builtin_functions[] = {
        {"UTF16_MUNGED",   utf16_munged_pull,  iconv_copy},
 
        {"ASCII", ascii_pull, ascii_push},
+       {"646", ascii_pull, ascii_push},
+       {"ISO-8859-1", ascii_pull, latin1_push},
        {"UCS2-HEX", ucs2hex_pull, ucs2hex_push}
 };
 
@@ -341,6 +344,32 @@ static size_t ascii_push(void *cd, const char **inbuf, size_t *inbytesleft,
        return ir_count;
 }
 
+static size_t latin1_push(void *cd, const char **inbuf, size_t *inbytesleft,
+                        char **outbuf, size_t *outbytesleft)
+{
+       int ir_count=0;
+
+       while (*inbytesleft >= 2 && *outbytesleft >= 1) {
+               (*outbuf)[0] = (*inbuf)[0];
+               if ((*inbuf)[1]) ir_count++;
+               (*inbytesleft)  -= 2;
+               (*outbytesleft) -= 1;
+               (*inbuf)  += 2;
+               (*outbuf) += 1;
+       }
+
+       if (*inbytesleft == 1) {
+               errno = EINVAL;
+               return -1;
+       }
+
+       if (*inbytesleft > 1) {
+               errno = E2BIG;
+               return -1;
+       }
+       
+       return ir_count;
+}
 
 static size_t ucs2hex_pull(void *cd, const char **inbuf, size_t *inbytesleft,
                         char **outbuf, size_t *outbytesleft)