3
0

get_header_tar_gz.c 991 B

123456789101112131415161718192021222324252627282930313233343536
  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 FAST_FUNC 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. /* Can skip this check, but error message will be less clear */
  20. if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
  21. bb_error_msg_and_die("invalid gzip magic");
  22. }
  23. #endif
  24. open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip");
  25. archive_handle->offset = 0;
  26. while (get_header_tar(archive_handle) == EXIT_SUCCESS)
  27. continue;
  28. /* Can only do one file at a time */
  29. return EXIT_FAILURE;
  30. }