]> arthur.barton.de Git - netatalk.git/blobdiff - bin/adv1tov2/adv1tov2.c
Remove bdb env on exit
[netatalk.git] / bin / adv1tov2 / adv1tov2.c
index 2e8d12a3ecf4ce565e6c98d4b39dd751f3470135..eade898b5d3fba6a8f89e88dd2574ff7f83a76f7 100644 (file)
@@ -1,21 +1,36 @@
-/* v1tov2: given a root directory, run down and convert all the
- * files/directories into appledouble v2.  */
+/*
+ * $Id: adv1tov2.c,v 1.5 2009-10-14 01:38:28 didg Exp $
+ * v1tov2: given a root directory, run down and convert all the
+ * files/directories into appledouble v2.
+ */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <atalk/adouble.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <dirent.h>
+#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
+#endif /* HAVE_FCNTL_H */
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif /* HAVE_UNISTD_H */
 #include <ctype.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/param.h>
+#include <errno.h>
+#include <string.h>
 
-#include <atalk/adouble.h>
+#include <atalk/util.h>
 
 #if AD_VERSION == AD_VERSION2
+#if 0
 /* translate characters */
-static int xlate(char *name, int flags) {
+static void xlate(char *name, int flags) {
   static const char hexdig[] = "0123456789abcdef";
   char upath[MAXPATHLEN + 1];
   char *m, *u;
@@ -41,21 +56,21 @@ static int xlate(char *name, int flags) {
       rename(ad_path(name, flags), ad_path(upath, flags)); /* rename rfork */
   }
 }
-
+#endif
 
 #define MAXDESCEND 0xFFFF
 /* recursively descend subdirectories. 
  * oh the stack space we use up! */
-void descend(DIR *dp)
+static void descend(DIR *dp)
 {
   DIR *dpnew;
   struct dirent *de;
-  unsigned char *m, *u;
   struct stat st;
   struct adouble ad;
   int flags;
   static int count = 0;
 
+  ad_init(&ad, AD_VERSION2, 0);
   if (count++ > MAXDESCEND) {
     fprintf(stderr, "FAILURE: too many subdirectories! possible infinite recursion.");
     return;
@@ -82,11 +97,11 @@ void descend(DIR *dp)
     }
 
     if (ad_open(de->d_name, flags, O_RDWR, 0, &ad) < 0) {
-      fprintf(stderr, "FAILURE: can't convert %s\n", de->d_name);
+      if (errno != ENOENT)
+          fprintf(stderr, "\nFAILURE: can't convert %s, %s\n", fullpathname(de->d_name), strerror(errno));
       continue;
     }
     ad_close(&ad, ADFLAGS_HF);
-    xlate(de->d_name, flags);
     fputc('.', stderr);
   }
   putc(')', stderr);
@@ -98,6 +113,7 @@ int main(int argc, char **argv)
   DIR           *dp;
   struct adouble ad;
  
+  ad_init(&ad, AD_VERSION2, 0);
   if (argc != 2) {
     fprintf(stderr, "%s <directory>\n", *argv);
     return -1;
@@ -121,15 +137,14 @@ int main(int argc, char **argv)
   closedir(dp);
   chdir("..");
 
-  xlate(argv[1], ADFLAGS_HF | ADFLAGS_DIR);
   putc('\n', stderr);
   return 0;
 }
 
-#else
+#else /* AD_VERSION == AD_VERSION2 */
 int main(int argc, char **argv)
 {
   fprintf(stderr, "%s not built for v2 AppleDouble files.\n", *argv);
   return -1;
 }
-#endif
+#endif /* AD_VERSION == AD_VERSION2 */