s3-util: for convenience, provide format comments in tdb_unpack().
[jra/samba/.git] / source3 / torture / smbiconv.c
index ce21a09025eb9330db546f47ca340ed3b6fece02..72fbdc470fe9172640d4ecf0e0fdcca1eda1829f 100644 (file)
@@ -8,7 +8,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
+#undef realloc
 
 static int
-process_block (smb_iconv_t cd, char *addr, size_t len, FILE *output)
+process_block (smb_iconv_t cd, const char *addr, size_t len, FILE *output)
 {
 #define OUTBUF_SIZE    32768
   const char *start = addr;
@@ -37,7 +37,7 @@ process_block (smb_iconv_t cd, char *addr, size_t len, FILE *output)
     {
       outptr = outbuf;
       outlen = OUTBUF_SIZE;
-      n = smb_iconv (cd, &addr, &len, &outptr, &outlen);
+      n = smb_iconv (cd,  &addr, &len, &outptr, &outlen);
 
       if (outptr != outbuf)
        {
@@ -86,7 +86,7 @@ incomplete character or shift sequence at end of buffer"));
 
 
 static int
-process_fd (iconv_t cd, int fd, FILE *output)
+process_fd (smb_iconv_t cd, int fd, FILE *output)
 {
   /* we have a problem with reading from a descriptor since we must not
      provide the iconv() function an incomplete character or shift
@@ -168,10 +168,10 @@ process_fd (iconv_t cd, int fd, FILE *output)
 int main(int argc, char *argv[])
 {
        const char *file = NULL;
-       char *from = "";
-       char *to = "";
+       const char *from = "";
+       const char *to = "";
        char *output = NULL;
-       char *preload = NULL;
+       const char *preload_modules[] = {NULL, NULL};
        FILE *out = stdout;
        int fd;
        smb_iconv_t cd;
@@ -184,7 +184,7 @@ int main(int argc, char *argv[])
                { "from-code", 'f', POPT_ARG_STRING, &from, 0, "Encoding of original text" },
                { "to-code", 't', POPT_ARG_STRING, &to, 0, "Encoding for output" },
                { "output", 'o', POPT_ARG_STRING, &output, 0, "Write output to this file" },
-               { "preload-modules", 'p', POPT_ARG_STRING, &preload, 0, "Modules to load" },
+               { "preload-modules", 'p', POPT_ARG_STRING, &preload_modules[0], 0, "Modules to load" },
                POPT_COMMON_SAMBA
                POPT_TABLEEND
        };
@@ -198,23 +198,23 @@ int main(int argc, char *argv[])
        
        while(poptGetNextOpt(pc) != -1);
 
-       if(preload)smb_load_modules(str_list_make(preload, NULL));
+       /* the following functions are part of the Samba debugging
+          facilities.  See lib/debug.c */
+       setup_logging("smbiconv", True);
+
+       if (preload_modules[0]) smb_load_modules(preload_modules);
 
        if(output) {
-               output = fopen(output, "w");
+               out = fopen(output, "w");
 
-               if(!output) {
+               if(!out) {
                        DEBUG(0, ("Can't open output file '%s': %s, exiting...\n", output, strerror(errno)));
                        return 1;
                }
        }
 
-       /* the following functions are part of the Samba debugging
-          facilities.  See lib/debug.c */
-       setup_logging("smbiconv", True);
-
        cd = smb_iconv_open(to, from);
-       if((int)cd == -1) {
+       if (cd == (smb_iconv_t)-1) {
                DEBUG(0,("unable to find from or to encoding, exiting...\n"));
                return 1;
        }
@@ -231,7 +231,7 @@ int main(int argc, char *argv[])
                }
 
                /* Loop thru all arguments */
-               process_fd(cd, fd, stdout);
+               process_fd(cd, fd, out);
 
                close(fd);
        }