]> Dogcows Code - chaz/tar/blob - src/tar.c
Do not include <print-copyr.h>.
[chaz/tar] / src / tar.c
1 /* A tar (tape archiver) program.
2
3 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000,
4 2001, 2003 Free Software Foundation, Inc.
5
6 Written by John Gilmore, starting 1985-08-25.
7
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any later
11 version.
12
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16 Public License for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
22 #include "system.h"
23
24 #include <fnmatch.h>
25 #include <getopt.h>
26
27 #include <signal.h>
28 #if ! defined SIGCHLD && defined SIGCLD
29 # define SIGCHLD SIGCLD
30 #endif
31
32 /* The following causes "common.h" to produce definitions of all the global
33 variables, rather than just "extern" declarations of them. GNU tar does
34 depend on the system loader to preset all GLOBAL variables to neutral (or
35 zero) values; explicit initialization is usually not done. */
36 #define GLOBAL
37 #include "common.h"
38
39 #include <getdate.h>
40 #include <localedir.h>
41 #include <prepargs.h>
42 #include <quotearg.h>
43 #include <xstrtol.h>
44
45 /* Local declarations. */
46
47 #ifndef DEFAULT_ARCHIVE
48 # define DEFAULT_ARCHIVE "tar.out"
49 #endif
50
51 #ifndef DEFAULT_BLOCKING
52 # define DEFAULT_BLOCKING 20
53 #endif
54
55 static void usage (int) __attribute__ ((noreturn));
56 \f
57 /* Miscellaneous. */
58
59 /* Name of option using stdin. */
60 static const char *stdin_used_by;
61
62 /* Doesn't return if stdin already requested. */
63 void
64 request_stdin (const char *option)
65 {
66 if (stdin_used_by)
67 USAGE_ERROR ((0, 0, _("Options `-%s' and `-%s' both want standard input"),
68 stdin_used_by, option));
69
70 stdin_used_by = option;
71 }
72
73 /* Returns true if and only if the user typed 'y' or 'Y'. */
74 int
75 confirm (const char *message_action, const char *message_name)
76 {
77 static FILE *confirm_file;
78 static int confirm_file_EOF;
79
80 if (!confirm_file)
81 {
82 if (archive == 0 || stdin_used_by)
83 {
84 confirm_file = fopen (TTY_NAME, "r");
85 if (! confirm_file)
86 open_fatal (TTY_NAME);
87 }
88 else
89 {
90 request_stdin ("-w");
91 confirm_file = stdin;
92 }
93 }
94
95 fprintf (stdlis, "%s %s?", message_action, quote (message_name));
96 fflush (stdlis);
97
98 {
99 int reply = confirm_file_EOF ? EOF : getc (confirm_file);
100 int character;
101
102 for (character = reply;
103 character != '\n';
104 character = getc (confirm_file))
105 if (character == EOF)
106 {
107 confirm_file_EOF = 1;
108 fputc ('\n', stdlis);
109 fflush (stdlis);
110 break;
111 }
112 return reply == 'y' || reply == 'Y';
113 }
114 }
115 \f
116 /* Options. */
117
118 /* For long options that unconditionally set a single flag, we have getopt
119 do it. For the others, we share the code for the equivalent short
120 named option, the name of which is stored in the otherwise-unused `val'
121 field of the `struct option'; for long options that have no equivalent
122 short option, we use non-characters as pseudo short options,
123 starting at CHAR_MAX + 1 and going upwards. */
124
125 enum
126 {
127 ANCHORED_OPTION = CHAR_MAX + 1,
128 ATIME_PRESERVE_OPTION,
129 BACKUP_OPTION,
130 CHECKPOINT_OPTION,
131 DELETE_OPTION,
132 EXCLUDE_OPTION,
133 FORCE_LOCAL_OPTION,
134 GROUP_OPTION,
135 IGNORE_CASE_OPTION,
136 IGNORE_FAILED_READ_OPTION,
137 INDEX_FILE_OPTION,
138 MODE_OPTION,
139 NEWER_MTIME_OPTION,
140 NO_ANCHORED_OPTION,
141 NO_IGNORE_CASE_OPTION,
142 NO_OVERWRITE_DIR_OPTION,
143 NO_WILDCARDS_OPTION,
144 NO_WILDCARDS_MATCH_SLASH_OPTION,
145 NULL_OPTION,
146 NUMERIC_OWNER_OPTION,
147 OVERWRITE_OPTION,
148 OWNER_OPTION,
149 POSIX_OPTION,
150 PRESERVE_OPTION,
151 RECORD_SIZE_OPTION,
152 RECURSIVE_UNLINK_OPTION,
153 REMOVE_FILES_OPTION,
154 RSH_COMMAND_OPTION,
155 SHOW_OMITTED_DIRS_OPTION,
156 SUFFIX_OPTION,
157 TOTALS_OPTION,
158 USE_COMPRESS_PROGRAM_OPTION,
159 VOLNO_FILE_OPTION,
160 WILDCARDS_OPTION,
161 WILDCARDS_MATCH_SLASH_OPTION,
162
163 /* Some cleanup is being made in GNU tar long options. Using old names is
164 allowed for a while, but will also send a warning to stderr. Take old
165 names out in 1.14, or in summer 1997, whichever happens last. */
166
167 OBSOLETE_ABSOLUTE_NAMES,
168 OBSOLETE_BLOCK_COMPRESS,
169 OBSOLETE_BLOCKING_FACTOR,
170 OBSOLETE_BLOCK_NUMBER,
171 OBSOLETE_READ_FULL_RECORDS,
172 OBSOLETE_TOUCH,
173 OBSOLETE_VERSION_CONTROL
174 };
175
176 /* If nonzero, display usage information and exit. */
177 static int show_help;
178
179 /* If nonzero, print the version on standard output and exit. */
180 static int show_version;
181
182 static struct option long_options[] =
183 {
184 {"absolute-names", no_argument, 0, 'P'},
185 {"absolute-paths", no_argument, 0, OBSOLETE_ABSOLUTE_NAMES},
186 {"after-date", required_argument, 0, 'N'},
187 {"anchored", no_argument, 0, ANCHORED_OPTION},
188 {"append", no_argument, 0, 'r'},
189 {"atime-preserve", no_argument, 0, ATIME_PRESERVE_OPTION},
190 {"backup", optional_argument, 0, BACKUP_OPTION},
191 {"block-compress", no_argument, 0, OBSOLETE_BLOCK_COMPRESS},
192 {"block-number", no_argument, 0, 'R'},
193 {"block-size", required_argument, 0, OBSOLETE_BLOCKING_FACTOR},
194 {"blocking-factor", required_argument, 0, 'b'},
195 {"bzip2", no_argument, 0, 'j'},
196 {"catenate", no_argument, 0, 'A'},
197 {"checkpoint", no_argument, 0, CHECKPOINT_OPTION},
198 {"compare", no_argument, 0, 'd'},
199 {"compress", no_argument, 0, 'Z'},
200 {"concatenate", no_argument, 0, 'A'},
201 {"confirmation", no_argument, 0, 'w'},
202 /* FIXME: --selective as a synonym for --confirmation? */
203 {"create", no_argument, 0, 'c'},
204 {"delete", no_argument, 0, DELETE_OPTION},
205 {"dereference", no_argument, 0, 'h'},
206 {"diff", no_argument, 0, 'd'},
207 {"directory", required_argument, 0, 'C'},
208 {"exclude", required_argument, 0, EXCLUDE_OPTION},
209 {"exclude-from", required_argument, 0, 'X'},
210 {"extract", no_argument, 0, 'x'},
211 {"file", required_argument, 0, 'f'},
212 {"files-from", required_argument, 0, 'T'},
213 {"force-local", no_argument, 0, FORCE_LOCAL_OPTION},
214 {"get", no_argument, 0, 'x'},
215 {"group", required_argument, 0, GROUP_OPTION},
216 {"gunzip", no_argument, 0, 'z'},
217 {"gzip", no_argument, 0, 'z'},
218 {"help", no_argument, &show_help, 1},
219 {"ignore-case", no_argument, 0, IGNORE_CASE_OPTION},
220 {"ignore-failed-read", no_argument, 0, IGNORE_FAILED_READ_OPTION},
221 {"ignore-zeros", no_argument, 0, 'i'},
222 /* FIXME: --ignore-end as a new name for --ignore-zeros? */
223 {"incremental", no_argument, 0, 'G'},
224 {"index-file", required_argument, 0, INDEX_FILE_OPTION},
225 {"info-script", required_argument, 0, 'F'},
226 {"interactive", no_argument, 0, 'w'},
227 {"keep-old-files", no_argument, 0, 'k'},
228 {"label", required_argument, 0, 'V'},
229 {"list", no_argument, 0, 't'},
230 {"listed-incremental", required_argument, 0, 'g'},
231 {"mode", required_argument, 0, MODE_OPTION},
232 {"modification-time", no_argument, 0, OBSOLETE_TOUCH},
233 {"multi-volume", no_argument, 0, 'M'},
234 {"new-volume-script", required_argument, 0, 'F'},
235 {"newer", required_argument, 0, 'N'},
236 {"newer-mtime", required_argument, 0, NEWER_MTIME_OPTION},
237 {"null", no_argument, 0, NULL_OPTION},
238 {"no-anchored", no_argument, 0, NO_ANCHORED_OPTION},
239 {"no-ignore-case", no_argument, 0, NO_IGNORE_CASE_OPTION},
240 {"no-overwrite-dir", no_argument, 0, NO_OVERWRITE_DIR_OPTION},
241 {"no-wildcards", no_argument, 0, NO_WILDCARDS_OPTION},
242 {"no-wildcards-match-slash", no_argument, 0, NO_WILDCARDS_MATCH_SLASH_OPTION},
243 {"no-recursion", no_argument, &recursion_option, 0},
244 {"no-same-owner", no_argument, &same_owner_option, -1},
245 {"no-same-permissions", no_argument, &same_permissions_option, -1},
246 {"numeric-owner", no_argument, 0, NUMERIC_OWNER_OPTION},
247 {"old-archive", no_argument, 0, 'o'},
248 {"one-file-system", no_argument, 0, 'l'},
249 {"overwrite", no_argument, 0, OVERWRITE_OPTION},
250 {"owner", required_argument, 0, OWNER_OPTION},
251 {"portability", no_argument, 0, 'o'},
252 {"posix", no_argument, 0, POSIX_OPTION},
253 {"preserve", no_argument, 0, PRESERVE_OPTION},
254 {"preserve-order", no_argument, 0, 's'},
255 {"preserve-permissions", no_argument, 0, 'p'},
256 {"recursion", no_argument, &recursion_option, FNM_LEADING_DIR},
257 {"recursive-unlink", no_argument, 0, RECURSIVE_UNLINK_OPTION},
258 {"read-full-blocks", no_argument, 0, OBSOLETE_READ_FULL_RECORDS},
259 {"read-full-records", no_argument, 0, 'B'},
260 /* FIXME: --partial-blocks might be a synonym for --read-full-records? */
261 {"record-number", no_argument, 0, OBSOLETE_BLOCK_NUMBER},
262 {"record-size", required_argument, 0, RECORD_SIZE_OPTION},
263 {"remove-files", no_argument, 0, REMOVE_FILES_OPTION},
264 {"rsh-command", required_argument, 0, RSH_COMMAND_OPTION},
265 {"same-order", no_argument, 0, 's'},
266 {"same-owner", no_argument, &same_owner_option, 1},
267 {"same-permissions", no_argument, 0, 'p'},
268 {"show-omitted-dirs", no_argument, 0, SHOW_OMITTED_DIRS_OPTION},
269 {"sparse", no_argument, 0, 'S'},
270 {"starting-file", required_argument, 0, 'K'},
271 {"suffix", required_argument, 0, SUFFIX_OPTION},
272 {"tape-length", required_argument, 0, 'L'},
273 {"to-stdout", no_argument, 0, 'O'},
274 {"totals", no_argument, 0, TOTALS_OPTION},
275 {"touch", no_argument, 0, 'm'},
276 {"uncompress", no_argument, 0, 'Z'},
277 {"ungzip", no_argument, 0, 'z'},
278 {"unlink-first", no_argument, 0, 'U'},
279 {"update", no_argument, 0, 'u'},
280 {"use-compress-program", required_argument, 0, USE_COMPRESS_PROGRAM_OPTION},
281 {"verbose", no_argument, 0, 'v'},
282 {"verify", no_argument, 0, 'W'},
283 {"version", no_argument, &show_version, 1},
284 {"version-control", required_argument, 0, OBSOLETE_VERSION_CONTROL},
285 {"volno-file", required_argument, 0, VOLNO_FILE_OPTION},
286 {"wildcards", no_argument, 0, WILDCARDS_OPTION},
287 {"wildcards-match-slash", no_argument, 0, WILDCARDS_MATCH_SLASH_OPTION},
288
289 {0, 0, 0, 0}
290 };
291
292 /* Print a usage message and exit with STATUS. */
293 static void
294 usage (int status)
295 {
296 if (status != TAREXIT_SUCCESS)
297 fprintf (stderr, _("Try `%s --help' for more information.\n"),
298 program_name);
299 else
300 {
301 fputs (_("\
302 GNU `tar' saves many files together into a single tape or disk archive, and\n\
303 can restore individual files from the archive.\n"),
304 stdout);
305 printf (_("\nUsage: %s [OPTION]... [FILE]...\n\
306 \n\
307 Examples:\n\
308 %s -cf archive.tar foo bar # Create archive.tar from files foo and bar.\n\
309 %s -tvf archive.tar # List all files in archive.tar verbosely.\n\
310 %s -xf archive.tar # Extract all files from archive.tar.\n"),
311 program_name, program_name, program_name, program_name);
312 fputs (_("\
313 \n\
314 If a long option shows an argument as mandatory, then it is mandatory\n\
315 for the equivalent short option also. Similarly for optional arguments.\n"),
316 stdout);
317 fputs(_("\
318 \n\
319 Main operation mode:\n\
320 -t, --list list the contents of an archive\n\
321 -x, --extract, --get extract files from an archive\n\
322 -c, --create create a new archive\n\
323 -d, --diff, --compare find differences between archive and file system\n\
324 -r, --append append files to the end of an archive\n\
325 -u, --update only append files newer than copy in archive\n\
326 -A, --catenate append tar files to an archive\n\
327 --concatenate same as -A\n\
328 --delete delete from the archive (not on mag tapes!)\n"),
329 stdout);
330 fputs (_("\
331 \n\
332 Operation modifiers:\n\
333 -W, --verify attempt to verify the archive after writing it\n\
334 --remove-files remove files after adding them to the archive\n\
335 -k, --keep-old-files don't replace existing files when extracting\n\
336 --overwrite overwrite existing files when extracting\n\
337 --no-overwrite-dir preserve metadata of existing directories\n\
338 -U, --unlink-first remove each file prior to extracting over it\n\
339 --recursive-unlink empty hierarchies prior to extracting directory\n\
340 -S, --sparse handle sparse files efficiently\n\
341 -O, --to-stdout extract files to standard output\n\
342 -G, --incremental handle old GNU-format incremental backup\n\
343 -g, --listed-incremental=FILE\n\
344 handle new GNU-format incremental backup\n\
345 --ignore-failed-read do not exit with nonzero on unreadable files\n"),
346 stdout);
347 fputs (_("\
348 \n\
349 Handling of file attributes:\n\
350 --owner=NAME force NAME as owner for added files\n\
351 --group=NAME force NAME as group for added files\n\
352 --mode=CHANGES force (symbolic) mode CHANGES for added files\n\
353 --atime-preserve don't change access times on dumped files\n\
354 -m, --modification-time don't extract file modified time\n\
355 --same-owner try extracting files with the same ownership\n\
356 --no-same-owner extract files as yourself\n\
357 --numeric-owner always use numbers for user/group names\n\
358 -p, --same-permissions extract permissions information\n\
359 --no-same-permissions do not extract permissions information\n\
360 --preserve-permissions same as -p\n\
361 -s, --same-order sort names to extract to match archive\n\
362 --preserve-order same as -s\n\
363 --preserve same as both -p and -s\n"),
364 stdout);
365 fputs (_("\
366 \n\
367 Device selection and switching:\n\
368 -f, --file=ARCHIVE use archive file or device ARCHIVE\n\
369 --force-local archive file is local even if has a colon\n\
370 --rsh-command=COMMAND use remote COMMAND instead of rsh\n\
371 -[0-7][lmh] specify drive and density\n\
372 -M, --multi-volume create/list/extract multi-volume archive\n\
373 -L, --tape-length=NUM change tape after writing NUM x 1024 bytes\n\
374 -F, --info-script=FILE run script at end of each tape (implies -M)\n\
375 --new-volume-script=FILE same as -F FILE\n\
376 --volno-file=FILE use/update the volume number in FILE\n"),
377 stdout);
378 fputs (_("\
379 \n\
380 Device blocking:\n\
381 -b, --blocking-factor=BLOCKS BLOCKS x 512 bytes per record\n\
382 --record-size=SIZE SIZE bytes per record, multiple of 512\n\
383 -i, --ignore-zeros ignore zeroed blocks in archive (means EOF)\n\
384 -B, --read-full-records reblock as we read (for 4.2BSD pipes)\n"),
385 stdout);
386 fputs (_("\
387 \n\
388 Archive format selection:\n\
389 -V, --label=NAME create archive with volume name NAME\n\
390 PATTERN at list/extract time, a globbing PATTERN\n\
391 -o, --old-archive, --portability write a V7 format archive\n\
392 --posix write a POSIX format archive\n\
393 -j, --bzip2 filter the archive through bzip2\n\
394 -z, --gzip, --ungzip filter the archive through gzip\n\
395 -Z, --compress, --uncompress filter the archive through compress\n\
396 --use-compress-program=PROG filter through PROG (must accept -d)\n"),
397 stdout);
398 fputs (_("\
399 \n\
400 Local file selection:\n\
401 -C, --directory=DIR change to directory DIR\n\
402 -T, --files-from=NAME get names to extract or create from file NAME\n\
403 --null -T reads null-terminated names, disable -C\n\
404 --exclude=PATTERN exclude files, given as a PATTERN\n\
405 -X, --exclude-from=FILE exclude patterns listed in FILE\n\
406 --anchored exclude patterns match file name start (default)\n\
407 --no-anchored exclude patterns match after any /\n\
408 --ignore-case exclusion ignores case\n\
409 --no-ignore-case exclusion is case sensitive (default)\n\
410 --wildcards exclude patterns use wildcards (default)\n\
411 --no-wildcards exclude patterns are plain strings\n\
412 --wildcards-match-slash exclude pattern wildcards match '/' (default)\n\
413 --no-wildcards-match-slash exclude pattern wildcards do not match '/'\n\
414 -P, --absolute-names don't strip leading `/'s from file names\n\
415 -h, --dereference dump instead the files symlinks point to\n\
416 --no-recursion avoid descending automatically in directories\n\
417 -l, --one-file-system stay in local file system when creating archive\n\
418 -K, --starting-file=NAME begin at file NAME in the archive\n"),
419 stdout);
420 #if !MSDOS
421 fputs (_("\
422 -N, --newer=DATE only store files newer than DATE\n\
423 --newer-mtime=DATE compare date and time when data changed only\n\
424 --after-date=DATE same as -N\n"),
425 stdout);
426 #endif
427 fputs (_("\
428 --backup[=CONTROL] backup before removal, choose version control\n\
429 --suffix=SUFFIX backup before removal, override usual suffix\n"),
430 stdout);
431 fputs (_("\
432 \n\
433 Informative output:\n\
434 --help print this help, then exit\n\
435 --version print tar program version number, then exit\n\
436 -v, --verbose verbosely list files processed\n\
437 --checkpoint print directory names while reading the archive\n\
438 --totals print total bytes written while creating archive\n\
439 --index-file=FILE send verbose output to FILE\n\
440 -R, --block-number show block number within archive with each message\n\
441 -w, --interactive ask for confirmation for every action\n\
442 --confirmation same as -w\n"),
443 stdout);
444 fputs (_("\
445 \n\
446 The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.\n\
447 The version control may be set with --backup or VERSION_CONTROL, values are:\n\
448 \n\
449 t, numbered make numbered backups\n\
450 nil, existing numbered if numbered backups exist, simple otherwise\n\
451 never, simple always make simple backups\n"),
452 stdout);
453 printf (_("\
454 \n\
455 GNU tar cannot read nor produce `--posix' archives. If POSIXLY_CORRECT\n\
456 is set in the environment, GNU extensions are disallowed with `--posix'.\n\
457 Support for POSIX is only partially implemented, don't count on it yet.\n\
458 ARCHIVE may be FILE, HOST:FILE or USER@HOST:FILE; DATE may be a textual date\n\
459 or a file name starting with `/' or `.', in which case the file's date is used.\n\
460 *This* `tar' defaults to `-f%s -b%d'.\n"),
461 DEFAULT_ARCHIVE, DEFAULT_BLOCKING);
462 printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
463 }
464 exit (status);
465 }
466
467 /* Parse the options for tar. */
468
469 /* Available option letters are DEHIJQY and aenqy. Some are reserved:
470
471 e exit immediately with a nonzero exit status if unexpected errors occur
472 E use extended headers (draft POSIX headers, that is)
473 I same as T (for compatibility with Solaris tar)
474 n the archive is quickly seekable, so don't worry about random seeks
475 q stop after extracting the first occurrence of the named file
476 y per-file gzip compression
477 Y per-block gzip compression */
478
479 #define OPTION_STRING \
480 "-01234567ABC:F:GIK:L:MN:OPRST:UV:WX:Zb:cdf:g:hijklmoprstuvwxyz"
481
482 static void
483 set_subcommand_option (enum subcommand subcommand)
484 {
485 if (subcommand_option != UNKNOWN_SUBCOMMAND
486 && subcommand_option != subcommand)
487 USAGE_ERROR ((0, 0,
488 _("You may not specify more than one `-Acdtrux' option")));
489
490 subcommand_option = subcommand;
491 }
492
493 static void
494 set_use_compress_program_option (const char *string)
495 {
496 if (use_compress_program_option && strcmp (use_compress_program_option, string) != 0)
497 USAGE_ERROR ((0, 0, _("Conflicting compression options")));
498
499 use_compress_program_option = string;
500 }
501
502 static void
503 decode_options (int argc, char **argv)
504 {
505 int optchar; /* option letter */
506 int input_files; /* number of input files */
507 char const *textual_date_option = 0;
508 char const *backup_suffix_string;
509 char const *version_control_string = 0;
510 int exclude_options = EXCLUDE_WILDCARDS;
511
512 /* Set some default option values. */
513
514 subcommand_option = UNKNOWN_SUBCOMMAND;
515 archive_format = DEFAULT_FORMAT;
516 blocking_factor = DEFAULT_BLOCKING;
517 record_size = DEFAULT_BLOCKING * BLOCKSIZE;
518 excluded = new_exclude ();
519 newer_mtime_option = TYPE_MINIMUM (time_t);
520 recursion_option = FNM_LEADING_DIR;
521
522 owner_option = -1;
523 group_option = -1;
524
525 backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
526
527 /* Convert old-style tar call by exploding option element and rearranging
528 options accordingly. */
529
530 if (argc > 1 && argv[1][0] != '-')
531 {
532 int new_argc; /* argc value for rearranged arguments */
533 char **new_argv; /* argv value for rearranged arguments */
534 char *const *in; /* cursor into original argv */
535 char **out; /* cursor into rearranged argv */
536 const char *letter; /* cursor into old option letters */
537 char buffer[3]; /* constructed option buffer */
538 const char *cursor; /* cursor in OPTION_STRING */
539
540 /* Initialize a constructed option. */
541
542 buffer[0] = '-';
543 buffer[2] = '\0';
544
545 /* Allocate a new argument array, and copy program name in it. */
546
547 new_argc = argc - 1 + strlen (argv[1]);
548 new_argv = xmalloc ((new_argc + 1) * sizeof (char *));
549 in = argv;
550 out = new_argv;
551 *out++ = *in++;
552
553 /* Copy each old letter option as a separate option, and have the
554 corresponding argument moved next to it. */
555
556 for (letter = *in++; *letter; letter++)
557 {
558 buffer[1] = *letter;
559 *out++ = xstrdup (buffer);
560 cursor = strchr (OPTION_STRING, *letter);
561 if (cursor && cursor[1] == ':')
562 {
563 if (in < argv + argc)
564 *out++ = *in++;
565 else
566 USAGE_ERROR ((0, 0, _("Old option `%c' requires an argument."),
567 *letter));
568 }
569 }
570
571 /* Copy all remaining options. */
572
573 while (in < argv + argc)
574 *out++ = *in++;
575 *out = 0;
576
577 /* Replace the old option list by the new one. */
578
579 argc = new_argc;
580 argv = new_argv;
581 }
582
583 /* Parse all options and non-options as they appear. */
584
585 input_files = 0;
586
587 prepend_default_options (getenv ("TAR_OPTIONS"), &argc, &argv);
588
589 while (optchar = getopt_long (argc, argv, OPTION_STRING, long_options, 0),
590 optchar != -1)
591 switch (optchar)
592 {
593 case '?':
594 usage (TAREXIT_FAILURE);
595
596 case 0:
597 break;
598
599 case 1:
600 /* File name or non-parsed option, because of RETURN_IN_ORDER
601 ordering triggered by the leading dash in OPTION_STRING. */
602
603 name_add (optarg);
604 input_files++;
605 break;
606
607 case 'A':
608 set_subcommand_option (CAT_SUBCOMMAND);
609 break;
610
611 case OBSOLETE_BLOCK_COMPRESS:
612 WARN ((0, 0, _("Obsolete option, now implied by --blocking-factor")));
613 break;
614
615 case OBSOLETE_BLOCKING_FACTOR:
616 WARN ((0, 0, _("Obsolete option name replaced by --blocking-factor")));
617 /* Fall through. */
618
619 case 'b':
620 {
621 uintmax_t u;
622 if (! (xstrtoumax (optarg, 0, 10, &u, "") == LONGINT_OK
623 && u == (blocking_factor = u)
624 && 0 < blocking_factor
625 && u == (record_size = u * BLOCKSIZE) / BLOCKSIZE))
626 USAGE_ERROR ((0, 0, "%s: %s", quotearg_colon (optarg),
627 _("Invalid blocking factor")));
628 }
629 break;
630
631 case OBSOLETE_READ_FULL_RECORDS:
632 WARN ((0, 0,
633 _("Obsolete option name replaced by --read-full-records")));
634 /* Fall through. */
635
636 case 'B':
637 /* Try to reblock input records. For reading 4.2BSD pipes. */
638
639 /* It would surely make sense to exchange -B and -R, but it seems
640 that -B has been used for a long while in Sun tar ans most
641 BSD-derived systems. This is a consequence of the block/record
642 terminology confusion. */
643
644 read_full_records_option = 1;
645 break;
646
647 case 'c':
648 set_subcommand_option (CREATE_SUBCOMMAND);
649 break;
650
651 case 'C':
652 name_add ("-C");
653 name_add (optarg);
654 break;
655
656 case 'd':
657 set_subcommand_option (DIFF_SUBCOMMAND);
658 break;
659
660 case 'f':
661 if (archive_names == allocated_archive_names)
662 {
663 allocated_archive_names *= 2;
664 archive_name_array =
665 xrealloc (archive_name_array,
666 sizeof (const char *) * allocated_archive_names);
667 }
668 archive_name_array[archive_names++] = optarg;
669 break;
670
671 case 'F':
672 /* Since -F is only useful with -M, make it implied. Run this
673 script at the end of each tape. */
674
675 info_script_option = optarg;
676 multi_volume_option = 1;
677 break;
678
679 case 'g':
680 listed_incremental_option = optarg;
681 after_date_option = 1;
682 /* Fall through. */
683
684 case 'G':
685 /* We are making an incremental dump (FIXME: are we?); save
686 directories at the beginning of the archive, and include in each
687 directory its contents. */
688
689 incremental_option = 1;
690 break;
691
692 case 'h':
693 /* Follow symbolic links. */
694
695 dereference_option = 1;
696 break;
697
698 case 'i':
699 /* Ignore zero blocks (eofs). This can't be the default,
700 because Unix tar writes two blocks of zeros, then pads out
701 the record with garbage. */
702
703 ignore_zeros_option = 1;
704 break;
705
706 case 'I':
707 USAGE_ERROR ((0, 0,
708 _("Warning: the -I option is not supported;"
709 " perhaps you meant -j or -T?")));
710 break;
711
712 case 'j':
713 set_use_compress_program_option ("bzip2");
714 break;
715
716 case 'k':
717 /* Don't replace existing files. */
718 old_files_option = KEEP_OLD_FILES;
719 break;
720
721 case 'K':
722 starting_file_option = 1;
723 addname (optarg, 0);
724 break;
725
726 case 'l':
727 /* When dumping directories, don't dump files/subdirectories
728 that are on other filesystems. */
729
730 one_file_system_option = 1;
731 break;
732
733 case 'L':
734 {
735 uintmax_t u;
736 if (xstrtoumax (optarg, 0, 10, &u, "") != LONGINT_OK)
737 USAGE_ERROR ((0, 0, "%s: %s", quotearg_colon (optarg),
738 _("Invalid tape length")));
739 tape_length_option = 1024 * (tarlong) u;
740 multi_volume_option = 1;
741 }
742 break;
743
744 case OBSOLETE_TOUCH:
745 WARN ((0, 0, _("Obsolete option name replaced by --touch")));
746 /* Fall through. */
747
748 case 'm':
749 touch_option = 1;
750 break;
751
752 case 'M':
753 /* Make multivolume archive: when we can't write any more into
754 the archive, re-open it, and continue writing. */
755
756 multi_volume_option = 1;
757 break;
758
759 #if !MSDOS
760 case 'N':
761 after_date_option = 1;
762 /* Fall through. */
763
764 case NEWER_MTIME_OPTION:
765 if (newer_mtime_option != TYPE_MINIMUM (time_t))
766 USAGE_ERROR ((0, 0, _("More than one threshold date")));
767
768 if (FILESYSTEM_PREFIX_LEN (optarg) != 0
769 || ISSLASH (*optarg)
770 || *optarg == '.')
771 {
772 struct stat st;
773 if (deref_stat (dereference_option, optarg, &st) != 0)
774 {
775 stat_error (optarg);
776 USAGE_ERROR ((0, 0, _("Date file not found")));
777 }
778 newer_mtime_option = st.st_mtime;
779 }
780 else
781 {
782 newer_mtime_option = get_date (optarg, 0);
783 if (newer_mtime_option == (time_t) -1)
784 WARN ((0, 0, _("Substituting %s for unknown date format %s"),
785 tartime (newer_mtime_option), quote (optarg)));
786 else
787 textual_date_option = optarg;
788 }
789
790 break;
791 #endif /* not MSDOS */
792
793 case 'o':
794 if (archive_format == DEFAULT_FORMAT)
795 archive_format = V7_FORMAT;
796 else if (archive_format != V7_FORMAT)
797 USAGE_ERROR ((0, 0, _("Conflicting archive format options")));
798 break;
799
800 case 'O':
801 to_stdout_option = 1;
802 break;
803
804 case 'p':
805 same_permissions_option = 1;
806 break;
807
808 case OBSOLETE_ABSOLUTE_NAMES:
809 WARN ((0, 0, _("Obsolete option name replaced by --absolute-names")));
810 /* Fall through. */
811
812 case 'P':
813 absolute_names_option = 1;
814 break;
815
816 case 'r':
817 set_subcommand_option (APPEND_SUBCOMMAND);
818 break;
819
820 case OBSOLETE_BLOCK_NUMBER:
821 WARN ((0, 0, _("Obsolete option name replaced by --block-number")));
822 /* Fall through. */
823
824 case 'R':
825 /* Print block numbers for debugging bad tar archives. */
826
827 /* It would surely make sense to exchange -B and -R, but it seems
828 that -B has been used for a long while in Sun tar ans most
829 BSD-derived systems. This is a consequence of the block/record
830 terminology confusion. */
831
832 block_number_option = 1;
833 break;
834
835 case 's':
836 /* Names to extr are sorted. */
837
838 same_order_option = 1;
839 break;
840
841 case 'S':
842 sparse_option = 1;
843 break;
844
845 case 't':
846 set_subcommand_option (LIST_SUBCOMMAND);
847 verbose_option++;
848 break;
849
850 case 'T':
851 files_from_option = optarg;
852 break;
853
854 case 'u':
855 set_subcommand_option (UPDATE_SUBCOMMAND);
856 break;
857
858 case 'U':
859 old_files_option = UNLINK_FIRST_OLD_FILES;
860 break;
861
862 case 'v':
863 verbose_option++;
864 break;
865
866 case 'V':
867 volume_label_option = optarg;
868 break;
869
870 case 'w':
871 interactive_option = 1;
872 break;
873
874 case 'W':
875 verify_option = 1;
876 break;
877
878 case 'x':
879 set_subcommand_option (EXTRACT_SUBCOMMAND);
880 break;
881
882 case 'X':
883 if (add_exclude_file (add_exclude, excluded, optarg,
884 exclude_options | recursion_option, '\n')
885 != 0)
886 {
887 int e = errno;
888 FATAL_ERROR ((0, e, "%s", quotearg_colon (optarg)));
889 }
890 break;
891
892 case 'y':
893 USAGE_ERROR ((0, 0,
894 _("Warning: the -y option is not supported;"
895 " perhaps you meant -j?")));
896 break;
897
898 case 'z':
899 set_use_compress_program_option ("gzip");
900 break;
901
902 case 'Z':
903 set_use_compress_program_option ("compress");
904 break;
905
906 case OBSOLETE_VERSION_CONTROL:
907 WARN ((0, 0, _("Obsolete option name replaced by --backup")));
908 /* Fall through. */
909
910 case ANCHORED_OPTION:
911 exclude_options |= EXCLUDE_ANCHORED;
912 break;
913
914 case ATIME_PRESERVE_OPTION:
915 atime_preserve_option = 1;
916 break;
917
918 case CHECKPOINT_OPTION:
919 checkpoint_option = 1;
920 break;
921
922 case BACKUP_OPTION:
923 backup_option = 1;
924 if (optarg)
925 version_control_string = optarg;
926 break;
927
928 case DELETE_OPTION:
929 set_subcommand_option (DELETE_SUBCOMMAND);
930 break;
931
932 case EXCLUDE_OPTION:
933 add_exclude (excluded, optarg, exclude_options | recursion_option);
934 break;
935
936 case FORCE_LOCAL_OPTION:
937 force_local_option = 1;
938 break;
939
940 case INDEX_FILE_OPTION:
941 index_file_name = optarg;
942 break;
943
944 case IGNORE_CASE_OPTION:
945 exclude_options |= FNM_CASEFOLD;
946 break;
947
948 case IGNORE_FAILED_READ_OPTION:
949 ignore_failed_read_option = 1;
950 break;
951
952 case GROUP_OPTION:
953 if (! (strlen (optarg) < GNAME_FIELD_SIZE
954 && gname_to_gid (optarg, &group_option)))
955 {
956 uintmax_t g;
957 if (xstrtoumax (optarg, 0, 10, &g, "") == LONGINT_OK
958 && g == (gid_t) g)
959 group_option = g;
960 else
961 FATAL_ERROR ((0, 0, "%s: %s", quotearg_colon (optarg),
962 _("%s: Invalid group")));
963 }
964 break;
965
966 case MODE_OPTION:
967 mode_option
968 = mode_compile (optarg,
969 MODE_MASK_EQUALS | MODE_MASK_PLUS | MODE_MASK_MINUS);
970 if (mode_option == MODE_INVALID)
971 FATAL_ERROR ((0, 0, _("Invalid mode given on option")));
972 if (mode_option == MODE_MEMORY_EXHAUSTED)
973 xalloc_die ();
974 break;
975
976 case NO_ANCHORED_OPTION:
977 exclude_options &= ~ EXCLUDE_ANCHORED;
978 break;
979
980 case NO_IGNORE_CASE_OPTION:
981 exclude_options &= ~ FNM_CASEFOLD;
982 break;
983
984 case NO_OVERWRITE_DIR_OPTION:
985 old_files_option = NO_OVERWRITE_DIR_OLD_FILES;
986 break;
987
988 case NO_WILDCARDS_OPTION:
989 exclude_options &= ~ EXCLUDE_WILDCARDS;
990 break;
991
992 case NO_WILDCARDS_MATCH_SLASH_OPTION:
993 exclude_options |= FNM_FILE_NAME;
994 break;
995
996 case NULL_OPTION:
997 filename_terminator = '\0';
998 break;
999
1000 case NUMERIC_OWNER_OPTION:
1001 numeric_owner_option = 1;
1002 break;
1003
1004 case OVERWRITE_OPTION:
1005 old_files_option = OVERWRITE_OLD_FILES;
1006 break;
1007
1008 case OWNER_OPTION:
1009 if (! (strlen (optarg) < UNAME_FIELD_SIZE
1010 && uname_to_uid (optarg, &owner_option)))
1011 {
1012 uintmax_t u;
1013 if (xstrtoumax (optarg, 0, 10, &u, "") == LONGINT_OK
1014 && u == (uid_t) u)
1015 owner_option = u;
1016 else
1017 FATAL_ERROR ((0, 0, "%s: %s", quotearg_colon (optarg),
1018 _("Invalid owner")));
1019 }
1020 break;
1021
1022 case POSIX_OPTION:
1023 #if OLDGNU_COMPATIBILITY
1024 if (archive_format == DEFAULT_FORMAT)
1025 archive_format = GNU_FORMAT;
1026 else if (archive_format != GNU_FORMAT)
1027 USAGE_ERROR ((0, 0, _("Conflicting archive format options")));
1028 #else
1029 if (archive_format == DEFAULT_FORMAT)
1030 archive_format = POSIX_FORMAT;
1031 else if (archive_format != POSIX_FORMAT)
1032 USAGE_ERROR ((0, 0, _("Conflicting archive format options")));
1033 #endif
1034 break;
1035
1036 case PRESERVE_OPTION:
1037 same_permissions_option = 1;
1038 same_order_option = 1;
1039 break;
1040
1041 case RECORD_SIZE_OPTION:
1042 {
1043 uintmax_t u;
1044 if (! (xstrtoumax (optarg, 0, 10, &u, "") == LONGINT_OK
1045 && u == (size_t) u))
1046 USAGE_ERROR ((0, 0, "%s: %s", quotearg_colon (optarg),
1047 _("Invalid record size")));
1048 record_size = u;
1049 if (record_size % BLOCKSIZE != 0)
1050 USAGE_ERROR ((0, 0, _("Record size must be a multiple of %d."),
1051 BLOCKSIZE));
1052 blocking_factor = record_size / BLOCKSIZE;
1053 }
1054 break;
1055
1056 case RECURSIVE_UNLINK_OPTION:
1057 recursive_unlink_option = 1;
1058 break;
1059
1060 case REMOVE_FILES_OPTION:
1061 remove_files_option = 1;
1062 break;
1063
1064 case RSH_COMMAND_OPTION:
1065 rsh_command_option = optarg;
1066 break;
1067
1068 case SUFFIX_OPTION:
1069 backup_option = 1;
1070 backup_suffix_string = optarg;
1071 break;
1072
1073 case USE_COMPRESS_PROGRAM_OPTION:
1074 set_use_compress_program_option (optarg);
1075 break;
1076
1077 case VOLNO_FILE_OPTION:
1078 volno_file_option = optarg;
1079 break;
1080
1081 case WILDCARDS_OPTION:
1082 exclude_options |= EXCLUDE_WILDCARDS;
1083 break;
1084
1085 case WILDCARDS_MATCH_SLASH_OPTION:
1086 exclude_options &= ~ FNM_FILE_NAME;
1087 break;
1088
1089 case '0':
1090 case '1':
1091 case '2':
1092 case '3':
1093 case '4':
1094 case '5':
1095 case '6':
1096 case '7':
1097
1098 #ifdef DEVICE_PREFIX
1099 {
1100 int device = optchar - '0';
1101 int density;
1102 static char buf[sizeof DEVICE_PREFIX + 10];
1103 char *cursor;
1104
1105 density = getopt_long (argc, argv, "lmh", 0, 0);
1106 strcpy (buf, DEVICE_PREFIX);
1107 cursor = buf + strlen (buf);
1108
1109 #ifdef DENSITY_LETTER
1110
1111 sprintf (cursor, "%d%c", device, density);
1112
1113 #else /* not DENSITY_LETTER */
1114
1115 switch (density)
1116 {
1117 case 'l':
1118 #ifdef LOW_NUM
1119 device += LOW_NUM;
1120 #endif
1121 break;
1122
1123 case 'm':
1124 #ifdef MID_NUM
1125 device += MID_NUM;
1126 #else
1127 device += 8;
1128 #endif
1129 break;
1130
1131 case 'h':
1132 #ifdef HGH_NUM
1133 device += HGH_NUM;
1134 #else
1135 device += 16;
1136 #endif
1137 break;
1138
1139 default:
1140 usage (TAREXIT_FAILURE);
1141 }
1142 sprintf (cursor, "%d", device);
1143
1144 #endif /* not DENSITY_LETTER */
1145
1146 if (archive_names == allocated_archive_names)
1147 {
1148 allocated_archive_names *= 2;
1149 archive_name_array =
1150 xrealloc (archive_name_array,
1151 sizeof (const char *) * allocated_archive_names);
1152 }
1153 archive_name_array[archive_names++] = buf;
1154
1155 /* FIXME: How comes this works for many archives when buf is
1156 not xstrdup'ed? */
1157 }
1158 break;
1159
1160 #else /* not DEVICE_PREFIX */
1161
1162 USAGE_ERROR ((0, 0,
1163 _("Options `-[0-7][lmh]' not supported by *this* tar")));
1164
1165 #endif /* not DEVICE_PREFIX */
1166 }
1167
1168 /* Handle operands after any "--" argument. */
1169 for (; optind < argc; optind++)
1170 {
1171 name_add (argv[optind]);
1172 input_files++;
1173 }
1174
1175 /* Process trivial options. */
1176
1177 if (show_version)
1178 {
1179 printf ("tar (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION);
1180 printf (_("Copyright (C) %d Free Software Foundation, Inc.\n"), 2003);
1181 puts (_("\
1182 This program comes with NO WARRANTY, to the extent permitted by law.\n\
1183 You may redistribute it under the terms of the GNU General Public License;\n\
1184 see the file named COPYING for details."));
1185
1186 puts (_("Written by John Gilmore and Jay Fenlason."));
1187
1188 exit (TAREXIT_SUCCESS);
1189 }
1190
1191 if (show_help)
1192 usage (TAREXIT_SUCCESS);
1193
1194 /* Derive option values and check option consistency. */
1195
1196 if (archive_format == DEFAULT_FORMAT)
1197 {
1198 #if OLDGNU_COMPATIBILITY
1199 archive_format = OLDGNU_FORMAT;
1200 #else
1201 archive_format = GNU_FORMAT;
1202 #endif
1203 }
1204
1205 if (archive_format == GNU_FORMAT && getenv ("POSIXLY_CORRECT"))
1206 archive_format = POSIX_FORMAT;
1207
1208 if ((volume_label_option
1209 || incremental_option || multi_volume_option || sparse_option)
1210 && archive_format != OLDGNU_FORMAT && archive_format != GNU_FORMAT)
1211 USAGE_ERROR ((0, 0,
1212 _("GNU features wanted on incompatible archive format")));
1213
1214 if (archive_names == 0)
1215 {
1216 /* If no archive file name given, try TAPE from the environment, or
1217 else, DEFAULT_ARCHIVE from the configuration process. */
1218
1219 archive_names = 1;
1220 archive_name_array[0] = getenv ("TAPE");
1221 if (! archive_name_array[0])
1222 archive_name_array[0] = DEFAULT_ARCHIVE;
1223 }
1224
1225 /* Allow multiple archives only with `-M'. */
1226
1227 if (archive_names > 1 && !multi_volume_option)
1228 USAGE_ERROR ((0, 0,
1229 _("Multiple archive files requires `-M' option")));
1230
1231 if (listed_incremental_option
1232 && newer_mtime_option != TYPE_MINIMUM (time_t))
1233 USAGE_ERROR ((0, 0,
1234 _("Cannot combine --listed-incremental with --newer")));
1235
1236 if (volume_label_option)
1237 {
1238 size_t volume_label_max_len =
1239 (sizeof current_header->header.name
1240 - 1 /* for trailing '\0' */
1241 - (multi_volume_option
1242 ? (sizeof " Volume "
1243 - 1 /* for null at end of " Volume " */
1244 + INT_STRLEN_BOUND (int) /* for volume number */
1245 - 1 /* for sign, as 0 <= volno */)
1246 : 0));
1247 if (volume_label_max_len < strlen (volume_label_option))
1248 USAGE_ERROR ((0, 0,
1249 _("%s: Volume label is too long (limit is %lu bytes)"),
1250 quotearg_colon (volume_label_option),
1251 (unsigned long) volume_label_max_len));
1252 }
1253
1254 /* If ready to unlink hierarchies, so we are for simpler files. */
1255 if (recursive_unlink_option)
1256 old_files_option = UNLINK_FIRST_OLD_FILES;
1257
1258 /* Forbid using -c with no input files whatsoever. Check that `-f -',
1259 explicit or implied, is used correctly. */
1260
1261 switch (subcommand_option)
1262 {
1263 case CREATE_SUBCOMMAND:
1264 if (input_files == 0 && !files_from_option)
1265 USAGE_ERROR ((0, 0,
1266 _("Cowardly refusing to create an empty archive")));
1267 break;
1268
1269 case EXTRACT_SUBCOMMAND:
1270 case LIST_SUBCOMMAND:
1271 case DIFF_SUBCOMMAND:
1272 for (archive_name_cursor = archive_name_array;
1273 archive_name_cursor < archive_name_array + archive_names;
1274 archive_name_cursor++)
1275 if (!strcmp (*archive_name_cursor, "-"))
1276 request_stdin ("-f");
1277 break;
1278
1279 case CAT_SUBCOMMAND:
1280 case UPDATE_SUBCOMMAND:
1281 case APPEND_SUBCOMMAND:
1282 for (archive_name_cursor = archive_name_array;
1283 archive_name_cursor < archive_name_array + archive_names;
1284 archive_name_cursor++)
1285 if (!strcmp (*archive_name_cursor, "-"))
1286 USAGE_ERROR ((0, 0,
1287 _("Options `-Aru' are incompatible with `-f -'")));
1288
1289 default:
1290 break;
1291 }
1292
1293 archive_name_cursor = archive_name_array;
1294
1295 /* Prepare for generating backup names. */
1296
1297 if (backup_suffix_string)
1298 simple_backup_suffix = xstrdup (backup_suffix_string);
1299
1300 if (backup_option)
1301 backup_type = xget_version ("--backup", version_control_string);
1302
1303 if (verbose_option && textual_date_option)
1304 {
1305 char const *treated_as = tartime (newer_mtime_option);
1306 if (strcmp (textual_date_option, treated_as) != 0)
1307 WARN ((0, 0, _("Treating date `%s' as %s"),
1308 textual_date_option, treated_as));
1309 }
1310 }
1311 \f
1312 /* Tar proper. */
1313
1314 /* Main routine for tar. */
1315 int
1316 main (int argc, char **argv)
1317 {
1318 #if HAVE_CLOCK_GETTIME
1319 if (clock_gettime (CLOCK_REALTIME, &start_timespec) != 0)
1320 #endif
1321 start_time = time (0);
1322 program_name = argv[0];
1323 setlocale (LC_ALL, "");
1324 bindtextdomain (PACKAGE, LOCALEDIR);
1325 textdomain (PACKAGE);
1326
1327 exit_status = TAREXIT_SUCCESS;
1328 filename_terminator = '\n';
1329 set_quoting_style (0, escape_quoting_style);
1330
1331 /* Pre-allocate a few structures. */
1332
1333 allocated_archive_names = 10;
1334 archive_name_array =
1335 xmalloc (sizeof (const char *) * allocated_archive_names);
1336 archive_names = 0;
1337
1338 #ifdef SIGCHLD
1339 /* System V fork+wait does not work if SIGCHLD is ignored. */
1340 signal (SIGCHLD, SIG_DFL);
1341 #endif
1342
1343 init_names ();
1344
1345 /* Decode options. */
1346
1347 decode_options (argc, argv);
1348 name_init (argc, argv);
1349
1350 /* Main command execution. */
1351
1352 if (volno_file_option)
1353 init_volume_number ();
1354
1355 switch (subcommand_option)
1356 {
1357 case UNKNOWN_SUBCOMMAND:
1358 USAGE_ERROR ((0, 0,
1359 _("You must specify one of the `-Acdtrux' options")));
1360
1361 case CAT_SUBCOMMAND:
1362 case UPDATE_SUBCOMMAND:
1363 case APPEND_SUBCOMMAND:
1364 update_archive ();
1365 break;
1366
1367 case DELETE_SUBCOMMAND:
1368 delete_archive_members ();
1369 break;
1370
1371 case CREATE_SUBCOMMAND:
1372 create_archive ();
1373 name_close ();
1374
1375 if (totals_option)
1376 print_total_written ();
1377 break;
1378
1379 case EXTRACT_SUBCOMMAND:
1380 extr_init ();
1381 read_and (extract_archive);
1382
1383 /* FIXME: should extract_finish () even if an ordinary signal is
1384 received. */
1385 extract_finish ();
1386
1387 break;
1388
1389 case LIST_SUBCOMMAND:
1390 read_and (list_archive);
1391 break;
1392
1393 case DIFF_SUBCOMMAND:
1394 diff_init ();
1395 read_and (diff_archive);
1396 break;
1397 }
1398
1399 if (volno_file_option)
1400 closeout_volume_number ();
1401
1402 /* Dispose of allocated memory, and return. */
1403
1404 free (archive_name_array);
1405 name_term ();
1406
1407 if (stdlis != stderr && (ferror (stdlis) || fclose (stdlis) != 0))
1408 FATAL_ERROR ((0, 0, _("Error in writing to standard output")));
1409 if (exit_status == TAREXIT_FAILURE)
1410 error (0, 0, _("Error exit delayed from previous errors"));
1411 if (ferror (stderr) || fclose (stderr) != 0)
1412 exit_status = TAREXIT_FAILURE;
1413 exit (exit_status);
1414 }
This page took 0.097461 seconds and 5 git commands to generate.