-/* 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;
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;
}
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);
DIR *dp;
struct adouble ad;
+ ad_init(&ad, AD_VERSION2, 0);
if (argc != 2) {
fprintf(stderr, "%s <directory>\n", *argv);
return -1;
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 */