]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
merge with 3.8.3
authorJim Meyering <jim@meyering.net>
Fri, 27 Aug 1993 04:43:46 +0000 (04:43 +0000)
committerJim Meyering <jim@meyering.net>
Fri, 27 Aug 1993 04:43:46 +0000 (04:43 +0000)
lib/Makefile.in
old/fileutils/ChangeLog
old/fileutils/NEWS
src/cp.c
src/install.c
src/ln.c
src/ls.c

index 3a71cac2b678b76f43807910e947cdcfc3c06996..ae30a2df5a944130e4ac03106e6dc5c858bafbad 100644 (file)
@@ -24,7 +24,7 @@ CC = @CC@
 AR = ar
 RANLIB = @RANLIB@
 DEFS = @DEFS@
-CFLAGS = -g
+CFLAGS = @CFLAGS@
 
 SOURCES = getdate.y posixtm.y \
 argmatch.c backupfile.c basename.c dirname.c eaccess.c \
index b74560f9723775726af3711e49220373b54a6fb1..4ededb20ee6845463919093750393b65ceb568e1 100644 (file)
@@ -1,4 +1,21 @@
-Wed Aug 25 21:40:00 EDT 1993
+Thu Aug 26 22:26:09 1993  Jim Meyering  (meyering@comco.com)
+
+       * ls.c (print_long_format, print_file_name_and_frills): Cast inode
+       number to unsigned long and print it with %lu to avoid warnings from
+       gcc -Wformat because the size and type of ino_t are system dependent.
+
+       * cp.c (do_copy): Plug a memory leak with --parents.
+
+       * ln.c (main): Like mv and cp, convert `ln x y/' to ln x y/x
+       when a is not a directory.
+       [PATH_BASENAME_CONCAT]: New macro.
+       (do_link): Use it here, too.
+
+       * ls.c (sort_files): Add `default: abort();' clause to switch stmts.
+
+       * cp.c (do_copy): Don't remove trailing slashes from source.
+
+Wed Aug 25 21:40:00 1993  Jim Meyering  (meyering@comco.com)
 
        * cp.c: Add --parents as synonym for --path.  Change --path to
        --parents in comments.  --path is deprecated.
@@ -16,13 +33,12 @@ Fri Aug 13 17:19:52 1993  Jim Meyering  (meyering@comco.com)
         (is_real_dir): New function.
         (movefile): In addition to when dest is a directory, if dest has
         a trailing `/' and source is not a directory, presume the target
-        is dest/`basename source`.  This converts `mv a b/' to `mv a b/a'
-       when a is not a directory -- so the command will fail when a is a
-       non-directory and (b doesn't exist or b isn't a directory or a
-       symlink to a directory).
+        is dest/`basename source`.  This converts `mv x y/' to `mv x y/x'
+       when x is not a directory.  This change means that the command
+       `mv any file/' will now fail rather than performing the move.
 
-       * ls.c (do_copy): Similarly, convert `cp a b/' to cp a b/a when
-       a is not a directory.
+       * cp.c (do_copy): Similarly, convert `cp x y/' to cp x y/x when
+       x is not a directory.
 
 Wed Aug  4 17:43:18 1993  Jim Meyering  (meyering@comco.com)
 
index 16246d08f413bddcf63d06d0a447a88ea971d615..e4121a4d9d78c8cb3b13ced5dae0fcfceef8e017 100644 (file)
@@ -2,6 +2,11 @@ Major changes in release 3.9:
 * ls and cp can handle mount points on more systems
 * cp, mkdir, and rmdir long option --path renamed to --parents;  --path
   will still work for a while
+* cp, ln, and mv convert `cp A B/' to cp A B/A when A is not a directory.
+  This change affects only the two-argument form of the commands.  It makes
+  such commands fail when the target has a trailing slash but is not a
+  directory or symlink to a directory and the source is not a directory.
+  They used to succeed, ignoring the implicitly contradictory trailing slash.
 \f
 Major changes in release 3.8:
 * install isn't as likely to produce spurious errors 
