]> arthur.barton.de Git - netatalk.git/blobdiff - bin/uniconv/uniconv.c
Remove all Appletalk stuff
[netatalk.git] / bin / uniconv / uniconv.c
index 9955c2dca904d57cbd8c87a111f32fdba00f057f..850c45d79747d13b77a15ed1bc3ca0d488efa3bf 100644 (file)
 #include <sys/param.h>
 #include <pwd.h>
 #include <dirent.h>
+#include <arpa/inet.h>
+
 #include <atalk/afp.h>
 #include <atalk/unicode.h>
 #include <atalk/util.h>
 #include <atalk/logger.h>
+#include <atalk/compat.h>
 
 #include "atalk/cnid.h"
 #ifndef MAXPATHLEN
@@ -142,15 +145,15 @@ static int do_rename( char* src, char *dst, struct stat *st)
 
 static char *convert_name(char *name, struct stat *st, cnid_t cur_did)
 {
-       static char   buffer[MAXPATHLEN];
+       static char   buffer[MAXPATHLEN +2];  /* for convert_charset dest_len parameter +2 */
        size_t outlen = 0;
        unsigned char *p,*q;
        int require_conversion = 0;
-        u_int16_t    flags = conv_flags;
+    u_int16_t    flags = conv_flags;
        cnid_t id;
 
-       p = name;
-       q = buffer;
+       p = (unsigned char *)name;
+       q = (unsigned char *)buffer;
 
        /* optimize for ascii case */
        while (*p != 0) {
@@ -168,24 +171,23 @@ static char *convert_name(char *name, struct stat *st, cnid_t cur_did)
        }
 
        /* convert charsets */
-       q=buffer;
-       p=name;
+       q=(unsigned char *)buffer;
+       p=(unsigned char *)name;
 
-       outlen = convert_charset(ch_from, ch_to, ch_mac, p, strlen(p), q, sizeof(buffer), &flags);
+       outlen = convert_charset(ch_from, ch_to, ch_mac, (char *)p, strlen((char *)p), (char *)q, sizeof(buffer) -2, &flags);
        if ((size_t)-1 == outlen) {
           if ( ch_to == CH_UTF8) {
                /* maybe name is already in UTF8? */
                flags = conv_flags;
-               q = (char*) buffer;
-               p = name;
-               outlen = convert_charset(ch_to, ch_to, ch_mac, p, strlen(p), q, sizeof(buffer), &flags);
+               q = (unsigned char *)buffer;
+               p = (unsigned char *)name;
+               outlen = convert_charset(ch_to, ch_to, ch_mac, (char *)p, strlen((char *)p), (char *)q, sizeof(buffer) -2, &flags);
                if ((size_t)-1 == outlen) {
                        /* it's not UTF8... */
                        fprintf(stderr, "ERROR: conversion from '%s' to '%s' for '%s' in DID %u failed!!!\n", 
                                from_charset, to_charset, name, ntohl(cur_did));
                        return name;
                }
-               buffer[outlen] = 0;
 
                if (!strcmp(buffer, name)) {
                        return name;
@@ -195,7 +197,7 @@ static char *convert_name(char *name, struct stat *st, cnid_t cur_did)
                        from_charset, to_charset, name, ntohl(cur_did));
           return name;
        }
-       buffer[outlen] = 0;
+
        if (strcmp (name, buffer)) {
            if (dry_run) {
                fprintf(stdout, "dry_run: would rename %s to %s.\n", name, buffer);
@@ -387,7 +389,7 @@ static int init(char* path)
 {
        DIR* startdir;
 
-        if (NULL == (cdb = cnid_open (path, 0, cnid_type, 0)) ) {
+    if (NULL == (cdb = cnid_open (path, 0, cnid_type, 0, NULL, NULL)) ) {
                 fprintf (stderr, "ERROR: cannot open CNID database in '%s'\n", path);
                 fprintf (stderr, "ERROR: check the logs for reasons, aborting\n");
                return -1;
@@ -412,12 +414,12 @@ static void usage( char * name )
     exit( 1 );
 }
 
-static void print_version ()
+static void print_version (void)
 {
     fprintf( stderr, "uniconv - Netatalk %s\n", VERSION );
 }
 
-static void help ()
+static void help (void)
 {
     fprintf (stdout, "\nuniconv, a tool to convert between various Netatalk volume encodings\n");
     fprintf (stdout, "\nUsage:  uniconv [-ndv] -c cnid -f fromcode -t tocode [-m maccode] path\n\n");
@@ -460,7 +462,7 @@ int main(int argc, char *argv[])
         setlinebuf(stdout); 
 #endif        
 
-        while ((c = getopt (argc, argv, "f:m:t:c:nvVh")) != -1)
+        while ((c = getopt (argc, argv, "f:m:t:c:dnvVh")) != -1)
         switch (c)
         {
        case 'f':
@@ -473,7 +475,7 @@ int main(int argc, char *argv[])
                mac_charset = strdup(optarg);
                break;
        case 'd':
-               conv_flags &= !CONV_ESCAPEDOTS;
+               conv_flags &= ~CONV_ESCAPEDOTS;
                usedots = 1;
                break;
        case 'n':