]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(main): When given two or more arguments but the only one
authorJim Meyering <jim@meyering.net>
Sat, 21 Apr 2001 09:47:39 +0000 (09:47 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 21 Apr 2001 09:47:39 +0000 (09:47 +0000)
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:'.

src/ls.c

index c69012635703e5cb7fa8977005fdec10375938bd..7eb50aa64c3da565b46def88ccb45f460de857ec 100644 (file)
--- 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)