aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-11-29 21:52:06 +0000
committerEric Andersen <andersen@codepoet.org>2000-11-29 21:52:06 +0000
commitcf1189f5a709ed52f862775af63dbf75b8124ccd (patch)
treeeba6e3ea3ac5221c19718d75b7505a2cbf716b76
parent4bfb6b7b67ff4238fde52e4019efe2284b9f99ef (diff)
downloadbusybox-w32-cf1189f5a709ed52f862775af63dbf75b8124ccd.tar.gz
busybox-w32-cf1189f5a709ed52f862775af63dbf75b8124ccd.tar.bz2
busybox-w32-cf1189f5a709ed52f862775af63dbf75b8124ccd.zip
Patch from Matt Kraai to fix an infinate loop with ls -aR
-rw-r--r--coreutils/ls.c38
-rw-r--r--ls.c38
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 @@
127 127
128#define SPLIT_DIR 0 128#define SPLIT_DIR 0
129#define SPLIT_FILE 1 129#define SPLIT_FILE 1
130#define SPLIT_SUBDIR 2
130 131
131#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f) 132#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
132#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)]) 133#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
@@ -236,11 +237,16 @@ static void nexttabstop( void )
236} 237}
237 238
238/*----------------------------------------------------------------------*/ 239/*----------------------------------------------------------------------*/
240static int is_subdir(struct dnode *dn)
241{
242 return (S_ISDIR(dn->dstat.st_mode) && strcmp(dn->name, ".") != 0 &&
243 strcmp(dn->name, "..") != 0);
244}
245
239int countdirs(struct dnode **dn, int nfiles) 246int countdirs(struct dnode **dn, int nfiles)
240{ 247{
241 int i, dirs; 248 int i, dirs;
242 249
243 /* count how many dirs and regular files there are */
244 if (dn==NULL || nfiles < 1) return(0); 250 if (dn==NULL || nfiles < 1) return(0);
245 dirs= 0; 251 dirs= 0;
246 for (i=0; i<nfiles; i++) { 252 for (i=0; i<nfiles; i++) {
@@ -249,6 +255,18 @@ int countdirs(struct dnode **dn, int nfiles)
249 return(dirs); 255 return(dirs);
250} 256}
251 257
258int countsubdirs(struct dnode **dn, int nfiles)
259{
260 int i, subdirs;
261
262 if (dn == NULL || nfiles < 1) return 0;
263 subdirs = 0;
264 for (i = 0; i < nfiles; i++)
265 if (is_subdir(dn[i]))
266 subdirs++;
267 return subdirs;
268}
269
252int countfiles(struct dnode **dnp) 270int countfiles(struct dnode **dnp)
253{ 271{
254 int nfiles; 272 int nfiles;
@@ -296,9 +314,13 @@ struct dnode **splitdnarray(struct dnode **dn, int nfiles, int which)
296 if (dn==NULL || nfiles < 1) return(NULL); 314 if (dn==NULL || nfiles < 1) return(NULL);
297 315
298 /* count how many dirs and regular files there are */ 316 /* count how many dirs and regular files there are */
299 dncnt= countdirs(dn, nfiles); /* assume we are looking for dirs */ 317 if (which == SPLIT_SUBDIR)
300 if (which != SPLIT_DIR) 318 dncnt = countsubdirs(dn, nfiles);
301 dncnt= nfiles - dncnt; /* looking for files */ 319 else {
320 dncnt= countdirs(dn, nfiles); /* assume we are looking for dirs */
321 if (which == SPLIT_FILE)
322 dncnt= nfiles - dncnt; /* looking for files */
323 }
302 324
303 /* allocate a file array and a dir array */ 325 /* allocate a file array and a dir array */
304 dnp= dnalloc(dncnt); 326 dnp= dnalloc(dncnt);
@@ -309,6 +331,10 @@ struct dnode **splitdnarray(struct dnode **dn, int nfiles, int which)
309 if (S_ISDIR(dn[i]->dstat.st_mode)) { 331 if (S_ISDIR(dn[i]->dstat.st_mode)) {
310 dnp[d++]= dn[i]; 332 dnp[d++]= dn[i];
311 } /* else skip the file */ 333 } /* else skip the file */
334 } else if (which == SPLIT_SUBDIR) {
335 if (is_subdir(dn[i])) {
336 dnp[d++]= dn[i];
337 } /* else skip the file or dir */
312 } else { 338 } else {
313 if (!(S_ISDIR(dn[i]->dstat.st_mode))) { 339 if (!(S_ISDIR(dn[i]->dstat.st_mode))) {
314 dnp[d++]= dn[i]; 340 dnp[d++]= dn[i];
@@ -455,8 +481,8 @@ void showdirs(struct dnode **dn, int ndirs)
455#ifdef BB_FEATURE_LS_RECURSIVE 481#ifdef BB_FEATURE_LS_RECURSIVE
456 if (disp_opts & DISP_RECURSIVE) { 482 if (disp_opts & DISP_RECURSIVE) {
457 /* recursive- list the sub-dirs */ 483 /* recursive- list the sub-dirs */
458 dnd= splitdnarray(subdnp, nfiles, SPLIT_DIR); 484 dnd= splitdnarray(subdnp, nfiles, SPLIT_SUBDIR);
459 dndirs= countdirs(subdnp, nfiles); 485 dndirs= countsubdirs(subdnp, nfiles);
460 if (dndirs > 0) { 486 if (dndirs > 0) {
461#ifdef BB_FEATURE_LS_SORTFILES 487#ifdef BB_FEATURE_LS_SORTFILES
462 shellsort(dnd, dndirs); 488 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 @@
127 127
128#define SPLIT_DIR 0 128#define SPLIT_DIR 0
129#define SPLIT_FILE 1 129#define SPLIT_FILE 1
130#define SPLIT_SUBDIR 2
130 131
131#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f) 132#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
132#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)]) 133#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
@@ -236,11 +237,16 @@ static void nexttabstop( void )
236} 237}
237 238
238/*----------------------------------------------------------------------*/ 239/*----------------------------------------------------------------------*/
240static int is_subdir(struct dnode *dn)
241{
242 return (S_ISDIR(dn->dstat.st_mode) && strcmp(dn->name, ".") != 0 &&
243 strcmp(dn->name, "..") != 0);
244}
245
239int countdirs(struct dnode **dn, int nfiles) 246int countdirs(struct dnode **dn, int nfiles)
240{ 247{
241 int i, dirs; 248 int i, dirs;
242 249
243 /* count how many dirs and regular files there are */
244 if (dn==NULL || nfiles < 1) return(0); 250 if (dn==NULL || nfiles < 1) return(0);
245 dirs= 0; 251 dirs= 0;
246 for (i=0; i<nfiles; i++) { 252 for (i=0; i<nfiles; i++) {
@@ -249,6 +255,18 @@ int countdirs(struct dnode **dn, int nfiles)
249 return(dirs); 255 return(dirs);
250} 256}
251 257
258int countsubdirs(struct dnode **dn, int nfiles)
259{
260 int i, subdirs;
261
262 if (dn == NULL || nfiles < 1) return 0;
263 subdirs = 0;
264 for (i = 0; i < nfiles; i++)
265 if (is_subdir(dn[i]))
266 subdirs++;
267 return subdirs;
268}
269
252int countfiles(struct dnode **dnp) 270int countfiles(struct dnode **dnp)
253{ 271{
254 int nfiles; 272 int nfiles;
@@ -296,9 +314,13 @@ struct dnode **splitdnarray(struct dnode **dn, int nfiles, int which)
296 if (dn==NULL || nfiles < 1) return(NULL); 314 if (dn==NULL || nfiles < 1) return(NULL);
297 315
298 /* count how many dirs and regular files there are */ 316 /* count how many dirs and regular files there are */
299 dncnt= countdirs(dn, nfiles); /* assume we are looking for dirs */ 317 if (which == SPLIT_SUBDIR)
300 if (which != SPLIT_DIR) 318 dncnt = countsubdirs(dn, nfiles);
301 dncnt= nfiles - dncnt; /* looking for files */ 319 else {
320 dncnt= countdirs(dn, nfiles); /* assume we are looking for dirs */
321 if (which == SPLIT_FILE)
322 dncnt= nfiles - dncnt; /* looking for files */
323 }
302 324
303 /* allocate a file array and a dir array */ 325 /* allocate a file array and a dir array */
304 dnp= dnalloc(dncnt); 326 dnp= dnalloc(dncnt);
@@ -309,6 +331,10 @@ struct dnode **splitdnarray(struct dnode **dn, int nfiles, int which)
309 if (S_ISDIR(dn[i]->dstat.st_mode)) { 331 if (S_ISDIR(dn[i]->dstat.st_mode)) {
310 dnp[d++]= dn[i]; 332 dnp[d++]= dn[i];
311 } /* else skip the file */ 333 } /* else skip the file */
334 } else if (which == SPLIT_SUBDIR) {
335 if (is_subdir(dn[i])) {
336 dnp[d++]= dn[i];
337 } /* else skip the file or dir */
312 } else { 338 } else {
313 if (!(S_ISDIR(dn[i]->dstat.st_mode))) { 339 if (!(S_ISDIR(dn[i]->dstat.st_mode))) {
314 dnp[d++]= dn[i]; 340 dnp[d++]= dn[i];
@@ -455,8 +481,8 @@ void showdirs(struct dnode **dn, int ndirs)
455#ifdef BB_FEATURE_LS_RECURSIVE 481#ifdef BB_FEATURE_LS_RECURSIVE
456 if (disp_opts & DISP_RECURSIVE) { 482 if (disp_opts & DISP_RECURSIVE) {
457 /* recursive- list the sub-dirs */ 483 /* recursive- list the sub-dirs */
458 dnd= splitdnarray(subdnp, nfiles, SPLIT_DIR); 484 dnd= splitdnarray(subdnp, nfiles, SPLIT_SUBDIR);
459 dndirs= countdirs(subdnp, nfiles); 485 dndirs= countsubdirs(subdnp, nfiles);
460 if (dndirs > 0) { 486 if (dndirs > 0) {
461#ifdef BB_FEATURE_LS_SORTFILES 487#ifdef BB_FEATURE_LS_SORTFILES
462 shellsort(dnd, dndirs); 488 shellsort(dnd, dndirs);