index 7ba6546799d0571acd6831ec7537c7f02ba7a02c..f6dd934e2852a6faca158072e49d8d35315454ff 100644 (file)
--- a/src/cp.c
+++ b/src/cp.c
@@ -41,6 +41,7 @@ struct dir_attr
 };
 
 char *dirname ();
+char *xstrdup ();
 enum backup_type get_version ();
 int eaccess_stat ();
 
@@ -375,7 +376,7 @@ do_copy (argc, argv)
              ap = basename (arg);
              /* For `cp -R source/.. dest', don't copy into `dest/..'. */
              if (!strcmp (ap, ".."))
-               dst_path = dest;
+               dst_path = xstrdup (dest);
              else
                {
                  dst_path = xmalloc (strlen (dest) + strlen (ap) + 2);
@@ -400,6 +401,7 @@ do_copy (argc, argv)
                }
            }
 
+         free (dst_path);
          ++optind;
          if (optind == argc - 1)
            break;
@@ -408,7 +410,7 @@ do_copy (argc, argv)
     }
   else if (argc - optind == 2)
     {
-      char *dst_path;
+      char *new_dest;
       char *source;
       struct stat source_stats;
 
@@ -417,23 +419,32 @@ do_copy (argc, argv)
 
       source = argv[optind];
 
+      /* When the destination is specified with a trailing slash and the
+        source exists but is not a directory, convert the user's command
+        `cp source dest/' to `cp source dest/basename(source)'.  */
+
       if (dest[strlen (dest) - 1] == '/'
          && lstat (source, &source_stats) == 0
          && !S_ISDIR (source_stats.st_mode))
        {
-         char *base;
+         char *source_base;
+         char *tmp_source;
+
+         tmp_source = (char *) alloca (strlen (source) + 1);
+         strcpy (tmp_source, source);
+         strip_trailing_slashes (tmp_source);
+         source_base = basename (tmp_source);
 
-         strip_trailing_slashes (source);
-         base = basename (source);
-         dst_path = (char *) alloca (strlen (dest) + 1 + strlen (base) + 1);
-         stpcpy (stpcpy (stpcpy (dst_path, dest), "/"), base);
+         new_dest = (char *) alloca (strlen (dest) + 1 +
+                                     strlen (source_base) + 1);
+         stpcpy (stpcpy (stpcpy (new_dest, dest), "/"), source_base);
        }
       else
        {
-         dst_path = dest;
+         new_dest = dest;
        }
 
-      return copy (argv[optind], dst_path, new_dst, 0, (struct dir_list *) 0);
+      return copy (source, new_dest, new_dst, 0, (struct dir_list *) 0);
     }
   else
     usage ("when copying multiple files, last argument must be a directory");
index 9d579c22de1cd2343538c6ff4850c8a7675fbbe4..e6fc16276fe0128ae04664090f798d544813cee9 100644 (file)
@@ -91,6 +91,7 @@ int wait ();
 #define READ_SIZE (32 * 1024)
 
 char *basename ();
+char *stpcpy ();
 char *xmalloc ();
 void error ();
 int make_path ();
@@ -291,7 +292,7 @@ install_file_in_dir (from, to_dir)
 
   from_base = basename (from);
   to = xmalloc ((unsigned) (strlen (to_dir) + strlen (from_base) + 2));
-  sprintf (to, "%s/%s", to_dir, from_base);
+  stpcpy (stpcpy (stpcpy (to, to_dir), "/"), from_base);
   ret = install_file_in_file (from, to);
   free (to);
   return ret;
index 95938f533fa08aef6d991abf59ccea8da60f6a5c..e2ddda982ecdf0289b638c6f73c2f46a1e041a70 100644 (file)
--- a/src/ln.c
+++ b/src/ln.c
@@ -33,12 +33,33 @@ int link ();                        /* Some systems don't declare this anywhere. */
 int symlink ();
 #endif
 
