From: Jim Meyering Date: Sat, 21 Apr 2001 09:47:39 +0000 (+0000) Subject: (main): When given two or more arguments but the only one X-Git-Tag: FILEUTILS-4_0_44~13 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=e1e14bdb38fe946d5c6bde8a1f47637dc2e58f77;p=thirdparty%2Fcoreutils.git (main): When given two or more arguments but the only one that exists is a directory, don't treat it as if it were the only argument. Before, `mkdir d; ls no-dir d 2>/dev/null' would act like `ls d' and produce no output. Now, it prints `d:'. --- diff --git a/src/ls.c b/src/ls.c index c690126357..7eb50aa64c 100644 --- a/src/ls.c +++ b/src/ls.c @@ -340,16 +340,13 @@ char *program_name; `files_index' is the number actually in use. */ /* Address of block containing the files that are described. */ - -static struct fileinfo *files; +static struct fileinfo *files; /* FIXME: rename this to e.g. cwd_file */ /* Length of block that `files' points to, measured in files. */ - -static int nfiles; +static int nfiles; /* FIXME: rename this to e.g. cwd_n_alloc */ /* Index of first unused in `files'. */ - -static int files_index; +static int files_index; /* FIXME: rename this to e.g. cwd_n_used */ /* When nonzero, in a color listing, color each symlink name according to the type of file it points to. Otherwise, color them according to the `ln' @@ -849,6 +846,7 @@ main (int argc, char **argv) { register int i; register struct pending *thispend; + unsigned int n_files; program_name = argv[0]; setlocale (LC_ALL, ""); @@ -896,8 +894,10 @@ main (int argc, char **argv) clear_files (); - if (i < argc) + n_files = argc - i; + if (0 <= n_files) dir_defaulted = 0; + for (; i < argc; i++) { gobble_file (argv[i], unknown, 1, ""); @@ -924,7 +924,7 @@ main (int argc, char **argv) if (pending_dirs) DIRED_PUTCHAR ('\n'); } - else if (pending_dirs && pending_dirs->next == 0) + else if (n_files <= 1 && pending_dirs && pending_dirs->next == 0) print_dir_name = 0; while (pending_dirs)