aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2014-01-30 13:00:58 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2014-01-30 13:00:58 +0200
commit9e2d258c81af9f8cedba2e4b8874fbaea59b43c4 (patch)
treed470f085625c6434d4661b185c981f8065c14d3c
parenta3987da2a573bd2438f15df6faa680922025be18 (diff)
downloadcpio-9e2d258c81af9f8cedba2e4b8874fbaea59b43c4.tar.gz
cpio-9e2d258c81af9f8cedba2e4b8874fbaea59b43c4.tar.bz2
Use exit codes consistenly.
-rw-r--r--src/copyin.c10
-rw-r--r--src/copyout.c6
-rw-r--r--src/main.c150
-rw-r--r--src/util.c24
4 files changed, 102 insertions, 88 deletions
diff --git a/src/copyin.c b/src/copyin.c
index 3282816..78ffdd7 100644
--- a/src/copyin.c
+++ b/src/copyin.c
@@ -958,3 +958,3 @@ read_in_header (struct cpio_file_stat *file_hdr, int in_des)
if (peeked_bytes < 6)
- error (1, 0, _("premature end of archive"));
+ error (PAXEXIT_FAILURE, 0, _("premature end of archive"));
@@ -1291,3 +1291,3 @@ process_copy_in ()
{
- error (2, errno, TTY_NAME);
+ error (PAXEXIT_FAILURE, errno, TTY_NAME);
}
@@ -1300,3 +1300,3 @@ process_copy_in ()
{
- error (2, errno, TTY_NAME);
+ error (PAXEXIT_FAILURE, errno, TTY_NAME);
}
@@ -1305,3 +1305,3 @@ process_copy_in ()
{
- error (2, errno, TTY_NAME);
+ error (PAXEXIT_FAILURE, errno, TTY_NAME);
}
@@ -1325,3 +1325,3 @@ process_copy_in ()
if (fstat (in_file_des, &file_stat))
- error (1, errno, _("standard input is closed"));
+ error (PAXEXIT_FAILURE, errno, _("standard input is closed"));
input_is_special =
diff --git a/src/copyout.c b/src/copyout.c
index a5a8931..63785ff 100644
--- a/src/copyout.c
+++ b/src/copyout.c
@@ -50,3 +50,3 @@ read_for_checksum (int in_file_des, int file_size, char *file_name)
if (bytes_read < 0)
- error (1, errno, _("cannot read checksum for %s"), file_name);
+ error (PAXEXIT_FAILURE, errno, _("cannot read checksum for %s"), file_name);
if (bytes_read == 0)
@@ -59,3 +59,3 @@ read_for_checksum (int in_file_des, int file_size, char *file_name)
if (lseek (in_file_des, 0L, SEEK_SET))
- error (1, errno, _("cannot read checksum for %s"), file_name);
+ error (PAXEXIT_FAILURE, errno, _("cannot read checksum for %s"), file_name);
@@ -608,3 +608,3 @@ process_copy_out ()
if (fstat (out_file_des, &file_stat))
- error (1, errno, _("standard output is closed"));
+ error (PAXEXIT_FAILURE, errno, _("standard output is closed"));
output_is_special =
diff --git a/src/main.c b/src/main.c
index d352e25..25320b5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -38,2 +38,3 @@
#include <progname.h>
+#include <closeout.h>
@@ -82,2 +83,4 @@ Examples:\n\
+static void usage (int status);
+
/* Print usage error message and exit with error. */
@@ -86,3 +89,3 @@ Examples:\n\
if (cond) \
- ERROR((PAXEXIT_FAILURE, 0, _("%s is meaningless with %s"), opt, mode_opt));
+ USAGE_ERROR ((0, 0, _("%s is meaningless with %s"), opt, mode_opt));
@@ -311,3 +314,3 @@ parse_opt (int key, char *arg, struct argp_state *state)
if (io_block_size < 1)
- error (2, 0, _("invalid block size"));
+ USAGE_ERROR ((0, 0, _("invalid block size")));
io_block_size *= 512;
@@ -317,3 +320,3 @@ parse_opt (int key, char *arg, struct argp_state *state)
if (archive_format != arf_unknown)
- error (0, EXIT_FAILURE, _("Archive format multiply defined"));
+ USAGE_ERROR ((0, 0, _("Archive format multiply defined")));
#ifdef SVR4_COMPAT
@@ -328,3 +331,3 @@ parse_opt (int key, char *arg, struct argp_state *state)
if (io_block_size < 1)
- error (2, 0, _("invalid block size"));
+ USAGE_ERROR ((0, 0, _("invalid block size")));
break;
@@ -353,3 +356,3 @@ parse_opt (int key, char *arg, struct argp_state *state)
if (archive_format != arf_unknown)
- error (PAXEXIT_FAILURE, 0, _("Archive format multiply defined"));
+ USAGE_ERROR ((0, 0, _("Archive format multiply defined")));
if (!strcasecmp (arg, "crc"))
@@ -371,5 +374,5 @@ parse_opt (int key, char *arg, struct argp_state *state)
else
- error (2, 0, _("\
+ USAGE_ERROR ((0, 0, _("\
invalid archive format `%s'; valid formats are:\n\
-crc newc odc bin ustar tar (all-caps also recognized)"), arg);
+crc newc odc bin ustar tar (all-caps also recognized)"), arg));
break;
@@ -378,3 +381,3 @@ crc newc odc bin ustar tar (all-caps also recognized)"), arg);
if (copy_function != 0)
- error (PAXEXIT_FAILURE, 0, _("Mode already defined"));
+ USAGE_ERROR ((0, 0, _("Mode already defined")));
copy_function = process_copy_in;
@@ -416,4 +419,4 @@ crc newc odc bin ustar tar (all-caps also recognized)"), arg);
if (set_owner_flag || set_group_flag)
- error (PAXEXIT_FAILURE, 0,
- _("--no-preserve-owner cannot be used with --owner"));
+ USAGE_ERROR ((0, 0,
+ _("--no-preserve-owner cannot be used with --owner")));
no_chown_flag = true;
@@ -423,3 +426,3 @@ crc newc odc bin ustar tar (all-caps also recognized)"), arg);
if (copy_function != 0)
- error (PAXEXIT_FAILURE, 0, _("Mode already defined"));
+ USAGE_ERROR ((0, 0, _("Mode already defined")));
copy_function = process_copy_out;
@@ -437,3 +440,3 @@ crc newc odc bin ustar tar (all-caps also recognized)"), arg);
if (copy_function != 0)
- error (PAXEXIT_FAILURE, 0, _("Mode already defined"));
+ USAGE_ERROR ((0, 0, _("Mode already defined")));
copy_function = process_copy_pass;
@@ -459,4 +462,4 @@ crc newc odc bin ustar tar (all-caps also recognized)"), arg);
if (no_chown_flag)
- error (PAXEXIT_FAILURE, 0,
- _("--owner cannot be used with --no-preserve-owner"));
+ USAGE_ERROR ((0, 0,
+ _("--owner cannot be used with --no-preserve-owner")));
else
@@ -467,3 +470,3 @@ crc newc odc bin ustar tar (all-caps also recognized)"), arg);
if (e)
- error (PAXEXIT_FAILURE, 0, "%s: %s", arg, e);
+ USAGE_ERROR ((0, 0, "%s: %s", arg, e));
if (u)
@@ -507,3 +510,3 @@ crc newc odc bin ustar tar (all-caps also recognized)"), arg);
if (warn_control (arg))
- argp_error (state, _("Invalid value for --warning option: %s"), arg);
+ USAGE_ERROR ((0, 0, _("Invalid value for --warning option: %s"), arg));
break;
@@ -544,2 +547,10 @@ static struct argp argp = {
+static void
+usage (int status)
+{
+ argp_help (&argp, stderr, ARGP_HELP_SEE, (char*) program_name);
+ close_stdout ();
+ exit (status);
+}
+
/* Process the arguments. Set all options and set up the copy pass
@@ -566,5 +577,5 @@ process_args (int argc, char *argv[])
else
- error (PAXEXIT_FAILURE, 0,
+ USAGE_ERROR ((0, 0,
_("You must specify one of -oipt options.\nTry `%s --help' or `%s --usage' for more information.\n"),
- program_name, program_name);
+ program_name, program_name));
}
@@ -578,15 +589,16 @@ process_args (int argc, char *argv[])
archive_des = 0;
- CHECK_USAGE(link_flag, "--link", "--extract");
- CHECK_USAGE(reset_time_flag, "--reset", "--extract");
- CHECK_USAGE(xstat != lstat, "--dereference", "--extract");
- CHECK_USAGE(append_flag, "--append", "--extract");
- CHECK_USAGE(output_archive_name, "-O", "--extract");
+ CHECK_USAGE (link_flag, "--link", "--extract");
+ CHECK_USAGE (reset_time_flag, "--reset", "--extract");
+ CHECK_USAGE (xstat != lstat, "--dereference", "--extract");
+ CHECK_USAGE (append_flag, "--append", "--extract");
+ CHECK_USAGE (output_archive_name, "-O", "--extract");
if (to_stdout_option)
{
- CHECK_USAGE(create_dir_flag, "--make-directories", "--to-stdout");
- CHECK_USAGE(rename_flag, "--rename", "--to-stdout");
- CHECK_USAGE(no_chown_flag, "--no-preserve-owner", "--to-stdout");
- CHECK_USAGE(set_owner_flag||set_group_flag, "--owner", "--to-stdout");
- CHECK_USAGE(retain_time_flag, "--preserve-modification-time",
- "--to-stdout");
+ CHECK_USAGE (create_dir_flag, "--make-directories", "--to-stdout");
+ CHECK_USAGE (rename_flag, "--rename", "--to-stdout");
+ CHECK_USAGE (no_chown_flag, "--no-preserve-owner", "--to-stdout");
+ CHECK_USAGE (set_owner_flag||set_group_flag,
+ "--owner", "--to-stdout");
+ CHECK_USAGE (retain_time_flag, "--preserve-modification-time",
+ "--to-stdout");
}
@@ -594,4 +606,4 @@ process_args (int argc, char *argv[])
if (archive_name && input_archive_name)
- error (PAXEXIT_FAILURE, 0,
- _("Both -I and -F are used in copy-in mode"));
+ USAGE_ERROR ((0, 0,
+ _("Both -I and -F are used in copy-in mode")));
@@ -607,28 +619,29 @@ process_args (int argc, char *argv[])
if (index != argc)
- error (PAXEXIT_FAILURE, 0, _("Too many arguments"));
+ USAGE_ERROR ((0, 0, _("Too many arguments")));
archive_des = 1;
- CHECK_USAGE(create_dir_flag, "--make-directories", "--create");
- CHECK_USAGE(rename_flag, "--rename", "--create");
- CHECK_USAGE(table_flag, "--list", "--create");
- CHECK_USAGE(unconditional_flag, "--unconditional", "--create");
- CHECK_USAGE(link_flag, "--link", "--create");
- CHECK_USAGE(sparse_flag, "--sparse", "--create");
- CHECK_USAGE(retain_time_flag, "--preserve-modification-time",
- "--create");
- CHECK_USAGE(no_chown_flag, "--no-preserve-owner", "--create");
- CHECK_USAGE(swap_bytes_flag, "--swap-bytes (--swap)", "--create");
- CHECK_USAGE(swap_halfwords_flag, "--swap-halfwords (--swap)",
- "--create");
- CHECK_USAGE(to_stdout_option, "--to-stdout", "--create");
+ CHECK_USAGE (create_dir_flag, "--make-directories", "--create");
+ CHECK_USAGE (rename_flag, "--rename", "--create");
+ CHECK_USAGE (table_flag, "--list", "--create");
+ CHECK_USAGE (unconditional_flag, "--unconditional", "--create");
+ CHECK_USAGE (link_flag, "--link", "--create");
+ CHECK_USAGE (sparse_flag, "--sparse", "--create");
+ CHECK_USAGE (retain_time_flag, "--preserve-modification-time",
+ "--create");
+ CHECK_USAGE (no_chown_flag, "--no-preserve-owner", "--create");
+ CHECK_USAGE (swap_bytes_flag, "--swap-bytes (--swap)", "--create");
+ CHECK_USAGE (swap_halfwords_flag, "--swap-halfwords (--swap)",
+ "--create");
+ CHECK_USAGE (to_stdout_option, "--to-stdout", "--create");
if (append_flag && !(archive_name || output_archive_name))
- error (PAXEXIT_FAILURE, 0,
- _("--append is used but no archive file name is given (use -F or -O options)"));
+ USAGE_ERROR ((0, 0,
+ _("--append is used but no archive file name "
+ "is given (use -F or -O options)")));
- CHECK_USAGE(rename_batch_file, "--rename-batch-file", "--create");
- CHECK_USAGE(input_archive_name, "-I", "--create");
+ CHECK_USAGE (rename_batch_file, "--rename-batch-file", "--create");
+ CHECK_USAGE (input_archive_name, "-I", "--create");
if (archive_name && output_archive_name)
- error (PAXEXIT_FAILURE, 0,
- _("Both -O and -F are used in copy-out mode"));
+ USAGE_ERROR ((0, 0,
+ _("Both -O and -F are used in copy-out mode")));
@@ -643,22 +656,23 @@ process_args (int argc, char *argv[])
if (index < argc - 1)
- error (PAXEXIT_FAILURE, 0, _("Too many arguments"));
+ USAGE_ERROR ((0, 0, _("Too many arguments")));
else if (index > argc - 1)
- error (PAXEXIT_FAILURE, 0, _("Not enough arguments"));
+ USAGE_ERROR ((0, 0, _("Not enough arguments")));
if (archive_format != arf_unknown)
- error (PAXEXIT_FAILURE, 0,
- _("Archive format is not specified in copy-pass mode (use --format option)"));
-
- CHECK_USAGE(swap_bytes_flag, "--swap-bytes (--swap)", "--pass-through");
- CHECK_USAGE(swap_halfwords_flag, "--swap-halfwords (--swap)",
- "--pass-through");
- CHECK_USAGE(table_flag, "--list", "--pass-through");
- CHECK_USAGE(rename_flag, "--rename", "--pass-through");
- CHECK_USAGE(append_flag, "--append", "--pass-through");
- CHECK_USAGE(rename_batch_file, "--rename-batch-file", "--pass-through");
- CHECK_USAGE(no_abs_paths_flag, "--no-absolute-pathnames",
- "--pass-through");
- CHECK_USAGE(no_abs_paths_flag, "--absolute-pathnames",
- "--pass-through");
- CHECK_USAGE(to_stdout_option, "--to-stdout", "--pass-through");
+ USAGE_ERROR ((0, 0,
+ _("Archive format is not specified in copy-pass mode "
+ "(use --format option)")));
+
+ CHECK_USAGE (swap_bytes_flag, "--swap-bytes (--swap)", "--pass-through");
+ CHECK_USAGE (swap_halfwords_flag, "--swap-halfwords (--swap)",
+ "--pass-through");
+ CHECK_USAGE (table_flag, "--list", "--pass-through");
+ CHECK_USAGE (rename_flag, "--rename", "--pass-through");
+ CHECK_USAGE (append_flag, "--append", "--pass-through");
+ CHECK_USAGE (rename_batch_file, "--rename-batch-file", "--pass-through");
+ CHECK_USAGE (no_abs_paths_flag, "--no-absolute-pathnames",
+ "--pass-through");
+ CHECK_USAGE (no_abs_paths_flag, "--absolute-pathnames",
+ "--pass-through");
+ CHECK_USAGE (to_stdout_option, "--to-stdout", "--pass-through");
diff --git a/src/util.c b/src/util.c
index 2fcab61..f717104 100644
--- a/src/util.c
+++ b/src/util.c
@@ -92,6 +92,6 @@ tape_empty_output_buffer (int out_des)
if (rest_bytes_written != rest_output_size)
- error (1, errno, _("write error"));
+ error (PAXEXIT_FAILURE, errno, _("write error"));
}
else
- error (1, errno, _("write error"));
+ error (PAXEXIT_FAILURE, errno, _("write error"));
}
@@ -145,5 +145,5 @@ disk_empty_output_buffer (int out_des, bool flush)
if (bytes_written == -1)
- error (1, errno, _("write error"));
+ error (PAXEXIT_FAILURE, errno, _("write error"));
else
- error (1, 0, _("write error: partial write"));
+ error (PAXEXIT_FAILURE, 0, _("write error: partial write"));
}
@@ -209,3 +209,3 @@ tape_fill_input_buffer (int in_des, int num_bytes)
if (input_size < 0)
- error (1, errno, _("read error"));
+ error (PAXEXIT_FAILURE, errno, _("read error"));
if (input_size == 0)
@@ -378,3 +378,3 @@ tape_buffered_peek (char *peek_buf, int in_des, int num_bytes)
if (tmp_input_size < 0)
- error (1, errno, _("read error"));
+ error (PAXEXIT_FAILURE, errno, _("read error"));
input_bytes += tmp_input_size;
@@ -622,3 +622,3 @@ create_all_directories (char *name)
if (dir == NULL)
- error (2, 0, _("virtual memory exhausted"));
+ error (PAXEXIT_FAILURE, 0, _("virtual memory exhausted"));
@@ -665,3 +665,3 @@ prepare_append (int out_file_des)
if (lseek (out_file_des, start_of_block, SEEK_SET) < 0)
- error (1, errno, _("cannot seek on output"));
+ error (PAXEXIT_FAILURE, errno, _("cannot seek on output"));
if (useful_bytes_in_block > 0)
@@ -671,3 +671,3 @@ prepare_append (int out_file_des)
if (lseek (out_file_des, start_of_block, SEEK_SET) < 0)
- error (1, errno, _("cannot seek on output"));
+ error (PAXEXIT_FAILURE, errno, _("cannot seek on output"));
/* fix juo -- is this copy_tape_buf_out? or copy_disk? */
@@ -825,6 +825,6 @@ get_next_reel (int tape_des)
if (tty_in == NULL)
- error (2, errno, TTY_NAME);
+ error (PAXEXIT_FAILURE, errno, TTY_NAME);
tty_out = fopen (TTY_NAME, "w");
if (tty_out == NULL)
- error (2, errno, TTY_NAME);
+ error (PAXEXIT_FAILURE, errno, TTY_NAME);
@@ -893,3 +893,3 @@ get_next_reel (int tape_des)
if (tape_des != old_tape_des)
- error (1, 0, _("internal error: tape descriptor changed from %d to %d"),
+ error (PAXEXIT_FAILURE, 0, _("internal error: tape descriptor changed from %d to %d"),
old_tape_des, tape_des);

Return to:

Send suggestions and report system problems to the System administrator.