+/* Construct a string NEW_DEST by concatenating DEST, a slash, and
+   basename(SOURCE) in alloca'd memory.  Don't modify DEST or SOURCE.  */
+
+#define PATH_BASENAME_CONCAT(new_dest, dest, source)                   \
+    do                                                                 \
+      {                                                                        \
+       char *source_base;                                              \
+       char *tmp_source;                                               \
+                                                                       \
+       tmp_source = (char *) alloca (strlen ((source)) + 1);           \
+       strcpy (tmp_source, (source));                                  \
+       strip_trailing_slashes (tmp_source);                            \
+       source_base = basename (tmp_source);                            \
+                                                                       \
+       (new_dest) = (char *) alloca (strlen ((dest)) + 1               \
+                                     + strlen (source_base) + 1);      \
+       stpcpy (stpcpy (stpcpy ((new_dest), (dest)), "/"), source_base);\
+      }                                                                        \
+    while (0)
+
 char *basename ();
 enum backup_type get_version ();
 int isdir ();
 int yesno ();
 void error ();
 void strip_trailing_slashes ();
+char *stpcpy ();
 
 static void usage ();
 static int do_link ();
@@ -174,7 +195,30 @@ main (argc, argv)
     errors = do_link (argv[optind], ".");
   else if (optind == argc - 2)
     {
-      errors = do_link (argv[optind], argv[optind + 1]);
+      struct stat source_stats;
+      char *source;
+      char *dest;
+      char *new_dest;
+
+      source = argv[optind];
+      dest = argv[optind + 1];
+
+      /* When the destination is specified with a trailing slash and the
+        source exists but is not a directory, convert the user's command
+        `ln source dest/' to `ln source dest/basename(source)'.  */
+
+      if (dest[strlen (dest) - 1] == '/'
+         && lstat (source, &source_stats) == 0
+         && !S_ISDIR (source_stats.st_mode))
+       {
+         PATH_BASENAME_CONCAT (new_dest, dest, source);
+       }
+      else
+       {
+         new_dest = dest;
+       }
+
+      errors = do_link (source, new_dest);
     }
   else
     {
@@ -215,17 +259,7 @@ do_link (source, dest)
     {
       /* Target is a directory; build the full filename. */
       char *new_dest;
-      char *source_base;
-      char *tmp_source;
-
-      tmp_source = (char *) alloca (strlen (source) + 1);
-      strcpy (tmp_source, source);
-      strip_trailing_slashes (tmp_source);
-
-      source_base = basename (tmp_source);
-      new_dest = (char *)
-       alloca (strlen (source_base) + 1 + strlen (dest) + 1);
-      sprintf (new_dest, "%s/%s", dest, source_base);
+      PATH_BASENAME_CONCAT (new_dest, dest, source);
       dest = new_dest;
     }
 
index 1b562be8cda5219d2a77913d2765e9ef8aa07ebf..b20b2117733b804ab48af568f41302eecae798f7 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -1218,6 +1218,8 @@ sort_files ()
        case time_atime:
          func = sort_reverse ? rev_cmp_atime : compare_atime;
          break;
+       default:
+         abort ();
        }
       break;
     case sort_name:
@@ -1229,6 +1231,8 @@ sort_files ()
     case sort_size:
       func = sort_reverse ? rev_cmp_size : compare_size;
       break;
+    default:
+      abort ();
     }
 
   qsort (files, files_index, sizeof (struct file), func);
@@ -1435,11 +1439,12 @@ print_long_format (f)
     }
 
   if (print_inode)
-    printf ("%6u ", f->stat.st_ino);
+    printf ("%6lu ", (unsigned long) f->stat.st_ino);
 
   if (print_block_size)
     printf ("%*u ", block_size_size,
-           convert_blocks (ST_NBLOCKS (f->stat), kilobyte_blocks));
+           (unsigned) convert_blocks (ST_NBLOCKS (f->stat),
+                                           kilobyte_blocks));
 
   /* The space between the mode and the number of links is the POSIX
      "optional alternate access method flag". */
@@ -1560,11 +1565,12 @@ print_file_name_and_frills (f)
      struct file *f;
 {
   if (print_inode)
-    printf ("%6u ", f->stat.st_ino);
+    printf ("%6lu ", (unsigned long) f->stat.st_ino);
 
   if (print_block_size)
     printf ("%*u ", block_size_size,
-           convert_blocks (ST_NBLOCKS (f->stat), kilobyte_blocks));
+           (unsigned) convert_blocks (ST_NBLOCKS (f->stat),
+                                           kilobyte_blocks));
 
   print_name_with_quoting (f->name);