From cf1189f5a709ed52f862775af63dbf75b8124ccd Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Wed, 29 Nov 2000 21:52:06 +0000 Subject: [PATCH] Patch from Matt Kraai to fix an infinate loop with ls -aR --- coreutils/ls.c | 38 ++++++++++++++++++++++++++++++++------ ls.c | 38 ++++++++++++++++++++++++++++++++------ 2 files changed, 64 insertions(+), 12 deletions(-) diff --git a/coreutils/ls.c b/coreutils/ls.c index b1fbe3b2a..d508a1bfe 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -127,6 +127,7 @@ #define SPLIT_DIR 0 #define SPLIT_FILE 1 +#define SPLIT_SUBDIR 2 #define TYPEINDEX(mode) (((mode) >> 12) & 0x0f) #define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)]) @@ -236,11 +237,16 @@ static void nexttabstop( void ) } /*----------------------------------------------------------------------*/ +static int is_subdir(struct dnode *dn) +{ + return (S_ISDIR(dn->dstat.st_mode) && strcmp(dn->name, ".") != 0 && + strcmp(dn->name, "..") != 0); +} + int countdirs(struct dnode **dn, int nfiles) { int i, dirs; - /* count how many dirs and regular files there are */ if (dn==NULL || nfiles < 1) return(0); dirs= 0; for (i=0; idstat.st_mode)) { dnp[d++]= dn[i]; } /* else skip the file */ + } else if (which == SPLIT_SUBDIR) { + if (is_subdir(dn[i])) { + dnp[d++]= dn[i]; + } /* else skip the file or dir */ } else { if (!(S_ISDIR(dn[i]->dstat.st_mode))) { dnp[d++]= dn[i]; @@ -455,8 +481,8 @@ void showdirs(struct dnode **dn, int ndirs) #ifdef BB_FEATURE_LS_RECURSIVE if (disp_opts & DISP_RECURSIVE) { /* recursive- list the sub-dirs */ - dnd= splitdnarray(subdnp, nfiles, SPLIT_DIR); - dndirs= countdirs(subdnp, nfiles); + dnd= splitdnarray(subdnp, nfiles, SPLIT_SUBDIR); + dndirs= countsubdirs(subdnp, nfiles); if (dndirs > 0) { #ifdef BB_FEATURE_LS_SORTFILES shellsort(dnd, dndirs); diff --git a/ls.c b/ls.c index b1fbe3b2a..d508a1bfe 100644 --- a/ls.c +++ b/ls.c @@ -127,6 +127,7 @@ #define SPLIT_DIR 0 #define SPLIT_FILE 1 +#define SPLIT_SUBDIR 2 #define TYPEINDEX(mode) (((mode) >> 12) & 0x0f) #define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)]) @@ -236,11 +237,16 @@ static void nexttabstop( void ) } /*----------------------------------------------------------------------*/ +static int is_subdir(struct dnode *dn) +{ + return (S_ISDIR(dn->dstat.st_mode) && strcmp(dn->name, ".") != 0 && + strcmp(dn->name, "..") != 0); +} + int countdirs(struct dnode **dn, int nfiles) { int i, dirs; - /* count how many dirs and regular files there are */ if (dn==NULL || nfiles < 1) return(0); dirs= 0; for (i=0; idstat.st_mode)) { dnp[d++]= dn[i]; } /* else skip the file */ + } else if (which == SPLIT_SUBDIR) { + if (is_subdir(dn[i])) { + dnp[d++]= dn[i]; + } /* else skip the file or dir */ } else { if (!(S_ISDIR(dn[i]->dstat.st_mode))) { dnp[d++]= dn[i]; @@ -455,8 +481,8 @@ void showdirs(struct dnode **dn, int ndirs) #ifdef BB_FEATURE_LS_RECURSIVE if (disp_opts & DISP_RECURSIVE) { /* recursive- list the sub-dirs */ - dnd= splitdnarray(subdnp, nfiles, SPLIT_DIR); - dndirs= countdirs(subdnp, nfiles); + dnd= splitdnarray(subdnp, nfiles, SPLIT_SUBDIR); + dndirs= countsubdirs(subdnp, nfiles); if (dndirs > 0) { #ifdef BB_FEATURE_LS_SORTFILES shellsort(dnd, dndirs);