unarchive.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #ifndef __UNARCHIVE_H__
  2. #define __UNARCHIVE_H__
  3. #define ARCHIVE_PRESERVE_DATE 1
  4. #define ARCHIVE_CREATE_LEADING_DIRS 2
  5. #define ARCHIVE_EXTRACT_UNCONDITIONAL 4
  6. #define ARCHIVE_EXTRACT_QUIET 8
  7. #define ARCHIVE_EXTRACT_NEWER 16
  8. #include <sys/types.h>
  9. #include <stdio.h>
  10. #include "libbb.h"
  11. typedef struct file_headers_s {
  12. char *name;
  13. char *link_name;
  14. off_t size;
  15. uid_t uid;
  16. gid_t gid;
  17. mode_t mode;
  18. time_t mtime;
  19. dev_t device;
  20. } file_header_t;
  21. typedef struct archive_handle_s {
  22. /* define if the header and data compenent should processed */
  23. char (*filter)(struct archive_handle_s *);
  24. llist_t *accept;
  25. llist_t *reject;
  26. llist_t *passed; /* List of files that have successfully been worked on */
  27. /* Contains the processed header entry */
  28. file_header_t *file_header;
  29. /* process the header component, e.g. tar -t */
  30. void (*action_header)(const file_header_t *);
  31. /* process the data component, e.g. extract to filesystem */
  32. void (*action_data)(struct archive_handle_s *);
  33. /* How to process any sub archive, e.g. get_header_tar_gz */
  34. char (*action_data_subarchive)(struct archive_handle_s *);
  35. /* Contains the handle to a sub archive */
  36. struct archive_handle_s *sub_archive;
  37. /* The raw stream as read from disk or stdin */
  38. int src_fd;
  39. /* Count the number of bytes processed */
  40. off_t offset;
  41. /* Function that skips data: read_by_char or read_by_skip */
  42. void (*seek)(const struct archive_handle_s *archive_handle, const unsigned int amount);
  43. /* Temporary storage */
  44. char *buffer;
  45. /* Misc. stuff */
  46. unsigned char flags;
  47. } archive_handle_t;
  48. extern archive_handle_t *init_handle(void);
  49. extern char filter_accept_all(archive_handle_t *archive_handle);
  50. extern char filter_accept_list(archive_handle_t *archive_handle);
  51. extern char filter_accept_list_reassign(archive_handle_t *archive_handle);
  52. extern char filter_accept_reject_list(archive_handle_t *archive_handle);
  53. extern void unpack_ar_archive(archive_handle_t *ar_archive);
  54. extern void data_skip(archive_handle_t *archive_handle);
  55. extern void data_extract_all(archive_handle_t *archive_handle);
  56. extern void data_extract_to_stdout(archive_handle_t *archive_handle);
  57. extern void data_extract_to_buffer(archive_handle_t *archive_handle);
  58. extern void header_skip(const file_header_t *file_header);
  59. extern void header_list(const file_header_t *file_header);
  60. extern void header_verbose_list(const file_header_t *file_header);
  61. extern void check_header_gzip(int src_fd);
  62. extern char get_header_ar(archive_handle_t *archive_handle);
  63. extern char get_header_cpio(archive_handle_t *archive_handle);
  64. extern char get_header_tar(archive_handle_t *archive_handle);
  65. extern char get_header_tar_bz2(archive_handle_t *archive_handle);
  66. extern char get_header_tar_gz(archive_handle_t *archive_handle);
  67. extern void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amount);
  68. extern void seek_by_char(const archive_handle_t *archive_handle, const unsigned int amount);
  69. extern void archive_xread_all(const archive_handle_t *archive_handle, void *buf, const size_t count);
  70. extern ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned char *buf, size_t count);
  71. extern void data_align(archive_handle_t *archive_handle, const unsigned short boundary);
  72. extern const llist_t *find_list_entry(const llist_t *list, const char *filename);
  73. extern int uncompressStream(int src_fd, int dst_fd);
  74. extern void inflate_init(unsigned int bufsize);
  75. extern int inflate_unzip(int in, int out);
  76. extern int inflate_gunzip(int in, int out);
  77. extern int open_transformer(int src_fd, int (*transformer)(int src_fd, int dst_fd));
  78. #endif