diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-01-30 13:00:58 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-01-30 13:00:58 +0200 |
commit | 9e2d258c81af9f8cedba2e4b8874fbaea59b43c4 (patch) | |
tree | d470f085625c6434d4661b185c981f8065c14d3c | |
parent | a3987da2a573bd2438f15df6faa680922025be18 (diff) | |
download | cpio-9e2d258c81af9f8cedba2e4b8874fbaea59b43c4.tar.gz cpio-9e2d258c81af9f8cedba2e4b8874fbaea59b43c4.tar.bz2 |
Use exit codes consistenly.
-rw-r--r-- | src/copyin.c | 10 | ||||
-rw-r--r-- | src/copyout.c | 6 | ||||
-rw-r--r-- | src/main.c | 150 | ||||
-rw-r--r-- | src/util.c | 24 |
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 | |||
@@ -956,7 +956,7 @@ read_in_header (struct cpio_file_stat *file_hdr, int in_des) | |||
956 | { | 956 | { |
957 | peeked_bytes = tape_buffered_peek (tmpbuf, in_des, 512); | 957 | peeked_bytes = tape_buffered_peek (tmpbuf, in_des, 512); |
958 | if (peeked_bytes < 6) | 958 | if (peeked_bytes < 6) |
959 | error (1, 0, _("premature end of archive")); | 959 | error (PAXEXIT_FAILURE, 0, _("premature end of archive")); |
960 | 960 | ||
961 | if (!strncmp (tmpbuf, "070701", 6)) | 961 | if (!strncmp (tmpbuf, "070701", 6)) |
962 | archive_format = arf_newascii; | 962 | archive_format = arf_newascii; |
@@ -1289,7 +1289,7 @@ process_copy_in () | |||
1289 | rename_in = fopen (rename_batch_file, "r"); | 1289 | rename_in = fopen (rename_batch_file, "r"); |
1290 | if (rename_in == NULL) | 1290 | if (rename_in == NULL) |
1291 | { | 1291 | { |
1292 | error (2, errno, TTY_NAME); | 1292 | error (PAXEXIT_FAILURE, errno, TTY_NAME); |
1293 | } | 1293 | } |
1294 | } | 1294 | } |
1295 | else if (rename_flag) | 1295 | else if (rename_flag) |
@@ -1298,12 +1298,12 @@ process_copy_in () | |||
1298 | tty_in = fopen (TTY_NAME, "r"); | 1298 | tty_in = fopen (TTY_NAME, "r"); |
1299 | if (tty_in == NULL) | 1299 | if (tty_in == NULL) |
1300 | { | 1300 | { |
1301 | error (2, errno, TTY_NAME); | 1301 | error (PAXEXIT_FAILURE, errno, TTY_NAME); |
1302 | } | 1302 | } |
1303 | tty_out = fopen (TTY_NAME, "w"); | 1303 | tty_out = fopen (TTY_NAME, "w"); |
1304 | if (tty_out == NULL) | 1304 | if (tty_out == NULL) |
1305 | { | 1305 | { |
1306 | error (2, errno, TTY_NAME); | 1306 | error (PAXEXIT_FAILURE, errno, TTY_NAME); |
1307 | } | 1307 | } |
1308 | } | 1308 | } |
1309 | 1309 | ||
@@ -1323,7 +1323,7 @@ process_copy_in () | |||
1323 | else | 1323 | else |
1324 | { | 1324 | { |
1325 | if (fstat (in_file_des, &file_stat)) | 1325 | if (fstat (in_file_des, &file_stat)) |
1326 | error (1, errno, _("standard input is closed")); | 1326 | error (PAXEXIT_FAILURE, errno, _("standard input is closed")); |
1327 | input_is_special = | 1327 | input_is_special = |
1328 | #ifdef S_ISBLK | 1328 | #ifdef S_ISBLK |
1329 | S_ISBLK (file_stat.st_mode) || | 1329 | S_ISBLK (file_stat.st_mode) || |
diff --git a/src/copyout.c b/src/copyout.c index a5a8931..63785ff 100644 --- a/src/copyout.c +++ b/src/copyout.c | |||
@@ -48,7 +48,7 @@ read_for_checksum (int in_file_des, int file_size, char *file_name) | |||
48 | { | 48 | { |
49 | bytes_read = read (in_file_des, buf, BUFSIZ); | 49 | bytes_read = read (in_file_des, buf, BUFSIZ); |
50 | if (bytes_read < 0) | 50 | if (bytes_read < 0) |
51 | error (1, errno, _("cannot read checksum for %s"), file_name); | 51 | error (PAXEXIT_FAILURE, errno, _("cannot read checksum for %s"), file_name); |
52 | if (bytes_read == 0) | 52 | if (bytes_read == 0) |
53 | break; | 53 | break; |
54 | if (bytes_left < bytes_read) | 54 | if (bytes_left < bytes_read) |
@@ -57,7 +57,7 @@ read_for_checksum (int in_file_des, int file_size, char *file_name) | |||
57 | crc += buf[i] & 0xff; | 57 | crc += buf[i] & 0xff; |
58 | } | 58 | } |
59 | if (lseek (in_file_des, 0L, SEEK_SET)) | 59 | if (lseek (in_file_des, 0L, SEEK_SET)) |
60 | error (1, errno, _("cannot read checksum for %s"), file_name); | 60 | error (PAXEXIT_FAILURE, errno, _("cannot read checksum for %s"), file_name); |
61 | 61 | ||
62 | return crc; | 62 | return crc; |
63 | } | 63 | } |
@@ -606,7 +606,7 @@ process_copy_out () | |||
606 | else | 606 | else |
607 | { | 607 | { |
608 | if (fstat (out_file_des, &file_stat)) | 608 | if (fstat (out_file_des, &file_stat)) |
609 | error (1, errno, _("standard output is closed")); | 609 | error (PAXEXIT_FAILURE, errno, _("standard output is closed")); |
610 | output_is_special = | 610 | output_is_special = |
611 | #ifdef S_ISBLK | 611 | #ifdef S_ISBLK |
612 | S_ISBLK (file_stat.st_mode) || | 612 | S_ISBLK (file_stat.st_mode) || |
@@ -36,6 +36,7 @@ | |||
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #include <progname.h> | 38 | #include <progname.h> |
39 | #include <closeout.h> | ||
39 | 40 | ||
40 | #include "filetypes.h" | 41 | #include "filetypes.h" |
41 | #include "cpiohdr.h" | 42 | #include "cpiohdr.h" |
@@ -80,11 +81,13 @@ Examples:\n\ | |||
80 | # Copy files named in name-list to destination-directory\n\ | 81 | # Copy files named in name-list to destination-directory\n\ |
81 | cpio -p destination-directory < name-list\n"); | 82 | cpio -p destination-directory < name-list\n"); |
82 | 83 | ||
84 | static void usage (int status); | ||
85 | |||
83 | /* Print usage error message and exit with error. */ | 86 | /* Print usage error message and exit with error. */ |
84 | 87 | ||
85 | #define CHECK_USAGE(cond, opt, mode_opt) \ | 88 | #define CHECK_USAGE(cond, opt, mode_opt) \ |
86 | if (cond) \ | 89 | if (cond) \ |
87 | ERROR((PAXEXIT_FAILURE, 0, _("%s is meaningless with %s"), opt, mode_opt)); | 90 | USAGE_ERROR ((0, 0, _("%s is meaningless with %s"), opt, mode_opt)); |
88 | 91 | ||
89 | static struct argp_option options[] = { | 92 | static struct argp_option options[] = { |
90 | /* ********** */ | 93 | /* ********** */ |
@@ -309,13 +312,13 @@ parse_opt (int key, char *arg, struct argp_state *state) | |||
309 | case BLOCK_SIZE_OPTION: /* --block-size */ | 312 | case BLOCK_SIZE_OPTION: /* --block-size */ |
310 | io_block_size = atoi (arg); | 313 | io_block_size = atoi (arg); |
311 | if (io_block_size < 1) | 314 | if (io_block_size < 1) |
312 | error (2, 0, _("invalid block size")); | 315 | USAGE_ERROR ((0, 0, _("invalid block size"))); |
313 | io_block_size *= 512; | 316 | io_block_size *= 512; |
314 | break; | 317 | break; |
315 | 318 | ||
316 | case 'c': /* Use the old portable ASCII format. */ | 319 | case 'c': /* Use the old portable ASCII format. */ |
317 | if (archive_format != arf_unknown) | 320 | if (archive_format != arf_unknown) |
318 | error (0, EXIT_FAILURE, _("Archive format multiply defined")); | 321 | USAGE_ERROR ((0, 0, _("Archive format multiply defined"))); |
319 | #ifdef SVR4_COMPAT | 322 | #ifdef SVR4_COMPAT |
320 | archive_format = arf_newascii; /* -H newc. */ | 323 | archive_format = arf_newascii; /* -H newc. */ |
321 | #else | 324 | #else |
@@ -326,7 +329,7 @@ parse_opt (int key, char *arg, struct argp_state *state) | |||
326 | case 'C': /* Block size. */ | 329 | case 'C': /* Block size. */ |
327 | io_block_size = atoi (arg); | 330 | io_block_size = atoi (arg); |
328 | if (io_block_size < 1) | 331 | if (io_block_size < 1) |
329 | error (2, 0, _("invalid block size")); | 332 | USAGE_ERROR ((0, 0, _("invalid block size"))); |
330 | break; | 333 | break; |
331 | 334 | ||
332 | case 'd': /* Create directories where needed. */ | 335 | case 'd': /* Create directories where needed. */ |
@@ -351,7 +354,7 @@ parse_opt (int key, char *arg, struct argp_state *state) | |||
351 | 354 | ||
352 | case 'H': /* Header format name. */ | 355 | case 'H': /* Header format name. */ |
353 | if (archive_format != arf_unknown) | 356 | if (archive_format != arf_unknown) |
354 | error (PAXEXIT_FAILURE, 0, _("Archive format multiply defined")); | 357 | USAGE_ERROR ((0, 0, _("Archive format multiply defined"))); |
355 | if (!strcasecmp (arg, "crc")) | 358 | if (!strcasecmp (arg, "crc")) |
356 | archive_format = arf_crcascii; | 359 | archive_format = arf_crcascii; |
357 | else if (!strcasecmp (arg, "newc")) | 360 | else if (!strcasecmp (arg, "newc")) |
@@ -369,14 +372,14 @@ parse_opt (int key, char *arg, struct argp_state *state) | |||
369 | else if (!strcasecmp (arg, "hpbin")) | 372 | else if (!strcasecmp (arg, "hpbin")) |
370 | archive_format = arf_hpbinary; | 373 | archive_format = arf_hpbinary; |
371 | else | 374 | else |
372 | error (2, 0, _("\ | 375 | USAGE_ERROR ((0, 0, _("\ |
373 | invalid archive format `%s'; valid formats are:\n\ | 376 | invalid archive format `%s'; valid formats are:\n\ |
374 | crc newc odc bin ustar tar (all-caps also recognized)"), arg); | 377 | crc newc odc bin ustar tar (all-caps also recognized)"), arg)); |
375 | break; | 378 | break; |
376 | 379 | ||
377 | case 'i': /* Copy-in mode. */ | 380 | case 'i': /* Copy-in mode. */ |
378 | if (copy_function != 0) | 381 | if (copy_function != 0) |
379 | error (PAXEXIT_FAILURE, 0, _("Mode already defined")); | 382 | USAGE_ERROR ((0, 0, _("Mode already defined"))); |
380 | copy_function = process_copy_in; | 383 | copy_function = process_copy_in; |
381 | break; | 384 | break; |
382 | 385 | ||
@@ -414,14 +417,14 @@ crc newc odc bin ustar tar (all-caps also recognized)"), arg); | |||
414 | 417 | ||
415 | case NO_PRESERVE_OWNER_OPTION: /* --no-preserve-owner */ | 418 | case NO_PRESERVE_OWNER_OPTION: /* --no-preserve-owner */ |
416 | if (set_owner_flag || set_group_flag) | 419 | if (set_owner_flag || set_group_flag) |
417 | error (PAXEXIT_FAILURE, 0, | 420 | USAGE_ERROR ((0, 0, |
418 | _("--no-preserve-owner cannot be used with --owner")); | 421 | _("--no-preserve-owner cannot be used with --owner"))); |
419 | no_chown_flag = true; | 422 | no_chown_flag = true; |
420 | break; | 423 | break; |
421 | 424 | ||
422 | case 'o': /* Copy-out mode. */ | 425 | case 'o': /* Copy-out mode. */ |
423 | if (copy_function != 0) | 426 | if (copy_function != 0) |
424 | error (PAXEXIT_FAILURE, 0, _("Mode already defined")); | 427 | USAGE_ERROR ((0, 0, _("Mode already defined"))); |
425 | copy_function = process_copy_out; | 428 | copy_function = process_copy_out; |
426 | break; | 429 | break; |
427 | 430 | ||
@@ -435,7 +438,7 @@ crc newc odc bin ustar tar (all-caps also recognized)"), arg); | |||
435 | 438 | ||
436 | case 'p': /* Copy-pass mode. */ | 439 | case 'p': /* Copy-pass mode. */ |
437 | if (copy_function != 0) | 440 | if (copy_function != 0) |
438 | error (PAXEXIT_FAILURE, 0, _("Mode already defined")); | 441 | USAGE_ERROR ((0, 0, _("Mode already defined"))); |
439 | copy_function = process_copy_pass; | 442 | copy_function = process_copy_pass; |
440 | break; | 443 | break; |
441 | 444 | ||
@@ -457,15 +460,15 @@ crc newc odc bin ustar tar (all-caps also recognized)"), arg); | |||
457 | 460 | ||
458 | case 'R': /* Set the owner. */ | 461 | case 'R': /* Set the owner. */ |
459 | if (no_chown_flag) | 462 | if (no_chown_flag) |
460 | error (PAXEXIT_FAILURE, 0, | 463 | USAGE_ERROR ((0, 0, |
461 | _("--owner cannot be used with --no-preserve-owner")); | 464 | _("--owner cannot be used with --no-preserve-owner"))); |
462 | else | 465 | else |
463 | { | 466 | { |
464 | char *e, *u, *g; | 467 | char *e, *u, *g; |
465 | 468 | ||
466 | e = parse_user_spec (arg, |