diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/libbb.h | 21 | ||||
-rw-r--r-- | include/unarchive.h | 109 |
2 files changed, 88 insertions, 42 deletions
diff --git a/include/libbb.h b/include/libbb.h index 6ab942bd8..bd0d1e942 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -48,10 +48,6 @@ | |||
48 | # include "sha1.h" | 48 | # include "sha1.h" |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | /* Compatability with ANSI C */ | ||
52 | #ifndef inline | ||
53 | # define inline | ||
54 | #endif | ||
55 | 51 | ||
56 | #if (__GNU_LIBRARY__ < 5) && (!defined __dietlibc__) | 52 | #if (__GNU_LIBRARY__ < 5) && (!defined __dietlibc__) |
57 | /* libc5 doesn't define socklen_t */ | 53 | /* libc5 doesn't define socklen_t */ |
@@ -74,6 +70,9 @@ char *strtok_r(char *s, const char *delim, char **ptrptr); | |||
74 | #define BUF_SIZE 8192 | 70 | #define BUF_SIZE 8192 |
75 | #define EXPAND_ALLOC 1024 | 71 | #define EXPAND_ALLOC 1024 |
76 | 72 | ||
73 | static inline int is_decimal(int ch) { return ((ch >= '0') && (ch <= '9')); } | ||
74 | static inline int is_octal(int ch) { return ((ch >= '0') && (ch <= '7')); } | ||
75 | |||
77 | /* Macros for min/max. */ | 76 | /* Macros for min/max. */ |
78 | #ifndef MIN | 77 | #ifndef MIN |
79 | #define MIN(a,b) (((a)<(b))?(a):(b)) | 78 | #define MIN(a,b) (((a)<(b))?(a):(b)) |
@@ -83,8 +82,6 @@ char *strtok_r(char *s, const char *delim, char **ptrptr); | |||
83 | #define MAX(a,b) (((a)>(b))?(a):(b)) | 82 | #define MAX(a,b) (((a)>(b))?(a):(b)) |
84 | #endif | 83 | #endif |
85 | 84 | ||
86 | |||
87 | |||
88 | extern void show_usage(void) __attribute__ ((noreturn)); | 85 | extern void show_usage(void) __attribute__ ((noreturn)); |
89 | extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); | 86 | extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
90 | extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); | 87 | extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); |
@@ -228,10 +225,7 @@ extern long arith (const char *startbuf, int *errcode); | |||
228 | int read_package_field(const char *package_buffer, char **field_name, char **field_value); | 225 | int read_package_field(const char *package_buffer, char **field_name, char **field_value); |
229 | char *fgets_str(FILE *file, const char *terminating_string); | 226 | char *fgets_str(FILE *file, const char *terminating_string); |
230 | 227 | ||
231 | extern int inflate(FILE *in, FILE *out); | 228 | extern int inflate(int in, int out); |
232 | extern int unzip(FILE *l_in_file, FILE *l_out_file); | ||
233 | extern void gz_close(int gunzip_pid); | ||
234 | extern FILE *gz_open(FILE *compressed_file, int *pid); | ||
235 | 229 | ||
236 | extern struct hostent *xgethostbyname(const char *name); | 230 | extern struct hostent *xgethostbyname(const char *name); |
237 | extern struct hostent *xgethostbyname2(const char *name, int af); | 231 | extern struct hostent *xgethostbyname2(const char *name, int af); |
@@ -335,4 +329,11 @@ extern char *pw_encrypt(const char *clear, const char *salt); | |||
335 | extern struct spwd *pwd_to_spwd(const struct passwd *pw); | 329 | extern struct spwd *pwd_to_spwd(const struct passwd *pw); |
336 | extern int obscure(const char *old, const char *newval, const struct passwd *pwdp); | 330 | extern int obscure(const char *old, const char *newval, const struct passwd *pwdp); |
337 | 331 | ||
332 | //extern int xopen(const char *pathname, int flags, mode_t mode); | ||
333 | extern int xopen(const char *pathname, int flags); | ||
334 | extern ssize_t xread(int fd, void *buf, size_t count); | ||
335 | extern ssize_t xread_all_eof(int fd, void *buf, size_t count); | ||
336 | extern void xread_all(int fd, void *buf, size_t count); | ||
337 | extern unsigned char xread_char(int fd); | ||
338 | |||
338 | #endif /* __LIBCONFIG_H__ */ | 339 | #endif /* __LIBCONFIG_H__ */ |
diff --git a/include/unarchive.h b/include/unarchive.h index ffddc89f4..e564e9572 100644 --- a/include/unarchive.h +++ b/include/unarchive.h | |||
@@ -1,21 +1,19 @@ | |||
1 | #include <stdio.h> /* for FILE */ | 1 | #ifndef __UNARCHIVE_H__ |
2 | #include <unistd.h> /* for off_t */ | 2 | #define __UNARCHIVE_H__ |
3 | 3 | ||
4 | enum extract_functions_e { | 4 | #define ARCHIVE_PRESERVE_DATE 1 |
5 | extract_verbose_list = 1, | 5 | #define ARCHIVE_CREATE_LEADING_DIRS 2 |
6 | extract_list = 2, | 6 | #define ARCHIVE_EXTRACT_UNCONDITIONAL 4 |
7 | extract_one_to_buffer = 4, | 7 | #define ARCHIVE_EXTRACT_QUIET 8 |
8 | extract_to_stdout = 8, | 8 | |
9 | extract_all_to_fs = 16, | 9 | #include <sys/types.h> |
10 | extract_preserve_date = 32, | 10 | |
11 | extract_data_tar_gz = 64, | 11 | typedef struct gunzip_s { |
12 | extract_control_tar_gz = 128, | 12 | unsigned short buffer_count; |
13 | extract_unzip_only = 256, | 13 | unsigned char *buffer; |
14 | extract_unconditional = 512, | 14 | unsigned int crc; |
15 | extract_create_leading_dirs = 1024, | 15 | unsigned int count; |
16 | extract_quiet = 2048, | 16 | } gunzip_t; |
17 | extract_exclude_list = 4096 | ||
18 | }; | ||
19 | 17 | ||
20 | typedef struct file_headers_s { | 18 | typedef struct file_headers_s { |
21 | char *name; | 19 | char *name; |
@@ -26,23 +24,70 @@ typedef struct file_headers_s { | |||
26 | mode_t mode; | 24 | mode_t mode; |
27 | time_t mtime; | 25 | time_t mtime; |
28 | dev_t device; | 26 | dev_t device; |
29 | int (*extract_func) (FILE *, FILE *); | ||
30 | } file_header_t; | 27 | } file_header_t; |
31 | 28 | ||
32 | file_header_t *get_header_ar(FILE * in_file); | 29 | typedef struct llist_s { |
33 | file_header_t *get_header_cpio(FILE * src_stream); | 30 | const char *data; |
34 | file_header_t *get_header_tar(FILE * tar_stream); | 31 | const struct llist_s *link; |
35 | file_header_t *get_header_zip(FILE * zip_stream); | 32 | } llist_t; |
33 | |||
34 | typedef struct archive_handle_s { | ||
35 | /* define if the header and data compenent should processed */ | ||
36 | char (*filter)(const llist_t *, const llist_t *, const char *); | ||
37 | const llist_t *accept; | ||
38 | const llist_t *reject; | ||
39 | |||
40 | /* Contains the processed header entry */ | ||
41 | file_header_t *file_header; | ||
42 | |||
43 | /* process the header component, e.g. tar -t */ | ||
44 | void (*action_header)(const file_header_t *); | ||
45 | |||
46 | /* process the data componenet, e.g. extract to filesystem */ | ||
47 | void (*action_data)(struct archive_handle_s *); | ||
48 | char (*action_data_subarchive)(struct archive_handle_s *); | ||
49 | |||
50 | /* Contains the handle to a sub archive */ | ||
51 | struct archive_handle_s *sub_archive; | ||
52 | |||
53 | /* The raw stream as read from disk or stdin */ | ||
54 | int src_fd; | ||
55 | |||
56 | /* Count the number of bytes processed */ | ||
57 | off_t offset; | ||
58 | |||
59 | /* Misc. stuff */ | ||
60 | unsigned char flags; | ||
61 | |||
62 | } archive_handle_t; | ||
63 | |||
64 | extern archive_handle_t *init_handle(void); | ||
65 | |||
66 | extern char filter_accept_all(const llist_t *accept_list, const llist_t *reject_list, const char *key); | ||
67 | extern char filter_accept_list(const llist_t *accept_list, const llist_t *reject_list, const char *key); | ||
68 | extern char filter_accept_reject_list(const llist_t *accept_list, const llist_t *reject_list, const char *key); | ||
69 | |||
70 | extern void unpack_ar_archive(archive_handle_t *ar_archive); | ||
71 | |||
72 | extern void data_gunzip(archive_handle_t *archive_handle); | ||
73 | extern void data_skip(archive_handle_t *archive_handle); | ||
74 | extern void data_extract_all(archive_handle_t *archive_handle); | ||
75 | extern void data_extract_to_stdout(archive_handle_t *archive_handle); | ||
76 | |||
77 | extern void header_skip(const file_header_t *file_header); | ||
78 | extern void header_list(const file_header_t *file_header); | ||
79 | extern void header_verbose_list(const file_header_t *file_header); | ||
36 | 80 | ||
37 | void seek_sub_file(FILE * src_stream, const int count); | 81 | extern void check_header_gzip(int src_fd); |
82 | extern void check_trailer_gzip(int src_fd); | ||
38 | 83 | ||
39 | extern off_t archive_offset; | 84 | extern char get_header_ar(archive_handle_t *archive_handle); |
85 | extern char get_header_tar(archive_handle_t *archive_handle); | ||
86 | extern char get_header_tar_gz(archive_handle_t *archive_handle); | ||
40 | 87 | ||
41 | char *unarchive(FILE * src_stream, FILE * out_stream, | 88 | //extern void seek_sub_file(int src_fd, unsigned int amount); |
42 | file_header_t * (*get_headers) (FILE *), | 89 | extern const unsigned short data_align(const int src_fd, const unsigned int offset, const unsigned short align_to); |
43 | const int extract_function, const char *prefix, | 90 | extern const llist_t *add_to_list(const llist_t *old_head, const char *new_item); |
44 | char **include_name, char **exclude_name); | 91 | extern int copy_file_chunk_fd(int src_fd, int dst_fd, unsigned long long chunksize); |
45 | 92 | ||
46 | char *deb_extract(const char *package_filename, FILE * out_stream, | 93 | #endif |
47 | const int extract_function, const char *prefix, | ||
48 | const char *filename); | ||