less: document -S flag and make it independently configurable
[oweals/busybox.git] / archival / libarchive / filter_accept_list_reassign.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  *  Copyright (C) 2002 by Glenn McGrath
4  *
5  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
6  */
7
8 #include "libbb.h"
9 #include "bb_archive.h"
10
11 /* Built and used only if ENABLE_DPKG || ENABLE_DPKG_DEB */
12
13 /*
14  * Reassign the subarchive metadata parser based on the filename extension
15  * e.g. if its a .tar.gz modify archive_handle->sub_archive to process a .tar.gz
16  * or if its a .tar.bz2 make archive_handle->sub_archive handle that
17  */
18 char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle)
19 {
20         /* Check the file entry is in the accept list */
21         if (find_list_entry(archive_handle->accept, archive_handle->file_header->name)) {
22                 const char *name_ptr;
23
24                 /* Find extension */
25                 name_ptr = strrchr(archive_handle->file_header->name, '.');
26                 if (!name_ptr)
27                         return EXIT_FAILURE;
28                 name_ptr++;
29
30                 /* Modify the subarchive handler based on the extension */
31                 if (strcmp(name_ptr, "tar") == 0) {
32                         archive_handle->dpkg__action_data_subarchive = get_header_tar;
33                         return EXIT_SUCCESS;
34                 }
35                 if (ENABLE_FEATURE_SEAMLESS_GZ
36                  && strcmp(name_ptr, "gz") == 0
37                 ) {
38                         archive_handle->dpkg__action_data_subarchive = get_header_tar_gz;
39                         return EXIT_SUCCESS;
40                 }
41                 if (ENABLE_FEATURE_SEAMLESS_BZ2
42                  && strcmp(name_ptr, "bz2") == 0
43                 ) {
44                         archive_handle->dpkg__action_data_subarchive = get_header_tar_bz2;
45                         return EXIT_SUCCESS;
46                 }
47                 if (ENABLE_FEATURE_SEAMLESS_LZMA
48                  && strcmp(name_ptr, "lzma") == 0
49                 ) {
50                         archive_handle->dpkg__action_data_subarchive = get_header_tar_lzma;
51                         return EXIT_SUCCESS;
52                 }
53                 if (ENABLE_FEATURE_SEAMLESS_XZ
54                  && strcmp(name_ptr, "xz") == 0
55                 ) {
56                         archive_handle->dpkg__action_data_subarchive = get_header_tar_xz;
57                         return EXIT_SUCCESS;
58                 }
59         }
60         return EXIT_FAILURE;
61 }