]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Merge in Ulrich's and my changes from libc.
authorJim Meyering <jim@meyering.net>
Tue, 14 Jan 2003 12:58:22 +0000 (12:58 +0000)
committerJim Meyering <jim@meyering.net>
Tue, 14 Jan 2003 12:58:22 +0000 (12:58 +0000)
lib/ftw.c

index 29c72db1da8b796c09d04a3254d15095f4168154..b7583db12b35d0f1857e26265027d901609829a3 100644 (file)
--- a/lib/ftw.c
+++ b/lib/ftw.c
@@ -146,7 +146,7 @@ struct ftw_data
 
 
 /* Internally we use the FTW_* constants used for `nftw'.  When invoked
-   as `ftw' map the flag to the subset of values used by `ftw'.  */
+   as `ftw', map each flag to the subset of values used by `ftw'.  */
 static const int nftw_arr[] =
 {
   FTW_F, FTW_D, FTW_DNR, FTW_NS, FTW_SL, FTW_DP, FTW_SLN
@@ -225,7 +225,7 @@ open_dir_stream (struct ftw_data *data, struct dir_data *dirp)
                {
                  char *newp;
                  bufsize += MAX (1024, 2 * this_len);
-                 newp = realloc (buf, bufsize);
+                 newp = (char *) realloc (buf, bufsize);
                  if (newp == NULL)
                    {
                      /* No more memory.  */
@@ -307,7 +307,7 @@ process_entry (struct ftw_data *data, struct dir_data *dir, const char *name,
       char *newp;
 
       data->dirbufsize *= 2;
-      newp = realloc (data->dirbuf, data->dirbufsize);
+      newp = (char *) realloc (data->dirbuf, data->dirbufsize);
       if (newp == NULL)
        return -1;
       data->dirbuf = newp;
@@ -315,7 +315,7 @@ process_entry (struct ftw_data *data, struct dir_data *dir, const char *name,
 
   *((char *) __mempcpy (data->dirbuf + data->ftw.base, name, namlen)) = '\0';
 
-  if ( ! (data->flags & FTW_CHDIR))
+  if ((data->flags & FTW_CHDIR) == 0)
     name = data->dirbuf;
 
   if (((data->flags & FTW_PHYS)
@@ -370,15 +370,8 @@ process_entry (struct ftw_data *data, struct dir_data *dir, const char *name,
                            result = -1;
                        }
                      else
-                       {
-                         /* Please note that we overwrite a slash.  */
-                         data->dirbuf[data->ftw.base - 1] = '\0';
-
-                         if (__chdir (data->dirbuf) < 0)
-                           result = -1;
-
-                         data->dirbuf[data->ftw.base - 1] = '/';
-                       }
+                       if (__chdir ("..") < 0)
+                         result = -1;
                    }
                }
            }
@@ -604,13 +597,17 @@ ftw_startup (const char *dir, int is_nftw, void *func, int descriptors,
   /* Get stat info for start directory.  */
   if (result == 0)
     {
+      const char *name = ((data.flags & FTW_CHDIR)
+                         ? data.dirbuf + data.ftw.base
+                         : data.dirbuf);
+
       if (((flags & FTW_PHYS)
-          ? LXSTAT (_STAT_VER, data.dirbuf, &st)
-          : XSTAT (_STAT_VER, data.dirbuf, &st)) < 0)
+          ? LXSTAT (_STAT_VER, name, &st)
+          : XSTAT (_STAT_VER, name, &st)) < 0)
        {
          if (!(flags & FTW_PHYS)
              && errno == ENOENT
-             && LXSTAT (_STAT_VER, dir, &st) == 0
+             && LXSTAT (_STAT_VER, name, &st) == 0
              && S_ISLNK (st.st_mode))
            result = (*data.func) (data.dirbuf, &st, data.cvt_arr[FTW_SLN],
                                   &data.ftw);