summaryrefslogtreecommitdiff
path: root/src/cp.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-02-17 08:39:20 +0000
committerJim Meyering <jim@meyering.net>2003-02-17 08:39:20 +0000
commit2bb32c98a5560063fc6171fe49d2e0d8268b8f43 (patch)
treed7bc36baa81201f43ec6392f61c6e5c3effd77da /src/cp.c
parent49cda05bd33f60ccc16fa67dfebb079f52a25456 (diff)
downloadcoreutils-2bb32c98a5560063fc6171fe49d2e0d8268b8f43.tar.xz
(run): New function, preparing for use of
RUN_WITH_BIG_STACK_*
Diffstat (limited to 'src/cp.c')
-rw-r--r--src/cp.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/cp.c b/src/cp.c
index adcb7b97f..9ae9f2acc 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -119,9 +119,6 @@ static int const reply_vals[] =
I_ALWAYS_YES, I_ALWAYS_NO, I_ASK_USER
};
-/* The error code to return to the system. */
-static int exit_status = 0;
-
static struct option const long_opts[] =
{
{"archive", no_argument, NULL, 'a'},
@@ -826,6 +823,25 @@ decode_preserve_arg (char const *arg, struct cp_options *x, int on_off)
free (arg_writable);
}
+static void run (size_t, char **, char const *, struct cp_options *)
+ ATTRIBUTE_NORETURN;
+/* Encapsulate the `copy-and-exit' functionality. */
+static void
+run (size_t n_files, char **files, char const *target_directory,
+ struct cp_options *x)
+{
+ int fail;
+
+ /* Allocate space for remembering copied and created files. */
+ hash_init ();
+
+ fail = do_copy (n_files, files, target_directory, x);
+
+ forget_all ();
+
+ exit (fail ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
int
main (int argc, char **argv)
{
@@ -1050,13 +1066,5 @@ main (int argc, char **argv)
if (x.unlink_dest_after_failed_open && (x.hard_link || x.symbolic_link))
x.unlink_dest_before_opening = 1;
- /* Allocate space for remembering copied and created files. */
-
- hash_init ();
-
- exit_status |= do_copy (argc - optind, argv + optind, target_directory, &x);
-
- forget_all ();
-
- exit (exit_status);
+ run (argc - optind, argv + optind, target_directory, &x);
}