Blob Blame History Raw
diff -urNp coreutils-7.6-orig/src/ls.c coreutils-7.6/src/ls.c
--- coreutils-7.6-orig/src/ls.c	2009-11-23 10:31:08.000000000 +0100
+++ coreutils-7.6/src/ls.c	2009-11-23 10:35:47.000000000 +0100
@@ -3592,6 +3592,18 @@ format_group_width (gid_t g)
 }
 
 
+/* Return a pointer to a formatted version of F->stat.st_ino,
+   possibly using buffer, BUF, of length BUFLEN, which must be at least
+   INT_BUFSIZE_BOUND (uintmax_t) bytes.  */
+static char *
+format_inode (char *buf, size_t buflen, const struct fileinfo *f)
+{
+  assert (INT_BUFSIZE_BOUND (uintmax_t) <= buflen);
+  return (f->stat.st_ino == NOT_AN_INODE_NUMBER
+          ? (char *) "?"
+          : umaxtostr (f->stat.st_ino, buf));
+}
+
 /* Print info about f in scontext format */
 static void
 print_scontext_format (const struct fileinfo *f)
@@ -3713,9 +3725,7 @@ print_long_format (const struct fileinfo
     {
       char hbuf[INT_BUFSIZE_BOUND (uintmax_t)];
       sprintf (p, "%*s ", inode_number_width,
-               (f->stat.st_ino == NOT_AN_INODE_NUMBER
-                ? "?"
-                : umaxtostr (f->stat.st_ino, hbuf)));
+               format_inode (hbuf, sizeof hbuf, f));
       /* Increment by strlen (p) here, rather than by inode_number_width + 1.
          The latter is wrong when inode_number_width is zero.  */
       p += strlen (p);
@@ -4105,7 +4115,7 @@ print_file_name_and_frills (const struct
 
   if (print_inode)
     printf ("%*s ", format == with_commas ? 0 : inode_number_width,
-            umaxtostr (f->stat.st_ino, buf));
+             format_inode (buf, sizeof buf, f));
 
   if (print_block_size)
     printf ("%*s ", format == with_commas ? 0 : block_size_width,
diff -urNp coreutils-7.6-orig/tests/ls/dangle coreutils-7.6/tests/ls/dangle
--- coreutils-7.6-orig/tests/ls/dangle	2009-09-01 13:01:16.000000000 +0200
+++ coreutils-7.6/tests/ls/dangle	2009-11-23 10:37:44.000000000 +0100
@@ -26,6 +26,9 @@ fi
 ln -s no-such-file dangle || framework_failure
 mkdir -p dir/sub || framework_failure
 ln -s dir slink-to-dir || framework_failure
+mkdir d || framework_failure
+ln -s no-such d/dangle || framework_failure
+echo '? dangle' > subdir_exp || framework_failure
 
 fail=0
 
@@ -50,4 +53,9 @@ EOF
 
 compare out exp || fail=1
 
+# Ensure that ls -Li prints "?" as the inode of a dangling symlink.
+rm -f out
+ls -Li d > out 2>/dev/null && fail=1
+compare out subdir_exp || fail=1
+
 Exit $fail