summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2009-09-29 15:43:01 +0100
committerPádraig Brady <P@draigBrady.com>2009-09-30 15:42:35 +0100
commitd4c7114bce116aefe28c899f5d0e7dcc39feb103 (patch)
tree39f8d349167efadb14da112fddfccd98569b8bf4 /src
parentce1069c2151da3fffc70281a14b96034ba15da5a (diff)
downloadcoreutils-d4c7114bce116aefe28c899f5d0e7dcc39feb103.tar.xz
ls: always print "?" for allocated size of a dereferenced dangling symlink
Previously for `ls -Ls` (but not `ls -Lsl`), we referenced the st_blocks returned from the previous failed stat() call. This undefined value was seen to be 0 for dangling symlinks at least. * src/ls.c (print_file_name_and_frills, length_of_file_name_and_frills): Don't use st_blocks if the previous stat() failed * tests/ls/dangle: Add a test case * NEWS: Mention the fix, and roll up related items into a single entry.
Diffstat (limited to 'src')
-rw-r--r--src/ls.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/ls.c b/src/ls.c
index 801e717c6..30df92c1a 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -4016,8 +4016,9 @@ print_file_name_and_frills (const struct fileinfo *f, size_t start_col)
if (print_block_size)
printf ("%*s ", format == with_commas ? 0 : block_size_width,
- human_readable (ST_NBLOCKS (f->stat), buf, human_output_opts,
- ST_NBLOCKSIZE, output_block_size));
+ ! f->stat_ok ? "?"
+ : human_readable (ST_NBLOCKS (f->stat), buf, human_output_opts,
+ ST_NBLOCKSIZE, output_block_size));
if (print_scontext)
printf ("%*s ", format == with_commas ? 0 : scontext_width, f->scontext);
@@ -4234,9 +4235,10 @@ length_of_file_name_and_frills (const struct fileinfo *f)
if (print_block_size)
len += 1 + (format == with_commas
- ? strlen (human_readable (ST_NBLOCKS (f->stat), buf,
- human_output_opts, ST_NBLOCKSIZE,
- output_block_size))
+ ? strlen (! f->stat_ok ? "?"
+ : human_readable (ST_NBLOCKS (f->stat), buf,
+ human_output_opts, ST_NBLOCKSIZE,
+ output_block_size))
: block_size_width);
if (print_scontext)