xref: /aosp_15_r20/external/sandboxed-api/oss-internship-2020/libarchive/ld_preload_example/minitar.h (revision ec63e07ab9515d95e79c211197c445ef84cefa6a)
1 // Copyright 2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef LIBARCHIVE_LD_PRELOAD_EXAMPLE_MINITAR_H_
16 #define LIBARCHIVE_LD_PRELOAD_EXAMPLE_MINITAR_H_
17 
18 #include <archive.h>
19 #include <archive_entry.h>
20 #include <fcntl.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sys/stat.h>
25 #include <sys/types.h>
26 #include <unistd.h>
27 
28 #include <iostream>
29 
30 // The declarations below have been extracted from upstream's minitar.c, hence
31 // the formatting.
32 //
33 // clang-format off
34 
35 /*
36  * NO_CREATE implies NO_BZIP2_CREATE and NO_GZIP_CREATE and NO_COMPRESS_CREATE.
37  */
38 #ifdef NO_CREATE
39 #undef NO_BZIP2_CREATE
40 #define NO_BZIP2_CREATE
41 #undef NO_COMPRESS_CREATE
42 #define NO_COMPRESS_CREATE
43 #undef NO_GZIP_CREATE
44 #define NO_GZIP_CREATE
45 #endif
46 
47 /*
48  * The combination of NO_BZIP2_CREATE and NO_BZIP2_EXTRACT is
49  * equivalent to NO_BZIP2.
50  */
51 #ifdef NO_BZIP2_CREATE
52 #ifdef NO_BZIP2_EXTRACT
53 #undef NO_BZIP2
54 #define NO_BZIP2
55 #endif
56 #endif
57 
58 #ifdef NO_BZIP2
59 #undef NO_BZIP2_EXTRACT
60 #define NO_BZIP2_EXTRACT
61 #undef NO_BZIP2_CREATE
62 #define NO_BZIP2_CREATE
63 #endif
64 
65 /*
66  * The combination of NO_COMPRESS_CREATE and NO_COMPRESS_EXTRACT is
67  * equivalent to NO_COMPRESS.
68  */
69 #ifdef NO_COMPRESS_CREATE
70 #ifdef NO_COMPRESS_EXTRACT
71 #undef NO_COMPRESS
72 #define NO_COMPRESS
73 #endif
74 #endif
75 
76 #ifdef NO_COMPRESS
77 #undef NO_COMPRESS_EXTRACT
78 #define NO_COMPRESS_EXTRACT
79 #undef NO_COMPRESS_CREATE
80 #define NO_COMPRESS_CREATE
81 #endif
82 
83 /*
84  * The combination of NO_GZIP_CREATE and NO_GZIP_EXTRACT is
85  * equivalent to NO_GZIP.
86  */
87 #ifdef NO_GZIP_CREATE
88 #ifdef NO_GZIP_EXTRACT
89 #undef NO_GZIP
90 #define NO_GZIP
91 #endif
92 #endif
93 
94 #ifdef NO_GZIP
95 #undef NO_GZIP_EXTRACT
96 #define NO_GZIP_EXTRACT
97 #undef NO_GZIP_CREATE
98 #define NO_GZIP_CREATE
99 #endif
100 
101 #ifndef NO_CREATE
102 void create(const char *filename, int compress, const char **argv,
103             int verbose = 1);
104 #endif
105 void errmsg(const char *);
106 void extract(const char *filename, int do_extract, int flags, int verbose = 1);
107 int copy_data(struct archive *, struct archive *);
108 void msg(const char *);
109 void usage(void);
110 
111 // clang-format on
112 #endif  // LIBARCHIVE_LD_PRELOAD_EXAMPLE_MINITAR_H_
113