added some comments at the request of a frustrated abartlet
[tprouty/samba.git] / source4 / lib / charset / iconv.c
index 1c571f896182da9469482ceb8dd3454736e14302..d4f930b4622dc8893d4f58acd6a743374d5caf9d 100644 (file)
@@ -113,7 +113,7 @@ static size_t sys_iconv(void *cd,
  * It only knows about a very small number of character sets - just
  * enough that Samba works on systems that don't have iconv.
  **/
-size_t smb_iconv(smb_iconv_t cd, 
+_PUBLIC_ size_t smb_iconv(smb_iconv_t cd, 
                 const char **inbuf, size_t *inbytesleft,
                 char **outbuf, size_t *outbytesleft)
 {
@@ -154,16 +154,17 @@ static bool is_utf16(const char *name)
                strcasecmp(name, "UTF-16LE") == 0;
 }
 
-/*
-  simple iconv_open() wrapper
- */
-smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode)
+
+
+_PUBLIC_ smb_iconv_t smb_iconv_open_ex(TALLOC_CTX *mem_ctx, const char *tocode, 
+                             const char *fromcode, bool native_iconv)
 {
        smb_iconv_t ret;
        const struct charset_functions *from=NULL, *to=NULL;
        int i;
 
-       ret = (smb_iconv_t)talloc_named(NULL, sizeof(*ret), 
+       ret = (smb_iconv_t)talloc_named(mem_ctx,
+                                       sizeof(*ret), 
                                        "iconv(%s,%s)", tocode, fromcode);
        if (!ret) {
                errno = ENOMEM;
@@ -199,7 +200,7 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode)
        }
 
 #ifdef HAVE_NATIVE_ICONV
-       if ((!from || !to) && !lp_parm_bool(NULL, "iconv", "native", true)) {
+       if ((!from || !to) && !native_iconv) {
                goto failed;
        }
        if (!from) {
@@ -259,10 +260,18 @@ failed:
        return (smb_iconv_t)-1;
 }
 
+/*
+  simple iconv_open() wrapper
+ */
+_PUBLIC_ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode)
+{
+       return smb_iconv_open_ex(NULL, tocode, fromcode, true);
+}
+
 /*
   simple iconv_close() wrapper
 */
-int smb_iconv_close(smb_iconv_t cd)
+_PUBLIC_ int smb_iconv_close(smb_iconv_t cd)
 {
 #ifdef HAVE_NATIVE_ICONV
        if (cd->cd_direct) iconv_close((iconv_t)cd->cd_direct);
@@ -460,6 +469,9 @@ static size_t iconv_copy(void *cd, const char **inbuf, size_t *inbytesleft,
        return 0;
 }
 
+/*
+  this takes a UTF8 sequence and produces a UTF16 sequence
+ */
 static size_t utf8_pull(void *cd, const char **inbuf, size_t *inbytesleft,
                         char **outbuf, size_t *outbytesleft)
 {
@@ -577,6 +589,10 @@ error:
        return -1;
 }
 
+
+/*
+  this takes a UTF16 sequence and produces a UTF8 sequence
+ */
 static size_t utf8_push(void *cd, const char **inbuf, size_t *inbytesleft,
                        char **outbuf, size_t *outbytesleft)
 {