check_header_gzip.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <stdlib.h>
  2. #include <unistd.h>
  3. #include "libbb.h"
  4. #include "unarchive.h" /* for external decl of check_header_gzip */
  5. extern void check_header_gzip(int src_fd)
  6. {
  7. union {
  8. unsigned char raw[8];
  9. struct {
  10. unsigned char method;
  11. unsigned char flags;
  12. unsigned int mtime;
  13. unsigned char xtra_flags;
  14. unsigned char os_flags;
  15. } formated;
  16. } header;
  17. bb_xread_all(src_fd, header.raw, 8);
  18. /* Check the compression method */
  19. if (header.formated.method != 8) {
  20. bb_error_msg_and_die("Unknown compression method %d",
  21. header.formated.method);
  22. }
  23. if (header.formated.flags & 0x04) {
  24. /* bit 2 set: extra field present */
  25. unsigned char extra_short;
  26. extra_short = bb_xread_char(src_fd) + (bb_xread_char(src_fd) << 8);
  27. while (extra_short > 0) {
  28. /* Ignore extra field */
  29. bb_xread_char(src_fd);
  30. extra_short--;
  31. }
  32. }
  33. /* Discard original name if any */
  34. if (header.formated.flags & 0x08) {
  35. /* bit 3 set: original file name present */
  36. while(bb_xread_char(src_fd) != 0);
  37. }
  38. /* Discard file comment if any */
  39. if (header.formated.flags & 0x10) {
  40. /* bit 4 set: file comment present */
  41. while(bb_xread_char(src_fd) != 0);
  42. }
  43. /* Read the header checksum */
  44. if (header.formated.flags & 0x02) {
  45. bb_xread_char(src_fd);
  46. bb_xread_char(src_fd);
  47. }
  48. return;
  49. }