[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ls and root directory indicator

From: Sami Kerola
Subject: ls and root directory indicator
Date: Sun, 24 Feb 2013 17:39:32 +0000


When using file type indicator to a root, e.g.,

$ ls -Fd /

two slashes are printed. To me that feels wrong. Patch below is an
attempt to make root print out to be a single slash. Perhaps there is
more elegant way to do the same. Or maybe I am mistaking, and double
slash is correct, although I could not find earlier posting about

>From 639409e3355676cb786a403eea60c1ef4bbaf61d Mon Sep 17 00:00:00 2001
From: Sami Kerola <address@hidden>
Date: Sun, 24 Feb 2013 17:17:20 +0000
Subject: [PATCH] ls: do not print directory indicator for root

Previously 'ls -Fd /' printed unnecessary directory indicator.  The root
is represented by '/' character, which does not need to be repeated.
* src/ls.c: (print_long_format, print_file_name_and_frills): Check if a
output name is root, and skip indicator when necessary.
 src/ls.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/ls.c b/src/ls.c
index d9876f8..a8d02d2 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -3970,7 +3970,7 @@ print_long_format (const struct fileinfo *f)
             print_type_indicator (true, f->linkmode, unknown);
-  else if (indicator_style != none)
+  else if (indicator_style != none && strcmp(f->name, "/"))
     print_type_indicator (f->stat_ok, f->stat.st_mode, f->filetype);

@@ -4212,7 +4212,7 @@ print_file_name_and_frills (const struct
fileinfo *f, size_t start_col)

   size_t width = print_name_with_quoting (f, false, NULL, start_col);

-  if (indicator_style != none)
+  if (indicator_style != none && strcmp(f->name, "/"))
     width += print_type_indicator (f->stat_ok, f->stat.st_mode, f->filetype);

   return width;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]