- printf ("tar (%s) %s\n%s\n", PACKAGE_NAME, PACKAGE_VERSION,
- "Copyright (C) 2004 Free Software Foundation, Inc.\n");
- puts (_("Based on the work of John Gilmore and Jay Fenlason. See AUTHORS\n\
-for complete list of authors.\n"));
- printf (_(" GNU tar is free software; you can redistribute it and/or modify\n"
- " it under the terms of the GNU General Public License as published by\n"
- " the Free Software Foundation; either version 2 of the License, or\n"
- " (at your option) any later version.\n"
- "\n"
- " GNU tar is distributed in the hope that it will be useful,\n"
- " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
- " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
- " GNU General Public License for more details.\n"
- "\n"
- " You should have received a copy of the GNU General Public License\n"
- " along with GNU tar; if not, write to the Free Software\n"
- " Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n\n"));
- exit (0);
+ static struct sigtab
+ {
+ char *name;
+ int signo;
+ } sigtab[] = {
+ { "SIGUSR1", SIGUSR1 },
+ { "USR1", SIGUSR1 },
+ { "SIGUSR2", SIGUSR2 },
+ { "USR2", SIGUSR2 },
+ { "SIGHUP", SIGHUP },
+ { "HUP", SIGHUP },
+ { "SIGINT", SIGINT },
+ { "INT", SIGINT },
+ { "SIGQUIT", SIGQUIT },
+ { "QUIT", SIGQUIT }
+ };
+ struct sigtab *p;
+
+ for (p = sigtab; p < sigtab + sizeof (sigtab) / sizeof (sigtab[0]); p++)
+ if (strcmp (p->name, name) == 0)
+ {
+ stat_on_signal (p->signo);
+ return;
+ }
+ FATAL_ERROR ((0, 0, _("Unknown signal name: %s"), name));
+}
+
+\f
+struct textual_date
+{
+ struct textual_date *next;
+ struct timespec *ts;
+ const char *option;
+ const char *date;
+};
+
+static void
+get_date_or_file (struct tar_args *args, const char *option,
+ const char *str, struct timespec *ts)
+{
+ if (FILE_SYSTEM_PREFIX_LEN (str) != 0
+ || ISSLASH (*str)
+ || *str == '.')
+ {
+ struct stat st;
+ if (deref_stat (dereference_option, str, &st) != 0)
+ {
+ stat_error (str);
+ USAGE_ERROR ((0, 0, _("Date sample file not found")));
+ }
+ *ts = get_stat_mtime (&st);
+ }
+ else
+ {
+ if (! get_date (ts, str, NULL))
+ {
+ WARN ((0, 0, _("Substituting %s for unknown date format %s"),
+ tartime (*ts, false), quote (str)));
+ ts->tv_nsec = 0;
+ }
+ else
+ {
+ struct textual_date *p = xmalloc (sizeof (*p));
+ p->ts = ts;
+ p->option = option;
+ p->date = str;
+ p->next = args->textual_date;
+ args->textual_date = p;
+ }
+ }
+}
+
+static void
+report_textual_dates (struct tar_args *args)
+{
+ struct textual_date *p;
+ for (p = args->textual_date; p; )
+ {
+ struct textual_date *next = p->next;
+ char const *treated_as = tartime (*p->ts, true);
+ if (strcmp (p->date, treated_as) != 0)
+ WARN ((0, 0, _("Option %s: Treating date `%s' as %s"),
+ p->option, p->date, treated_as));
+ free (p);
+ p = next;
+ }
+}
+
+\f
+static volatile int _argp_hang;
+
+enum read_file_list_state /* Result of reading file name from the list file */
+ {
+ file_list_success, /* OK, name read successfully */
+ file_list_end, /* End of list file */
+ file_list_zero /* Zero separator encountered where it should not */
+ };
+
+/* Read from FP a sequence of characters up to FILENAME_TERMINATOR and put them
+ into STK.
+ */
+static enum read_file_list_state
+read_name_from_file (FILE *fp, struct obstack *stk)
+{
+ int c;
+ size_t counter = 0;
+
+ for (c = getc (fp); c != EOF && c != filename_terminator; c = getc (fp))
+ {
+ if (c == 0)
+ {
+ /* We have read a zero separator. The file possibly is
+ zero-separated */
+ /* FATAL_ERROR((0, 0, N_("file name contains null character"))); */
+ return file_list_zero;
+ }
+ obstack_1grow (stk, c);
+ counter++;
+ }
+
+ obstack_1grow (stk, 0);
+
+ return (counter == 0 && c == EOF) ? file_list_end : file_list_success;
+}
+
+\f
+static bool files_from_option; /* When set, tar will not refuse to create
+ empty archives */
+static struct obstack argv_stk; /* Storage for additional command line options
+ read using -T option */
+
+/* Prevent recursive inclusion of the same file */
+struct file_id_list
+{
+ struct file_id_list *next;
+ ino_t ino;
+ dev_t dev;
+};
+
+static struct file_id_list *file_id_list;
+
+static void
+add_file_id (const char *filename)
+{
+ struct file_id_list *p;
+ struct stat st;
+
+ if (stat (filename, &st))
+ stat_fatal (filename);
+ for (p = file_id_list; p; p = p->next)
+ if (p->ino == st.st_ino && p->dev == st.st_dev)
+ {
+ FATAL_ERROR ((0, 0, _("%s: file list already read"),
+ quotearg_colon (filename)));
+ }
+ p = xmalloc (sizeof *p);
+ p->next = file_id_list;
+ p->ino = st.st_ino;
+ p->dev = st.st_dev;
+ file_id_list = p;