From 5080aa5faa80c516888c97a5aa94a2c2a80e993f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 31 Jan 2022 08:42:07 -0800 Subject: [PATCH 13/43] cp: simplify cp/install/ln/mv pacification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 | 24 ++---------------------- src/cp-hash.c | 11 ----------- src/cp-hash.h | 1 - src/cp.c | 11 +---------- src/install.c | 5 +---- src/ln.c | 8 +------- src/mv.c | 6 +----- 7 files changed, 6 insertions(+), 60 deletions(-) diff --git a/src/copy.c b/src/copy.c index 4a7d9b5d9..33a26c36a 100644 --- a/src/copy.c +++ b/src/copy.c @@ -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. diff --git a/src/cp-hash.c b/src/cp-hash.c index 3a3a07490..e566a4c4a 100644 --- a/src/cp-hash.c +++ b/src/cp-hash.c @@ -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 diff --git a/src/cp-hash.h b/src/cp-hash.h index 72870fa6d..989fcc53b 100644 --- a/src/cp-hash.h +++ b/src/cp-hash.h @@ -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 (); diff --git a/src/cp.c b/src/cp.c index d680eb01d..5084037f1 100644 --- 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); } diff --git a/src/install.c b/src/install.c index a27a5343b..38e26a887 100644 --- a/src/install.c +++ b/src/install.c @@ -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); } diff --git a/src/ln.c b/src/ln.c index 5a05c078c..bb4695853 100644 --- 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); } diff --git a/src/mv.c b/src/mv.c index fcf32cd43..21018a0d3 100644 --- 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); } -- 2.32.0