1 /* This file is part of GNU tar.
2 Copyright 2007, 2009, 2013-2014, 2016 Free Software Foundation, Inc.
4 Written by Sergey Poznyakoff.
6 GNU tar is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any later
11 GNU tar is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14 Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with GNU tar. If not, see <http://www.gnu.org/licenses/>. */
22 struct compression_suffix
29 static struct compression_suffix compression_suffixes[] = {
30 #define __CAT2__(a,b) a ## b
31 #define S(s,p) #s, sizeof (#s) - 1, __CAT2__(p,_PROGRAM)
47 { S(txz, XZ) }, /* Slackware */
53 static struct compression_suffix const *
54 find_compression_suffix (const char *name, size_t *ret_len)
56 char *suf = strrchr (name, '.');
61 struct compression_suffix *p;
66 for (p = compression_suffixes; p->suffix; p++)
68 if (p->length == len && memcmp (p->suffix, suf, len) == 0)
71 *ret_len = strlen (name) - len - 1;
80 find_compression_program (const char *name, const char *defprog)
82 struct compression_suffix const *p = find_compression_suffix (name, NULL);
89 set_compression_program_by_suffix (const char *name, const char *defprog)
91 const char *program = find_compression_program (name, defprog);
93 use_compress_program_option = program;
97 strip_compression_suffix (const char *name)
102 if (find_compression_suffix (name, &len))
104 if (strncmp (name + len - 4, ".tar", 4) == 0)
108 s = xmalloc (len + 1);
109 memcpy (s, name, len);