summaryrefslogtreecommitdiff
path: root/ls.c
diff options
context:
space:
mode:
Diffstat (limited to 'ls.c')
-rw-r--r--ls.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/ls.c b/ls.c
index 5d90802..8ec0ae2 100644
--- a/ls.c
+++ b/ls.c
@@ -59,15 +59,6 @@ static enum {
ATIME,
} sort = ALPHA;
-#define CHARACTER 1 << 0
-#define INODES 1 << 1
-#define DIRS 1 << 2
-#define QUOTE 1 << 3
-#define BLOCKS 1 << 4
-
-#define FOLLOW 1
-#define LLONG 2
-
#define DEFAULT_BLOCK_SIZE 512
static enum { HIDE_ALL, HIDE_SOME, HIDE_NONE } ls_hidden = HIDE_ALL;
@@ -150,7 +141,7 @@ static int ls_compare_files(const void *op_a, const void *op_b)
return (reverse ? -1 : 1) * ret;
}
-static int ls_dir(char *dir)
+static int ls_dir(char *dir, int showdirname)
{
size_t nfiles = 0;
struct file_info *files = NULL;
@@ -201,6 +192,9 @@ static int ls_dir(char *dir)
closedir(d);
qsort(files, nfiles, sizeof(*files), ls_compare_files);
+ if (showdirname) {
+ printf("%s:\n", dir);
+ }
ls_print(nfiles, files);
free(files);
@@ -585,7 +579,7 @@ int main(int argc, char *argv[])
size_t nfiles = 0;
struct file_info *op = operands;
while (op->path != NULL) {
- if (list_dirs_separately && !S_ISDIR(op->st.st_mode)) {
+ if (list_dirs_separately && S_ISDIR(op->st.st_mode)) {
break;
}
op++;
@@ -599,12 +593,15 @@ int main(int argc, char *argv[])
}
while (op->path != NULL) {
- ls_dir(op->path);
+ ls_dir(op->path, (size_t)argc > nfiles + 1);
op++;
+ if (op->path) {
+ printf("\n");
+ }
}
if (argc == 0) {
- return ls_dir(".");
+ return ls_dir(".", 0);
}
return ret;