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