3
0

get_header_tar_gz.c 941 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  4. */
  5. #include "libbb.h"
  6. #include "unarchive.h"
  7. char get_header_tar_gz(archive_handle_t *archive_handle)
  8. {
  9. #if BB_MMU
  10. unsigned char magic[2];
  11. #endif
  12. /* Can't lseek over pipes */
  13. archive_handle->seek = seek_by_read;
  14. /* Check gzip magic only if open_transformer will invoke unpack_gz_stream (MMU case).
  15. * Otherwise, it will invoke an external helper "gunzip -cf" (NOMMU case) which will
  16. * need the header. */
  17. #if BB_MMU
  18. xread(archive_handle->src_fd, &magic, 2);
  19. if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
  20. bb_error_msg_and_die("invalid gzip magic");
  21. }
  22. #endif
  23. archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip");
  24. archive_handle->offset = 0;
  25. while (get_header_tar(archive_handle) == EXIT_SUCCESS)
  26. continue;
  27. /* Can only do one file at a time */
  28. return EXIT_FAILURE;
  29. }