unzip.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #ifndef __UNZIP_H
  2. #define __UNZIP_H
  3. #include <stdio.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. // notaz: something's missing this
  8. #ifndef UINT16
  9. #define UINT32 unsigned int
  10. #define UINT16 unsigned short
  11. #define UINT8 unsigned char
  12. #endif
  13. /***************************************************************************
  14. * Support for retrieving files from zipfiles
  15. ***************************************************************************/
  16. struct zipent {
  17. UINT32 cent_file_header_sig;
  18. UINT8 version_made_by;
  19. UINT8 host_os;
  20. UINT8 version_needed_to_extract;
  21. UINT8 os_needed_to_extract;
  22. UINT16 general_purpose_bit_flag;
  23. UINT16 compression_method;
  24. UINT16 last_mod_file_time;
  25. UINT16 last_mod_file_date;
  26. UINT32 crc32;
  27. UINT32 compressed_size;
  28. UINT32 uncompressed_size;
  29. UINT16 filename_length;
  30. UINT16 extra_field_length;
  31. UINT16 file_comment_length;
  32. UINT16 disk_number_start;
  33. UINT16 internal_file_attrib;
  34. UINT32 external_file_attrib;
  35. UINT32 offset_lcl_hdr_frm_frst_disk;
  36. char* name; /* 0 terminated */
  37. };
  38. typedef struct _ZIP {
  39. char* zip; /* zip name */
  40. FILE* fp; /* zip handler */
  41. long length; /* length of zip file */
  42. char* ecd; /* end_of_cent_dir data */
  43. unsigned ecd_length; /* end_of_cent_dir length */
  44. char* cd; /* cent_dir data */
  45. unsigned cd_pos; /* position in cent_dir */
  46. struct zipent ent; /* buffer for readzip */
  47. /* end_of_cent_dir */
  48. UINT32 end_of_cent_dir_sig;
  49. UINT16 number_of_this_disk;
  50. UINT16 number_of_disk_start_cent_dir;
  51. UINT16 total_entries_cent_dir_this_disk;
  52. UINT16 total_entries_cent_dir;
  53. UINT32 size_of_cent_dir;
  54. UINT32 offset_to_start_of_cent_dir;
  55. UINT16 zipfile_comment_length;
  56. char* zipfile_comment; /* pointer in ecd */
  57. } ZIP;
  58. /* Opens a zip stream for reading
  59. return:
  60. !=0 success, zip stream
  61. ==0 error
  62. */
  63. ZIP* openzip(const char* path);
  64. /* Closes a zip stream */
  65. void closezip(ZIP* zip);
  66. /* Reads the current entry from a zip stream
  67. in:
  68. zip opened zip
  69. return:
  70. !=0 success
  71. ==0 error
  72. */
  73. struct zipent* readzip(ZIP* zip);
  74. /* Suspend access to a zip file (release file handler)
  75. in:
  76. zip opened zip
  77. note:
  78. A suspended zip is automatically reopened at first call of
  79. readuncompressd() or readcompressed() functions
  80. */
  81. void suspendzip(ZIP* zip);
  82. /* Resets a zip stream to the first entry
  83. in:
  84. zip opened zip
  85. note:
  86. ZIP file must be opened and not suspended
  87. */
  88. void rewindzip(ZIP* zip);
  89. /* Read compressed data from a zip entry
  90. in:
  91. zip opened zip
  92. ent entry to read
  93. out:
  94. data buffer for data, ent.compressed_size UINT8s allocated by the caller
  95. return:
  96. ==0 success
  97. <0 error
  98. */
  99. int readcompresszip(ZIP* zip, struct zipent* ent, char* data);
  100. /* Read decompressed data from a zip entry
  101. in:
  102. zip zip stream open
  103. ent entry to read
  104. out:
  105. data buffer for data, ent.uncompressed_size UINT8s allocated by the caller
  106. return:
  107. ==0 success
  108. <0 error
  109. */
  110. int readuncompresszip(ZIP* zip, struct zipent* ent, char* data);
  111. int seekcompresszip(ZIP* zip, struct zipent* ent);
  112. /* public functions */
  113. int /* error */ load_zipped_file (const char *zipfile, const char *filename,
  114. unsigned char **buf, unsigned int *length);
  115. int /* error */ checksum_zipped_file (const char *zipfile, const char *filename, unsigned int *length, unsigned int *sum);
  116. void unzip_cache_clear(void);
  117. /* public globals */
  118. extern int gUnzipQuiet; /* flag controls error messages */
  119. #ifdef __cplusplus
  120. }
  121. #endif
  122. #endif