quilt-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Quilt-dev] [patch 3/8] Unmerged patches regenerated against CVS HEAD


From: Gary V. Vaughan
Subject: [Quilt-dev] [patch 3/8] Unmerged patches regenerated against CVS HEAD
Date: Thu, 22 Sep 2005 13:27:03 +0100
User-agent: quilt/0.42-1

Although Mac OS X 10.4 (I'm running 10.4.2) has nftw and ftw compatibility
functions, and code that uses them seems to build and link properly: the
resulting calls do nothing, which breaks `quilt pop' at least.

This patch reimplements the file tree walk manually with dirent, which is
fully supported even on old host architectures.

 lib/backup-files.c |   95 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 83 insertions(+), 12 deletions(-)

Index: quilt-HEAD/lib/backup-files.c
===================================================================
--- quilt-HEAD.orig/lib/backup-files.c
+++ quilt-HEAD/lib/backup-files.c
@@ -40,7 +40,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
-#include <ftw.h>
+#include <dirent.h>
 
 #if !defined(HAVE_MKSTEMP) && defined(HAVE_MKTEMP)
 # define mkstemp(x) creat(mktemp(x), 0600)
@@ -335,19 +335,87 @@ fail:
 }
 
 int
-walk(const char *path, const struct stat *stat, int flag, struct FTW *ftw)
+searchdir_p (const char *path, int complain)
+{
+       struct stat st;
+
+       /* ignore missing files */
+       if (stat(path, &st) != 0) {
+               if (complain) perror (path);
+               return 0;
+       }
+       /* and non-directories */
+       if (!S_ISDIR(st.st_mode)) {
+               if (complain)
+                       fprintf(stderr, "%s: not a directory\n", path);
+               return 0;
+       }
+       /* no access permission */
+       if (access(path, R_OK|X_OK) != 0) {
+               if (complain) perror (path);
+               return 0;
+       }
+
+       return 1;
+}
+
+int
+foreachdir (const char *root, int(*walk)(const char *))
+{
+       int errors = 0;
+       DIR *dir;
+
+       if (!searchdir_p(root, 1))
+               return 0;
+
+        dir = opendir(root);
+       if (dir) {
+               struct dirent *dp = 0;
+
+               while ((dp = readdir(dir))) {
+                       if (strcmp(dp->d_name, ".")
+                           && strcmp(dp->d_name, "..")) {
+                               char *path = malloc_nofail (2+ strlen (root) +
+                                                    strlen (dp->d_name));
+                               sprintf (path, "%s/%s", root, dp->d_name);
+                               if (searchdir_p (path, 0)) {
+                                       /* depth first recurse */
+                                       errors += foreachdir(path, walk);
+                               } else {
+                                       struct stat st;
+                                       if (stat(path, &st) != 0) {
+                                               /* ignore missing files */
+                                               continue;
+                                       }
+                                       if (S_ISREG(st.st_mode)) {
+                                               /* process regular files */
+                                               errors += walk(path);
+                                       }
+                               }
+                               free(path);
+                       }
+                       if (errors > 0) {
+                               break;
+                       }
+               }
+       }
+
+       if (closedir(dir) !=0) {
+               ++errors;
+               perror(root);
+       }
+
+       return errors;
+}
+
+int
+ftwalk(const char *path)
 {
        size_t prefix_len=strlen(opt_prefix), suffix_len=strlen(opt_suffix);
        size_t len = strlen(path);
        char *p;
        int ret;
 
-       if (flag == FTW_DNR) {
-               perror(path);
-               return 1;
-       }
-       if (!S_ISREG(stat->st_mode))
-               return 0;
        if (strncmp(opt_prefix, path, prefix_len))
                return 0;  /* prefix does not match */
        if (len < suffix_len || strcmp(opt_suffix, path + len - suffix_len))
@@ -450,13 +518,16 @@ main(int argc, char *argv[])
        }
        for (; optind < argc; optind++) {
                if (strcmp(argv[optind], "-") == 0) {
-                       char *dir = strdup(opt_prefix), *d = strrchr(dir, '/');
+                       char *dir, *d;
+
+                       dir = strdup(opt_prefix);
+                       d = strrchr(dir, '/');
                        if (d)
-                               *(d+1) = '\0';
+                               *d = '\0';
                        else
                                d = ".";
-                       status = nftw(dir, walk, 0, 0);
-                       free(dir);
+
+                       foreachdir (dir, ftwalk);
                } else
                        status = process_file(argv[optind]);
                if (status)

--
Gary V. Vaughan      ())_.  address@hidden,gnu.org}
Research Scientist   ( '/   http://tkd.kicks-ass.net
GNU Hacker           / )=   http://www.gnu.org/software/libtool
Technical Author   `(_~)_   http://sources.redhat.com/autobook




reply via email to

[Prev in Thread] Current Thread [Next in Thread]