]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cp: simplify cp/install/ln/mv pacification
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 31 Jan 2022 16:42:07 +0000 (08:42 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 31 Jan 2022 20:07:39 +0000 (12:07 -0800)
* src/copy.c (dest_info_free, src_info_free) [lint]:
Remove.  All uses removed.
(copy_internal): Pacify only Clang and Coverity; GCC doesn’t need it.
* src/cp-hash.c (forget_all) [lint]: Remove.  All uses removed.
* src/cp.c, src/install.c, src/ln.c, src/mv.c (main):
Use main_exit, not return.

src/copy.c
src/cp-hash.c
src/cp-hash.h
src/cp.c
src/install.c
src/ln.c
src/mv.c

index 4a7d9b5d9cbc7e4b96f3682d45bb13f2856ead75..33a26c36a392ea085de460854dba57eb405aa330 100644 (file)
@@ -1759,16 +1759,6 @@ dest_info_init (struct cp_options *x)
     xalloc_die ();
 }
 
-#ifdef lint
-extern void
-dest_info_free (struct cp_options *x)
-{
-  if (x->dest_info)
-    hash_free (x->dest_info);
-  x->dest_info = NULL;
-}
-#endif
-
 /* Initialize the hash table implementing a set of F_triple entries
    corresponding to source files listed on the command line.  */
 extern void
@@ -1793,16 +1783,6 @@ src_info_init (struct cp_options *x)
     xalloc_die ();
 }
 
-#ifdef lint
-extern void
-src_info_free (struct cp_options *x)
-{
-  if (x->src_info)
-    hash_free (x->src_info);
-  x->src_info = NULL;
-}
-#endif
-
 /* When effecting a move (e.g., for mv(1)), and given the name DST_NAME
    aka DST_DIRFD+DST_RELNAME
    of the destination and a corresponding stat buffer, DST_SB, return
@@ -2014,13 +1994,13 @@ copy_internal (char const *src_name, char const *dst_name,
           return false;
         }
     }
-#ifdef lint
   else
     {
+#if defined lint && (defined __clang__ || defined __COVERITY__)
       assert (x->move_mode);
       memset (&src_sb, 0, sizeof src_sb);
-    }
 #endif
+    }
 
   /* Detect the case in which the same source file appears more than
      once on the command line and no backup option has been selected.
index 3a3a07490356520978eb105d44144ac75fa81bb5..e566a4c4adefccd20064c6b3fac5596ee910a44a 100644 (file)
@@ -153,14 +153,3 @@ hash_init (void)
   if (src_to_dest == NULL)
     xalloc_die ();
 }
-
-/* Reset the hash structure in the global variable 'htab' to
-   contain no entries.  */
-
-#ifdef lint
-extern void
-forget_all (void)
-{
-  hash_free (src_to_dest);
-}
-#endif
index 72870fa6d823d912bd6b2d58d7a5b3ae035335b2..989fcc53b26f0d0d2ee6815469b2b2dc3d149ecf 100644 (file)
@@ -1,5 +1,4 @@
 void hash_init (void);
-void forget_all (void);
 void forget_created (ino_t ino, dev_t dev);
 char *remember_copied (char const *node, ino_t ino, dev_t dev)
   _GL_ATTRIBUTE_NONNULL ();
index d680eb01d20ba87d413e9bbd0c372c761f077f1d..5084037f15cd020f9f457644628d8b6d6ba4fae4 100644 (file)
--- a/src/cp.c
+++ b/src/cp.c
@@ -735,11 +735,6 @@ do_copy (int n_files, char **file, char const *target_directory,
 
           free (dst_name);
         }
-
-#ifdef lint
-      dest_info_free (x);
-      src_info_free (x);
-#endif
     }
   else /* !target_directory */
     {
@@ -1218,9 +1213,5 @@ main (int argc, char **argv)
   ok = do_copy (argc - optind, argv + optind,
                 target_directory, no_target_directory, &x);
 
-#ifdef lint
-  forget_all ();
-#endif
-
-  return ok ? EXIT_SUCCESS : EXIT_FAILURE;
+  main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
index a27a5343b4ed2fd2d1af7ea464bbe254b933d539..38e26a887865c5a45f74c1be7974a7fe005c3af7 100644 (file)
@@ -1023,11 +1023,8 @@ main (int argc, char **argv)
                                        i == 0 && mkdir_and_install,
                                        &target_dirfd))
               exit_status = EXIT_FAILURE;
-#ifdef lint
-          dest_info_free (&x);
-#endif
         }
     }
 
-  return exit_status;
+  main_exit (exit_status);
 }
index 5a05c078ce2b87c80d19b2a913a4ce7b87b682a8..bb4695853317b194844776bdd7c44f70af0fb1a8 100644 (file)
--- a/src/ln.c
+++ b/src/ln.c
@@ -674,15 +674,9 @@ main (int argc, char **argv)
           ok &= do_link (file[i], destdir_fd, dest_base, dest, -1);
           free (dest);
         }
-
-#ifdef lint
-      if (dest_set)
-        hash_free (dest_set);
-      dest_set = NULL;
-#endif
     }
   else
     ok = do_link (file[0], AT_FDCWD, file[1], file[1], link_errno);
 
-  return ok ? EXIT_SUCCESS : EXIT_FAILURE;
+  main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
index fcf32cd43615f012af42ac21bf11d7ea8dbce9e1..21018a0d338ef6ebc665ad0d5a1b9b4e2df3c933 100644 (file)
--- a/src/mv.c
+++ b/src/mv.c
@@ -487,10 +487,6 @@ main (int argc, char **argv)
           ok &= do_move (source, dest, target_dirfd, dest_relname, &x);
           free (dest);
         }
-
-#ifdef lint
-      dest_info_free (&x);
-#endif
     }
   else
     {
@@ -498,5 +494,5 @@ main (int argc, char **argv)
       ok = do_move (file[0], file[1], AT_FDCWD, file[1], &x);
     }
 
-  return ok ? EXIT_SUCCESS : EXIT_FAILURE;
+  main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }