summaryrefslogtreecommitdiff
path: root/src/ls.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1995-09-29 04:09:22 +0000
committerJim Meyering <jim@meyering.net>1995-09-29 04:09:22 +0000
commit527d04d44b99b07afb74bfa9007099147918be6c (patch)
treed232e9e31ce97a56dbb29e2b31abd785422c3dc0 /src/ls.c
parent9a12d0521603fc52dbea0cd1f9b91d0eb2cfbbde (diff)
downloadcoreutils-527d04d44b99b07afb74bfa9007099147918be6c.tar.xz
(dired_dump_obstack): Don't generate any output if the obstack is empty.
(main): Always initialize and dump subdired_obstack, not just if -R. `ls -lDR dir dir2' was using uninitialized subdired_obstack. Reported by Samuli K{rkk{inen <hskarkka@snakemail.hut.fi>.
Diffstat (limited to 'src/ls.c')
-rw-r--r--src/ls.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/ls.c b/src/ls.c
index d3c0e8b54..429e68b11 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -548,8 +548,11 @@ static size_t dired_pos;
/* With --dired, store pairs of beginning and ending indices of filenames. */
static struct obstack dired_obstack;
-/* With --dired and --recursive, store pairs of beginning and ending
- indices of directory names. */
+/* With --dired, store pairs of beginning and ending indices of any
+ directory names that appear as headers (just before `total' line)
+ for lists of directory entries. Such directory names are seen when
+ listing hierarchies using -R and when a directory is listed with at
+ least one other command line argument. */
static struct obstack subdired_obstack;
/* Save the current index on the specified obstack, OBS. */
@@ -586,15 +589,20 @@ dired_dump_obstack (prefix, os)
const char *prefix;
struct obstack *os;
{
- int i, n_pos;
- size_t *pos;
+ int n_pos;
- fputs (prefix, stdout);
n_pos = obstack_object_size (os) / sizeof (size_t);
- pos = (size_t *) obstack_finish (os);
- for (i = 0; i < n_pos; i++)
- printf (" %d", (int) pos[i]);
- fputs ("\n", stdout);
+ if (n_pos > 0)
+ {
+ int i;
+ size_t *pos;
+
+ pos = (size_t *) obstack_finish (os);
+ fputs (prefix, stdout);
+ for (i = 0; i < n_pos; i++)
+ printf (" %d", (int) pos[i]);
+ fputs ("\n", stdout);
+ }
}
void
@@ -631,8 +639,7 @@ main (argc, argv)
if (dired && format == long_format)
{
obstack_init (&dired_obstack);
- if (trace_dirs)
- obstack_init (&subdired_obstack);
+ obstack_init (&subdired_obstack);
}
nfiles = 100;
@@ -686,8 +693,7 @@ main (argc, argv)
{
/* No need to free these since we're about to exit. */
dired_dump_obstack ("//DIRED//", &dired_obstack);
- if (trace_dirs)
- dired_dump_obstack ("//SUBDIRED//", &subdired_obstack);
+ dired_dump_obstack ("//SUBDIRED//", &subdired_obstack);
}
exit (exit_status);