Some time ago I contributed an extension to ls.c.
Recently I found that my version, which (let it be said) offers an
amount of advantages over the previous one, also has a little bug: when
passed one single file specification, it assumed it was a directory,
with imaginable consequences.
here I contribute a correction to that bug.
if I didn't make a complete mess of my software development environment,
you should be able to apply the present patch to the 2000-01-07 elkscmd.
Mario.
--- ls.c Tue Dec 7 09:43:00 1999
+++ /mnt/fata/ls.c Fri Jan 21 11:36:42 2000
@@ -491,23 +491,19 @@
if (argv[1])
flags |= LSF_MULT;
-
- if(argc == 1 && recursive){
+ for(;*argv; argv++)
+ {
if (LSTAT(*argv, &statbuf) < 0) {
perror(*argv);
exit(1);
}
- if (S_ISDIR(statbuf.st_mode))
- {
- recursive--;
- getfiles( *argv, &files );
+ if (recursive && S_ISDIR(statbuf.st_mode))
+ pushStack(&dirs, strdup(*argv) );
+ else
+ pushStack(&files, strdup(*argv) );
}
if(recursive)
- printf("%s:\n", *argv);
- }
- else
- while(*argv)
- pushStack(&files, strdup(*argv++) );
+ recursive--;
sortStack(&files);
@@ -519,7 +515,7 @@
while(!isEmptyStack(&files)){
name = popStack(&files);
- TRACESTRING(name);
+ TRACESTRING(name)
if (LSTAT(name, &statbuf) < 0) {
perror(name);
@@ -544,6 +540,7 @@
}
printf("\n%s:\n", name);
free(name);
+ if(recursive)
recursive--;
}
} while(!isEmptyStack(&files) || !isEmptyStack(&dirs));