@papyrus-sdk/engine-native 0.2.22-beta.2 → 0.2.22-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/android/build.gradle +1 -0
  2. package/android/src/main/cpp/CMakeLists.txt +137 -0
  3. package/android/src/main/cpp/PapyrusComicArchiveJni.cpp +68 -0
  4. package/android/src/main/cpp/PapyrusComicArchiveTest.cpp +55 -0
  5. package/android/src/main/java/com/papyrus/engine/PapyrusComicArchiveNative.java +14 -0
  6. package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentView.java +353 -0
  7. package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentViewManager.java +32 -0
  8. package/android/src/main/java/com/papyrus/engine/PapyrusComicPageLayout.java +17 -0
  9. package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +298 -34
  10. package/android/src/main/java/com/papyrus/engine/PapyrusNativeTextModel.java +195 -0
  11. package/android/src/main/java/com/papyrus/engine/PapyrusPackage.java +3 -1
  12. package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerView.java +24 -0
  13. package/android/src/main/java/com/papyrus/engine/PapyrusRenderMath.java +9 -0
  14. package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentView.java +439 -0
  15. package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentViewManager.java +43 -0
  16. package/android/src/main/java/com/papyrus/engine/PapyrusTextStore.java +43 -0
  17. package/dist/index.d.mts +439 -3
  18. package/dist/index.d.ts +439 -3
  19. package/dist/index.js +412 -4
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +404 -3
  22. package/dist/index.mjs.map +1 -1
  23. package/ios/PapyrusComicDocumentView.h +21 -0
  24. package/ios/PapyrusComicDocumentView.m +374 -0
  25. package/ios/PapyrusComicDocumentViewManager.m +23 -0
  26. package/ios/PapyrusEngineStore.m +4 -0
  27. package/ios/PapyrusNativeEngine.m +664 -0
  28. package/ios/PapyrusNativeEngine.podspec +26 -1
  29. package/ios/PapyrusPageRotationRegistry.h +29 -0
  30. package/ios/PapyrusPageRotationRegistry.m +179 -0
  31. package/ios/PapyrusPageView.m +38 -11
  32. package/ios/PapyrusPdfDocumentView.h +2 -0
  33. package/ios/PapyrusPdfDocumentView.m +116 -9
  34. package/ios/PapyrusPdfDocumentViewManager.m +2 -0
  35. package/ios/PapyrusPdfPageTheme.h +15 -0
  36. package/ios/PapyrusPdfPageTheme.m +218 -0
  37. package/ios/PapyrusTextDocumentView.h +27 -0
  38. package/ios/PapyrusTextDocumentView.m +299 -0
  39. package/ios/PapyrusTextDocumentViewManager.m +29 -0
  40. package/ios/PapyrusTextStore.h +13 -0
  41. package/ios/PapyrusTextStore.m +73 -0
  42. package/package.json +5 -3
  43. package/third_party_licenses/BLAKE2-NOTICE.txt +11 -0
  44. package/third_party_licenses/libarchive-COPYING +65 -0
  45. package/vendor/libarchive/PapyrusComicArchive.cpp +376 -0
  46. package/vendor/libarchive/PapyrusComicArchive.h +30 -0
  47. package/vendor/libarchive/README.papyrus.md +15 -0
  48. package/vendor/libarchive/android.h +192 -0
  49. package/vendor/libarchive/config/PapyrusArchiveConfig.h +65 -0
  50. package/vendor/libarchive/libarchive/CMakeLists.txt +293 -0
  51. package/vendor/libarchive/libarchive/android_lf.h +36 -0
  52. package/vendor/libarchive/libarchive/archive.h +1266 -0
  53. package/vendor/libarchive/libarchive/archive_acl.c +2025 -0
  54. package/vendor/libarchive/libarchive/archive_acl_private.h +85 -0
  55. package/vendor/libarchive/libarchive/archive_blake2.h +197 -0
  56. package/vendor/libarchive/libarchive/archive_blake2_impl.h +161 -0
  57. package/vendor/libarchive/libarchive/archive_blake2s_ref.c +369 -0
  58. package/vendor/libarchive/libarchive/archive_blake2sp_ref.c +361 -0
  59. package/vendor/libarchive/libarchive/archive_check_magic.c +183 -0
  60. package/vendor/libarchive/libarchive/archive_cmdline.c +211 -0
  61. package/vendor/libarchive/libarchive/archive_cmdline_private.h +45 -0
  62. package/vendor/libarchive/libarchive/archive_crc32.h +123 -0
  63. package/vendor/libarchive/libarchive/archive_cryptor.c +534 -0
  64. package/vendor/libarchive/libarchive/archive_cryptor_private.h +199 -0
  65. package/vendor/libarchive/libarchive/archive_digest.c +1584 -0
  66. package/vendor/libarchive/libarchive/archive_digest_private.h +431 -0
  67. package/vendor/libarchive/libarchive/archive_disk_acl_darwin.c +558 -0
  68. package/vendor/libarchive/libarchive/archive_disk_acl_freebsd.c +712 -0
  69. package/vendor/libarchive/libarchive/archive_disk_acl_linux.c +760 -0
  70. package/vendor/libarchive/libarchive/archive_disk_acl_sunos.c +824 -0
  71. package/vendor/libarchive/libarchive/archive_endian.h +234 -0
  72. package/vendor/libarchive/libarchive/archive_entry.3 +147 -0
  73. package/vendor/libarchive/libarchive/archive_entry.c +2297 -0
  74. package/vendor/libarchive/libarchive/archive_entry.h +763 -0
  75. package/vendor/libarchive/libarchive/archive_entry_acl.3 +458 -0
  76. package/vendor/libarchive/libarchive/archive_entry_copy_bhfi.c +55 -0
  77. package/vendor/libarchive/libarchive/archive_entry_copy_stat.c +82 -0
  78. package/vendor/libarchive/libarchive/archive_entry_link_resolver.c +472 -0
  79. package/vendor/libarchive/libarchive/archive_entry_linkify.3 +224 -0
  80. package/vendor/libarchive/libarchive/archive_entry_locale.h +90 -0
  81. package/vendor/libarchive/libarchive/archive_entry_misc.3 +63 -0
  82. package/vendor/libarchive/libarchive/archive_entry_paths.3 +153 -0
  83. package/vendor/libarchive/libarchive/archive_entry_perms.3 +210 -0
  84. package/vendor/libarchive/libarchive/archive_entry_private.h +205 -0
  85. package/vendor/libarchive/libarchive/archive_entry_sparse.c +156 -0
  86. package/vendor/libarchive/libarchive/archive_entry_stat.3 +274 -0
  87. package/vendor/libarchive/libarchive/archive_entry_stat.c +121 -0
  88. package/vendor/libarchive/libarchive/archive_entry_strmode.c +69 -0
  89. package/vendor/libarchive/libarchive/archive_entry_time.3 +127 -0
  90. package/vendor/libarchive/libarchive/archive_entry_xattr.c +155 -0
  91. package/vendor/libarchive/libarchive/archive_hmac.c +345 -0
  92. package/vendor/libarchive/libarchive/archive_hmac_private.h +119 -0
  93. package/vendor/libarchive/libarchive/archive_integer.h +267 -0
  94. package/vendor/libarchive/libarchive/archive_match.c +1869 -0
  95. package/vendor/libarchive/libarchive/archive_openssl_evp_private.h +54 -0
  96. package/vendor/libarchive/libarchive/archive_openssl_hmac_private.h +54 -0
  97. package/vendor/libarchive/libarchive/archive_options.c +219 -0
  98. package/vendor/libarchive/libarchive/archive_options_private.h +49 -0
  99. package/vendor/libarchive/libarchive/archive_pack_dev.c +330 -0
  100. package/vendor/libarchive/libarchive/archive_pack_dev.h +49 -0
  101. package/vendor/libarchive/libarchive/archive_parse_date.c +1173 -0
  102. package/vendor/libarchive/libarchive/archive_pathmatch.c +480 -0
  103. package/vendor/libarchive/libarchive/archive_pathmatch.h +50 -0
  104. package/vendor/libarchive/libarchive/archive_platform.h +213 -0
  105. package/vendor/libarchive/libarchive/archive_platform_acl.h +53 -0
  106. package/vendor/libarchive/libarchive/archive_platform_stat.h +45 -0
  107. package/vendor/libarchive/libarchive/archive_platform_xattr.h +45 -0
  108. package/vendor/libarchive/libarchive/archive_ppmd7.c +1173 -0
  109. package/vendor/libarchive/libarchive/archive_ppmd7_private.h +119 -0
  110. package/vendor/libarchive/libarchive/archive_ppmd8.c +1293 -0
  111. package/vendor/libarchive/libarchive/archive_ppmd8_private.h +123 -0
  112. package/vendor/libarchive/libarchive/archive_ppmd_private.h +159 -0
  113. package/vendor/libarchive/libarchive/archive_private.h +209 -0
  114. package/vendor/libarchive/libarchive/archive_random.c +274 -0
  115. package/vendor/libarchive/libarchive/archive_random_private.h +36 -0
  116. package/vendor/libarchive/libarchive/archive_rb.c +709 -0
  117. package/vendor/libarchive/libarchive/archive_rb.h +113 -0
  118. package/vendor/libarchive/libarchive/archive_read.3 +250 -0
  119. package/vendor/libarchive/libarchive/archive_read.c +1814 -0
  120. package/vendor/libarchive/libarchive/archive_read_add_passphrase.3 +72 -0
  121. package/vendor/libarchive/libarchive/archive_read_add_passphrase.c +189 -0
  122. package/vendor/libarchive/libarchive/archive_read_append_filter.c +209 -0
  123. package/vendor/libarchive/libarchive/archive_read_data.3 +128 -0
  124. package/vendor/libarchive/libarchive/archive_read_data_into_fd.c +207 -0
  125. package/vendor/libarchive/libarchive/archive_read_disk.3 +422 -0
  126. package/vendor/libarchive/libarchive/archive_read_disk_entry_from_file.c +1086 -0
  127. package/vendor/libarchive/libarchive/archive_read_disk_posix.c +2639 -0
  128. package/vendor/libarchive/libarchive/archive_read_disk_private.h +97 -0
  129. package/vendor/libarchive/libarchive/archive_read_disk_set_standard_lookup.c +315 -0
  130. package/vendor/libarchive/libarchive/archive_read_disk_windows.c +2603 -0
  131. package/vendor/libarchive/libarchive/archive_read_extract.3 +135 -0
  132. package/vendor/libarchive/libarchive/archive_read_extract.c +59 -0
  133. package/vendor/libarchive/libarchive/archive_read_extract2.c +154 -0
  134. package/vendor/libarchive/libarchive/archive_read_filter.3 +163 -0
  135. package/vendor/libarchive/libarchive/archive_read_format.3 +190 -0
  136. package/vendor/libarchive/libarchive/archive_read_free.3 +91 -0
  137. package/vendor/libarchive/libarchive/archive_read_header.3 +89 -0
  138. package/vendor/libarchive/libarchive/archive_read_new.3 +57 -0
  139. package/vendor/libarchive/libarchive/archive_read_open.3 +247 -0
  140. package/vendor/libarchive/libarchive/archive_read_open_fd.c +236 -0
  141. package/vendor/libarchive/libarchive/archive_read_open_file.c +257 -0
  142. package/vendor/libarchive/libarchive/archive_read_open_filename.c +652 -0
  143. package/vendor/libarchive/libarchive/archive_read_open_memory.c +188 -0
  144. package/vendor/libarchive/libarchive/archive_read_private.h +274 -0
  145. package/vendor/libarchive/libarchive/archive_read_set_format.c +116 -0
  146. package/vendor/libarchive/libarchive/archive_read_set_options.3 +290 -0
  147. package/vendor/libarchive/libarchive/archive_read_set_options.c +132 -0
  148. package/vendor/libarchive/libarchive/archive_read_support_filter_all.c +84 -0
  149. package/vendor/libarchive/libarchive/archive_read_support_filter_by_code.c +68 -0
  150. package/vendor/libarchive/libarchive/archive_read_support_filter_bzip2.c +360 -0
  151. package/vendor/libarchive/libarchive/archive_read_support_filter_compress.c +457 -0
  152. package/vendor/libarchive/libarchive/archive_read_support_filter_grzip.c +108 -0
  153. package/vendor/libarchive/libarchive/archive_read_support_filter_gzip.c +538 -0
  154. package/vendor/libarchive/libarchive/archive_read_support_filter_lrzip.c +119 -0
  155. package/vendor/libarchive/libarchive/archive_read_support_filter_lz4.c +829 -0
  156. package/vendor/libarchive/libarchive/archive_read_support_filter_lzop.c +493 -0
  157. package/vendor/libarchive/libarchive/archive_read_support_filter_none.c +51 -0
  158. package/vendor/libarchive/libarchive/archive_read_support_filter_program.c +497 -0
  159. package/vendor/libarchive/libarchive/archive_read_support_filter_rpm.c +249 -0
  160. package/vendor/libarchive/libarchive/archive_read_support_filter_uu.c +739 -0
  161. package/vendor/libarchive/libarchive/archive_read_support_filter_xz.c +792 -0
  162. package/vendor/libarchive/libarchive/archive_read_support_filter_zstd.c +356 -0
  163. package/vendor/libarchive/libarchive/archive_read_support_format_7zip.c +4650 -0
  164. package/vendor/libarchive/libarchive/archive_read_support_format_all.c +88 -0
  165. package/vendor/libarchive/libarchive/archive_read_support_format_ar.c +597 -0
  166. package/vendor/libarchive/libarchive/archive_read_support_format_by_code.c +76 -0
  167. package/vendor/libarchive/libarchive/archive_read_support_format_cab.c +3410 -0
  168. package/vendor/libarchive/libarchive/archive_read_support_format_cpio.c +1152 -0
  169. package/vendor/libarchive/libarchive/archive_read_support_format_empty.c +95 -0
  170. package/vendor/libarchive/libarchive/archive_read_support_format_iso9660.c +3516 -0
  171. package/vendor/libarchive/libarchive/archive_read_support_format_lha.c +2931 -0
  172. package/vendor/libarchive/libarchive/archive_read_support_format_mtree.c +2113 -0
  173. package/vendor/libarchive/libarchive/archive_read_support_format_rar.c +3932 -0
  174. package/vendor/libarchive/libarchive/archive_read_support_format_rar5.c +4501 -0
  175. package/vendor/libarchive/libarchive/archive_read_support_format_raw.c +194 -0
  176. package/vendor/libarchive/libarchive/archive_read_support_format_tar.c +3785 -0
  177. package/vendor/libarchive/libarchive/archive_read_support_format_warc.c +875 -0
  178. package/vendor/libarchive/libarchive/archive_read_support_format_xar.c +3770 -0
  179. package/vendor/libarchive/libarchive/archive_read_support_format_zip.c +4710 -0
  180. package/vendor/libarchive/libarchive/archive_string.c +4391 -0
  181. package/vendor/libarchive/libarchive/archive_string.h +244 -0
  182. package/vendor/libarchive/libarchive/archive_string_composition.h +2289 -0
  183. package/vendor/libarchive/libarchive/archive_string_sprintf.c +200 -0
  184. package/vendor/libarchive/libarchive/archive_time.c +168 -0
  185. package/vendor/libarchive/libarchive/archive_time_private.h +47 -0
  186. package/vendor/libarchive/libarchive/archive_util.3 +239 -0
  187. package/vendor/libarchive/libarchive/archive_util.c +668 -0
  188. package/vendor/libarchive/libarchive/archive_version_details.c +516 -0
  189. package/vendor/libarchive/libarchive/archive_virtual.c +162 -0
  190. package/vendor/libarchive/libarchive/archive_windows.c +1035 -0
  191. package/vendor/libarchive/libarchive/archive_windows.h +332 -0
  192. package/vendor/libarchive/libarchive/archive_write.3 +266 -0
  193. package/vendor/libarchive/libarchive/archive_write.c +896 -0
  194. package/vendor/libarchive/libarchive/archive_write_add_filter.c +71 -0
  195. package/vendor/libarchive/libarchive/archive_write_add_filter_b64encode.c +329 -0
  196. package/vendor/libarchive/libarchive/archive_write_add_filter_by_name.c +76 -0
  197. package/vendor/libarchive/libarchive/archive_write_add_filter_bzip2.c +411 -0
  198. package/vendor/libarchive/libarchive/archive_write_add_filter_compress.c +459 -0
  199. package/vendor/libarchive/libarchive/archive_write_add_filter_grzip.c +143 -0
  200. package/vendor/libarchive/libarchive/archive_write_add_filter_gzip.c +493 -0
  201. package/vendor/libarchive/libarchive/archive_write_add_filter_lrzip.c +214 -0
  202. package/vendor/libarchive/libarchive/archive_write_add_filter_lz4.c +710 -0
  203. package/vendor/libarchive/libarchive/archive_write_add_filter_lzop.c +500 -0
  204. package/vendor/libarchive/libarchive/archive_write_add_filter_none.c +42 -0
  205. package/vendor/libarchive/libarchive/archive_write_add_filter_program.c +398 -0
  206. package/vendor/libarchive/libarchive/archive_write_add_filter_uuencode.c +320 -0
  207. package/vendor/libarchive/libarchive/archive_write_add_filter_xz.c +547 -0
  208. package/vendor/libarchive/libarchive/archive_write_add_filter_zstd.c +608 -0
  209. package/vendor/libarchive/libarchive/archive_write_blocksize.3 +112 -0
  210. package/vendor/libarchive/libarchive/archive_write_data.3 +88 -0
  211. package/vendor/libarchive/libarchive/archive_write_disk.3 +360 -0
  212. package/vendor/libarchive/libarchive/archive_write_disk_posix.c +4789 -0
  213. package/vendor/libarchive/libarchive/archive_write_disk_private.h +43 -0
  214. package/vendor/libarchive/libarchive/archive_write_disk_set_standard_lookup.c +265 -0
  215. package/vendor/libarchive/libarchive/archive_write_disk_windows.c +2952 -0
  216. package/vendor/libarchive/libarchive/archive_write_filter.3 +140 -0
  217. package/vendor/libarchive/libarchive/archive_write_finish_entry.3 +77 -0
  218. package/vendor/libarchive/libarchive/archive_write_format.3 +187 -0
  219. package/vendor/libarchive/libarchive/archive_write_free.3 +94 -0
  220. package/vendor/libarchive/libarchive/archive_write_header.3 +71 -0
  221. package/vendor/libarchive/libarchive/archive_write_new.3 +56 -0
  222. package/vendor/libarchive/libarchive/archive_write_open.3 +270 -0
  223. package/vendor/libarchive/libarchive/archive_write_open_fd.c +141 -0
  224. package/vendor/libarchive/libarchive/archive_write_open_file.c +102 -0
  225. package/vendor/libarchive/libarchive/archive_write_open_filename.c +272 -0
  226. package/vendor/libarchive/libarchive/archive_write_open_memory.c +110 -0
  227. package/vendor/libarchive/libarchive/archive_write_private.h +166 -0
  228. package/vendor/libarchive/libarchive/archive_write_set_format.c +124 -0
  229. package/vendor/libarchive/libarchive/archive_write_set_format_7zip.c +2571 -0
  230. package/vendor/libarchive/libarchive/archive_write_set_format_ar.c +540 -0
  231. package/vendor/libarchive/libarchive/archive_write_set_format_by_name.c +93 -0
  232. package/vendor/libarchive/libarchive/archive_write_set_format_cpio.c +11 -0
  233. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_binary.c +618 -0
  234. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_newc.c +457 -0
  235. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_odc.c +508 -0
  236. package/vendor/libarchive/libarchive/archive_write_set_format_filter_by_ext.c +141 -0
  237. package/vendor/libarchive/libarchive/archive_write_set_format_gnutar.c +790 -0
  238. package/vendor/libarchive/libarchive/archive_write_set_format_iso9660.c +8216 -0
  239. package/vendor/libarchive/libarchive/archive_write_set_format_mtree.c +2307 -0
  240. package/vendor/libarchive/libarchive/archive_write_set_format_pax.c +2249 -0
  241. package/vendor/libarchive/libarchive/archive_write_set_format_private.h +40 -0
  242. package/vendor/libarchive/libarchive/archive_write_set_format_raw.c +123 -0
  243. package/vendor/libarchive/libarchive/archive_write_set_format_shar.c +650 -0
  244. package/vendor/libarchive/libarchive/archive_write_set_format_ustar.c +768 -0
  245. package/vendor/libarchive/libarchive/archive_write_set_format_v7tar.c +648 -0
  246. package/vendor/libarchive/libarchive/archive_write_set_format_warc.c +491 -0
  247. package/vendor/libarchive/libarchive/archive_write_set_format_xar.c +3799 -0
  248. package/vendor/libarchive/libarchive/archive_write_set_format_zip.c +2548 -0
  249. package/vendor/libarchive/libarchive/archive_write_set_options.3 +779 -0
  250. package/vendor/libarchive/libarchive/archive_write_set_options.c +129 -0
  251. package/vendor/libarchive/libarchive/archive_write_set_passphrase.3 +72 -0
  252. package/vendor/libarchive/libarchive/archive_write_set_passphrase.c +95 -0
  253. package/vendor/libarchive/libarchive/archive_xxhash.h +48 -0
  254. package/vendor/libarchive/libarchive/config_freebsd.h +275 -0
  255. package/vendor/libarchive/libarchive/cpio.5 +389 -0
  256. package/vendor/libarchive/libarchive/filter_fork.h +44 -0
  257. package/vendor/libarchive/libarchive/filter_fork_posix.c +269 -0
  258. package/vendor/libarchive/libarchive/filter_fork_windows.c +270 -0
  259. package/vendor/libarchive/libarchive/libarchive-formats.5 +478 -0
  260. package/vendor/libarchive/libarchive/libarchive.3 +297 -0
  261. package/vendor/libarchive/libarchive/libarchive_changes.3 +339 -0
  262. package/vendor/libarchive/libarchive/libarchive_internals.3 +363 -0
  263. package/vendor/libarchive/libarchive/module.modulemap +34 -0
  264. package/vendor/libarchive/libarchive/mtree.5 +323 -0
  265. package/vendor/libarchive/libarchive/tar.5 +947 -0
  266. package/vendor/libarchive/libarchive/xxhash.c +531 -0
@@ -0,0 +1,652 @@
1
+ /*-
2
+ * Copyright (c) 2003-2010 Tim Kientzle
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions
7
+ * are met:
8
+ * 1. Redistributions of source code must retain the above copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright
11
+ * notice, this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ *
14
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
+ */
25
+
26
+ #include "archive_platform.h"
27
+
28
+ #ifdef HAVE_SYS_IOCTL_H
29
+ #include <sys/ioctl.h>
30
+ #endif
31
+ #ifdef HAVE_SYS_STAT_H
32
+ #include <sys/stat.h>
33
+ #endif
34
+ #ifdef HAVE_ERRNO_H
35
+ #include <errno.h>
36
+ #endif
37
+ #ifdef HAVE_FCNTL_H
38
+ #include <fcntl.h>
39
+ #endif
40
+ #ifdef HAVE_IO_H
41
+ #include <io.h>
42
+ #endif
43
+ #ifdef HAVE_LIMITS_H
44
+ #include <limits.h>
45
+ #endif
46
+ #ifdef HAVE_STDLIB_H
47
+ #include <stdlib.h>
48
+ #endif
49
+ #ifdef HAVE_STRING_H
50
+ #include <string.h>
51
+ #endif
52
+ #ifdef HAVE_UNISTD_H
53
+ #include <unistd.h>
54
+ #endif
55
+ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
56
+ #include <sys/disk.h>
57
+ #elif defined(__NetBSD__) || defined(__OpenBSD__)
58
+ #include <sys/disklabel.h>
59
+ #include <sys/dkio.h>
60
+ #elif defined(__DragonFly__)
61
+ #include <sys/diskslice.h>
62
+ #endif
63
+
64
+ #include "archive.h"
65
+ #include "archive_platform_stat.h"
66
+ #include "archive_private.h"
67
+ #include "archive_string.h"
68
+
69
+ #ifndef O_BINARY
70
+ #define O_BINARY 0
71
+ #endif
72
+ #ifndef O_CLOEXEC
73
+ #define O_CLOEXEC 0
74
+ #endif
75
+
76
+ struct read_file_data {
77
+ int fd;
78
+ size_t block_size;
79
+ void *buffer;
80
+ mode_t st_mode; /* Mode bits for opened file. */
81
+ int64_t size;
82
+ char use_lseek;
83
+ enum fnt_e { FNT_STDIN, FNT_MBS, FNT_WCS } filename_type;
84
+ union {
85
+ char m[1];/* MBS filename. */
86
+ wchar_t w[1];/* WCS filename. */
87
+ } filename; /* Must be last! */
88
+ };
89
+
90
+ static int file_open(struct archive *, void *);
91
+ static int file_close(struct archive *, void *);
92
+ static int file_close2(struct archive *, void *);
93
+ static int file_switch(struct archive *, void *, void *);
94
+ static ssize_t file_read(struct archive *, void *, const void **buff);
95
+ static int64_t file_seek(struct archive *, void *, int64_t request, int);
96
+ static int64_t file_skip(struct archive *, void *, int64_t request);
97
+ static int64_t file_skip_lseek(struct archive *, void *, int64_t request);
98
+
99
+ int
100
+ archive_read_open_file(struct archive *a, const char *filename,
101
+ size_t block_size)
102
+ {
103
+ return (archive_read_open_filename(a, filename, block_size));
104
+ }
105
+
106
+ int
107
+ archive_read_open_filename(struct archive *a, const char *filename,
108
+ size_t block_size)
109
+ {
110
+ const char *filenames[2];
111
+ filenames[0] = filename;
112
+ filenames[1] = NULL;
113
+ return archive_read_open_filenames(a, filenames, block_size);
114
+ }
115
+
116
+ int
117
+ archive_read_open_filenames(struct archive *a, const char **filenames,
118
+ size_t block_size)
119
+ {
120
+ struct read_file_data *mine;
121
+ const char *filename = NULL;
122
+ if (filenames)
123
+ filename = *(filenames++);
124
+
125
+ archive_clear_error(a);
126
+ do
127
+ {
128
+ size_t len;
129
+ if (filename == NULL)
130
+ filename = "";
131
+ len = strlen(filename);
132
+ mine = calloc(1, sizeof(*mine) + len);
133
+ if (mine == NULL)
134
+ goto no_memory;
135
+ memcpy(mine->filename.m, filename, len + 1);
136
+ mine->block_size = block_size;
137
+ mine->fd = -1;
138
+ mine->buffer = NULL;
139
+ mine->st_mode = mine->use_lseek = 0;
140
+ if (filename == NULL || filename[0] == '\0') {
141
+ mine->filename_type = FNT_STDIN;
142
+ } else
143
+ mine->filename_type = FNT_MBS;
144
+ if (archive_read_append_callback_data(a, mine) != (ARCHIVE_OK)) {
145
+ free(mine);
146
+ return (ARCHIVE_FATAL);
147
+ }
148
+ if (filenames == NULL)
149
+ break;
150
+ filename = *(filenames++);
151
+ } while (filename != NULL && filename[0] != '\0');
152
+ archive_read_set_open_callback(a, file_open);
153
+ archive_read_set_read_callback(a, file_read);
154
+ archive_read_set_skip_callback(a, file_skip);
155
+ archive_read_set_close_callback(a, file_close);
156
+ archive_read_set_switch_callback(a, file_switch);
157
+ archive_read_set_seek_callback(a, file_seek);
158
+
159
+ return (archive_read_open1(a));
160
+ no_memory:
161
+ archive_set_error(a, ENOMEM, "No memory");
162
+ return (ARCHIVE_FATAL);
163
+ }
164
+
165
+ /*
166
+ * This function is an implementation detail of archive_read_open_filename_w,
167
+ * which is exposed as a separate API on Windows.
168
+ */
169
+ #if !defined(_WIN32) || defined(__CYGWIN__)
170
+ static
171
+ #endif
172
+ int
173
+ archive_read_open_filenames_w(struct archive *a, const wchar_t **wfilenames,
174
+ size_t block_size)
175
+ {
176
+ struct read_file_data *mine;
177
+ const wchar_t *wfilename = NULL;
178
+ if (wfilenames)
179
+ wfilename = *(wfilenames++);
180
+
181
+ archive_clear_error(a);
182
+ do
183
+ {
184
+ if (wfilename == NULL)
185
+ wfilename = L"";
186
+ mine = calloc(1,
187
+ sizeof(*mine) + wcslen(wfilename) * MB_LEN_MAX);
188
+ if (mine == NULL)
189
+ goto no_memory;
190
+ mine->block_size = block_size;
191
+ mine->fd = -1;
192
+
193
+ if (wfilename == NULL || wfilename[0] == L'\0') {
194
+ mine->filename_type = FNT_STDIN;
195
+ } else {
196
+ #if defined(_WIN32) && !defined(__CYGWIN__)
197
+ mine->filename_type = FNT_WCS;
198
+ wcscpy(mine->filename.w, wfilename);
199
+ #else
200
+ /*
201
+ * POSIX system does not support a wchar_t interface for
202
+ * open() system call, so we have to translate a wchar_t
203
+ * filename to multi-byte one and use it.
204
+ */
205
+ struct archive_string fn;
206
+
207
+ archive_string_init(&fn);
208
+ if (archive_string_append_from_wcs(&fn, wfilename,
209
+ wcslen(wfilename)) != 0) {
210
+ if (errno == ENOMEM)
211
+ archive_set_error(a, errno,
212
+ "Can't allocate memory");
213
+ else
214
+ archive_set_error(a, EINVAL,
215
+ "Failed to convert a wide-character"
216
+ " filename to a multi-byte filename");
217
+ archive_string_free(&fn);
218
+ free(mine);
219
+ return (ARCHIVE_FATAL);
220
+ }
221
+ mine->filename_type = FNT_MBS;
222
+ strcpy(mine->filename.m, fn.s);
223
+ archive_string_free(&fn);
224
+ #endif
225
+ }
226
+ if (archive_read_append_callback_data(a, mine) != (ARCHIVE_OK)) {
227
+ free(mine);
228
+ return (ARCHIVE_FATAL);
229
+ }
230
+ if (wfilenames == NULL)
231
+ break;
232
+ wfilename = *(wfilenames++);
233
+ } while (wfilename != NULL && wfilename[0] != '\0');
234
+ archive_read_set_open_callback(a, file_open);
235
+ archive_read_set_read_callback(a, file_read);
236
+ archive_read_set_skip_callback(a, file_skip);
237
+ archive_read_set_close_callback(a, file_close);
238
+ archive_read_set_switch_callback(a, file_switch);
239
+ archive_read_set_seek_callback(a, file_seek);
240
+
241
+ return (archive_read_open1(a));
242
+ no_memory:
243
+ archive_set_error(a, ENOMEM, "No memory");
244
+ return (ARCHIVE_FATAL);
245
+ }
246
+
247
+ int
248
+ archive_read_open_filename_w(struct archive *a, const wchar_t *wfilename,
249
+ size_t block_size)
250
+ {
251
+ const wchar_t *wfilenames[2];
252
+ wfilenames[0] = wfilename;
253
+ wfilenames[1] = NULL;
254
+ return archive_read_open_filenames_w(a, wfilenames, block_size);
255
+ }
256
+
257
+ static int
258
+ file_open(struct archive *a, void *client_data)
259
+ {
260
+ la_seek_stat_t st;
261
+ struct read_file_data *mine = (struct read_file_data *)client_data;
262
+ void *buffer;
263
+ const char *filename = NULL;
264
+ #if defined(_WIN32) && !defined(__CYGWIN__)
265
+ const wchar_t *wfilename = NULL;
266
+ #endif
267
+ int fd = -1;
268
+ int is_disk_like = 0;
269
+ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
270
+ off_t mediasize = 0; /* FreeBSD-specific, so off_t okay here. */
271
+ #elif defined(__NetBSD__) || defined(__OpenBSD__)
272
+ struct disklabel dl;
273
+ #elif defined(__DragonFly__)
274
+ struct partinfo pi;
275
+ #endif
276
+
277
+ archive_clear_error(a);
278
+ if (mine->filename_type == FNT_STDIN) {
279
+ /* We used to delegate stdin support by
280
+ * directly calling archive_read_open_fd(a,0,block_size)
281
+ * here, but that doesn't (and shouldn't) handle the
282
+ * end-of-file flush when reading stdout from a pipe.
283
+ * Basically, read_open_fd() is intended for folks who
284
+ * are willing to handle such details themselves. This
285
+ * API is intended to be a little smarter for folks who
286
+ * want easy handling of the common case.
287
+ */
288
+ fd = 0;
289
+ #if defined(__CYGWIN__) || defined(_WIN32)
290
+ setmode(0, O_BINARY);
291
+ #endif
292
+ filename = "";
293
+ } else if (mine->filename_type == FNT_MBS) {
294
+ filename = mine->filename.m;
295
+ fd = open(filename, O_RDONLY | O_BINARY | O_CLOEXEC);
296
+ __archive_ensure_cloexec_flag(fd);
297
+ if (fd < 0) {
298
+ archive_set_error(a, errno,
299
+ "Failed to open '%s'", filename);
300
+ return (ARCHIVE_FATAL);
301
+ }
302
+ } else {
303
+ #if defined(_WIN32) && !defined(__CYGWIN__)
304
+ wfilename = mine->filename.w;
305
+ fd = _wopen(wfilename, O_RDONLY | O_BINARY);
306
+ if (fd < 0 && errno == ENOENT) {
307
+ wchar_t *fullpath;
308
+ fullpath = __la_win_permissive_name_w(wfilename);
309
+ if (fullpath != NULL) {
310
+ fd = _wopen(fullpath, O_RDONLY | O_BINARY);
311
+ free(fullpath);
312
+ }
313
+ }
314
+ if (fd < 0) {
315
+ archive_set_error(a, errno,
316
+ "Failed to open '%ls'", wfilename);
317
+ return (ARCHIVE_FATAL);
318
+ }
319
+ #else
320
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
321
+ "Unexpected operation in archive_read_open_filename");
322
+ goto fail;
323
+ #endif
324
+ }
325
+ if (la_seek_fstat(fd, &st) != 0) {
326
+ #if defined(_WIN32) && !defined(__CYGWIN__)
327
+ if (mine->filename_type == FNT_WCS)
328
+ archive_set_error(a, errno, "Can't stat '%ls'",
329
+ wfilename);
330
+ else
331
+ #endif
332
+ archive_set_error(a, errno, "Can't stat '%s'",
333
+ filename);
334
+ goto fail;
335
+ }
336
+
337
+ /*
338
+ * Determine whether the input looks like a disk device or a
339
+ * tape device. The results are used below to select an I/O
340
+ * strategy:
341
+ * = "disk-like" devices support arbitrary lseek() and will
342
+ * support I/O requests of any size. So we get easy skipping
343
+ * and can cheat on block sizes to get better performance.
344
+ * = "tape-like" devices require strict blocking and use
345
+ * specialized ioctls for seeking.
346
+ * = "socket-like" devices cannot seek at all but can improve
347
+ * performance by using nonblocking I/O to read "whatever is
348
+ * available right now".
349
+ *
350
+ * Right now, we only specially recognize disk-like devices,
351
+ * but it should be straightforward to add probes and strategy
352
+ * here for tape-like and socket-like devices.
353
+ */
354
+ if (S_ISREG(st.st_mode)) {
355
+ /* Safety: Tell the extractor not to overwrite the input. */
356
+ archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino);
357
+ /* Regular files act like disks. */
358
+ is_disk_like = 1;
359
+ }
360
+ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
361
+ /* FreeBSD: if it supports DIOCGMEDIASIZE ioctl, it's disk-like. */
362
+ else if (S_ISCHR(st.st_mode) &&
363
+ ioctl(fd, DIOCGMEDIASIZE, &mediasize) == 0 &&
364
+ mediasize > 0) {
365
+ is_disk_like = 1;
366
+ }
367
+ #elif defined(__NetBSD__) || defined(__OpenBSD__)
368
+ /* Net/OpenBSD: if it supports DIOCGDINFO ioctl, it's disk-like. */
369
+ else if ((S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) &&
370
+ ioctl(fd, DIOCGDINFO, &dl) == 0 &&
371
+ dl.d_partitions[DISKPART(st.st_rdev)].p_size > 0) {
372
+ is_disk_like = 1;
373
+ }
374
+ #elif defined(__DragonFly__)
375
+ /* DragonFly BSD: if it supports DIOCGPART ioctl, it's disk-like. */
376
+ else if (S_ISCHR(st.st_mode) &&
377
+ ioctl(fd, DIOCGPART, &pi) == 0 &&
378
+ pi.media_size > 0) {
379
+ is_disk_like = 1;
380
+ }
381
+ #elif defined(__linux__)
382
+ /* Linux: All block devices are disk-like. */
383
+ else if (S_ISBLK(st.st_mode) &&
384
+ lseek(fd, 0, SEEK_CUR) == 0 &&
385
+ lseek(fd, 0, SEEK_SET) == 0 &&
386
+ lseek(fd, 0, SEEK_END) > 0 &&
387
+ lseek(fd, 0, SEEK_SET) == 0) {
388
+ is_disk_like = 1;
389
+ }
390
+ #endif
391
+ /* TODO: Add an "is_tape_like" variable and appropriate tests. */
392
+
393
+ /* Disk-like devices prefer power-of-two block sizes. */
394
+ /* Use provided block_size as a guide so users have some control. */
395
+ if (is_disk_like) {
396
+ size_t new_block_size = 64 * 1024;
397
+ while (new_block_size < mine->block_size
398
+ && new_block_size < 64 * 1024 * 1024)
399
+ new_block_size *= 2;
400
+ mine->block_size = new_block_size;
401
+ }
402
+ buffer = malloc(mine->block_size);
403
+ if (buffer == NULL) {
404
+ archive_set_error(a, ENOMEM, "No memory");
405
+ goto fail;
406
+ }
407
+ mine->buffer = buffer;
408
+ mine->fd = fd;
409
+ /* Remember mode so close can decide whether to flush. */
410
+ mine->st_mode = st.st_mode;
411
+
412
+ /* Disk-like inputs can use lseek(). */
413
+ if (is_disk_like) {
414
+ mine->use_lseek = 1;
415
+ mine->size = st.st_size;
416
+ }
417
+
418
+ return (ARCHIVE_OK);
419
+ fail:
420
+ /*
421
+ * Don't close file descriptors not opened or ones pointing referring
422
+ * to `FNT_STDIN`.
423
+ */
424
+ if (fd != -1 && fd != 0)
425
+ close(fd);
426
+ return (ARCHIVE_FATAL);
427
+ }
428
+
429
+ static ssize_t
430
+ file_read(struct archive *a, void *client_data, const void **buff)
431
+ {
432
+ struct read_file_data *mine = (struct read_file_data *)client_data;
433
+ ssize_t bytes_read;
434
+
435
+ /* TODO: If a recent lseek() operation has left us
436
+ * mis-aligned, read and return a short block to try to get
437
+ * us back in alignment. */
438
+
439
+ /* TODO: Someday, try mmap() here; if that succeeds, give
440
+ * the entire file to libarchive as a single block. That
441
+ * could be a lot faster than block-by-block manual I/O. */
442
+
443
+ /* TODO: We might be able to improve performance on pipes and
444
+ * sockets by setting non-blocking I/O and just accepting
445
+ * whatever we get here instead of waiting for a full block
446
+ * worth of data. */
447
+
448
+ *buff = mine->buffer;
449
+ for (;;) {
450
+ bytes_read = read(mine->fd, mine->buffer, mine->block_size);
451
+ if (bytes_read < 0) {
452
+ if (errno == EINTR)
453
+ continue;
454
+ else if (mine->filename_type == FNT_STDIN)
455
+ archive_set_error(a, errno,
456
+ "Error reading stdin");
457
+ else if (mine->filename_type == FNT_MBS)
458
+ archive_set_error(a, errno,
459
+ "Error reading '%s'", mine->filename.m);
460
+ else
461
+ archive_set_error(a, errno,
462
+ "Error reading '%ls'", mine->filename.w);
463
+ }
464
+ return (bytes_read);
465
+ }
466
+ }
467
+
468
+ /*
469
+ * Regular files and disk-like block devices can use simple lseek
470
+ * without needing to round the request to the block size.
471
+ *
472
+ * TODO: This can leave future reads mis-aligned. Since we know the
473
+ * offset here, we should store it and use it in file_read() above
474
+ * to determine whether we should perform a short read to get back
475
+ * into alignment. Long series of mis-aligned reads can negatively
476
+ * impact disk throughput. (Of course, the performance impact should
477
+ * be carefully tested; extra code complexity is only worthwhile if
478
+ * it does provide measurable improvement.)
479
+ *
480
+ * TODO: Be lazy about the actual seek. There are a few pathological
481
+ * cases where libarchive makes a bunch of seek requests in a row
482
+ * without any intervening reads. This isn't a huge performance
483
+ * problem, since the kernel handles seeks lazily already, but
484
+ * it would be very slightly faster if we simply remembered the
485
+ * seek request here and then actually performed the seek at the
486
+ * top of the read callback above.
487
+ */
488
+ static int64_t
489
+ file_skip_lseek(struct archive *a, void *client_data, int64_t request)
490
+ {
491
+ struct read_file_data *mine = (struct read_file_data *)client_data;
492
+ #if defined(_WIN32) && !defined(__CYGWIN__)
493
+ /* We use _lseeki64() on Windows. */
494
+ int64_t old_offset, new_offset;
495
+ #else
496
+ off_t old_offset, new_offset;
497
+ #endif
498
+ la_seek_t skip = (la_seek_t)request;
499
+ int skip_bits = sizeof(skip) * 8 - 1;
500
+
501
+ /* We use off_t here because lseek() is declared that way. */
502
+
503
+ /* Reduce a request that would overflow the 'skip' variable. */
504
+ if (sizeof(request) > sizeof(skip)) {
505
+ const int64_t max_skip =
506
+ (((int64_t)1 << (skip_bits - 1)) - 1) * 2 + 1;
507
+ if (request > max_skip)
508
+ skip = max_skip;
509
+ }
510
+
511
+ if ((old_offset = lseek(mine->fd, 0, SEEK_CUR)) >= 0) {
512
+ if (old_offset >= mine->size ||
513
+ skip > mine->size - old_offset) {
514
+ /* Do not seek past end of file. */
515
+ errno = ESPIPE;
516
+ } else if ((new_offset = lseek(mine->fd, skip, SEEK_CUR)) >= 0)
517
+ return (new_offset - old_offset);
518
+ }
519
+
520
+ /* If lseek() fails, don't bother trying again. */
521
+ mine->use_lseek = 0;
522
+
523
+ /* Let libarchive recover with read+discard */
524
+ if (errno == ESPIPE)
525
+ return (0);
526
+
527
+ /* If the input is corrupted or truncated, fail. */
528
+ if (mine->filename_type == FNT_STDIN)
529
+ archive_set_error(a, errno, "Error seeking in stdin");
530
+ else if (mine->filename_type == FNT_MBS)
531
+ archive_set_error(a, errno, "Error seeking in '%s'",
532
+ mine->filename.m);
533
+ else
534
+ archive_set_error(a, errno, "Error seeking in '%ls'",
535
+ mine->filename.w);
536
+ return (-1);
537
+ }
538
+
539
+
540
+ /*
541
+ * TODO: Implement another file_skip_XXXX that uses MTIO ioctls to
542
+ * accelerate operation on tape drives.
543
+ */
544
+
545
+ static int64_t
546
+ file_skip(struct archive *a, void *client_data, int64_t request)
547
+ {
548
+ struct read_file_data *mine = (struct read_file_data *)client_data;
549
+
550
+ /* Delegate skip requests. */
551
+ if (mine->use_lseek)
552
+ return (file_skip_lseek(a, client_data, request));
553
+
554
+ /* If we can't skip, return 0; libarchive will read+discard instead. */
555
+ return (0);
556
+ }
557
+
558
+ /*
559
+ * TODO: Store the offset and use it in the read callback.
560
+ */
561
+ static int64_t
562
+ file_seek(struct archive *a, void *client_data, int64_t request, int whence)
563
+ {
564
+ struct read_file_data *mine = (struct read_file_data *)client_data;
565
+ la_seek_t seek = (la_seek_t)request;
566
+ int64_t r;
567
+ int seek_bits = sizeof(seek) * 8 - 1;
568
+
569
+ /* We use off_t here because lseek() is declared that way. */
570
+
571
+ /* Do not perform a seek which cannot be fulfilled. */
572
+ if (sizeof(request) > sizeof(seek)) {
573
+ const int64_t max_seek =
574
+ (((int64_t)1 << (seek_bits - 1)) - 1) * 2 + 1;
575
+ const int64_t min_seek = ~max_seek;
576
+ if (request < min_seek || request > max_seek) {
577
+ errno = EOVERFLOW;
578
+ goto err;
579
+ }
580
+ }
581
+
582
+ r = lseek(mine->fd, seek, whence);
583
+ if (r >= 0)
584
+ return r;
585
+
586
+ /* If the input is corrupted or truncated, fail. */
587
+ err:
588
+ if (mine->filename_type == FNT_STDIN)
589
+ archive_set_error(a, errno, "Error seeking in stdin");
590
+ else if (mine->filename_type == FNT_MBS)
591
+ archive_set_error(a, errno, "Error seeking in '%s'",
592
+ mine->filename.m);
593
+ else
594
+ archive_set_error(a, errno, "Error seeking in '%ls'",
595
+ mine->filename.w);
596
+ return (ARCHIVE_FATAL);
597
+ }
598
+
599
+ static int
600
+ file_close2(struct archive *a, void *client_data)
601
+ {
602
+ struct read_file_data *mine = (struct read_file_data *)client_data;
603
+
604
+ (void)a; /* UNUSED */
605
+
606
+ /* Only flush and close if open succeeded. */
607
+ if (mine->fd >= 0) {
608
+ /*
609
+ * Sometimes, we should flush the input before closing.
610
+ * Regular files: faster to just close without flush.
611
+ * Disk-like devices: Ditto.
612
+ * Tapes: must not flush (user might need to
613
+ * read the "next" item on a non-rewind device).
614
+ * Pipes and sockets: must flush (otherwise, the
615
+ * program feeding the pipe or socket may complain).
616
+ * Here, I flush everything except for regular files and
617
+ * device nodes.
618
+ */
619
+ if (!S_ISREG(mine->st_mode)
620
+ && !S_ISCHR(mine->st_mode)
621
+ && !S_ISBLK(mine->st_mode)) {
622
+ ssize_t bytesRead;
623
+ do {
624
+ bytesRead = read(mine->fd, mine->buffer,
625
+ mine->block_size);
626
+ } while (bytesRead > 0);
627
+ }
628
+ /* If a named file was opened, then it needs to be closed. */
629
+ if (mine->filename_type != FNT_STDIN)
630
+ close(mine->fd);
631
+ }
632
+ free(mine->buffer);
633
+ mine->buffer = NULL;
634
+ mine->fd = -1;
635
+ return (ARCHIVE_OK);
636
+ }
637
+
638
+ static int
639
+ file_close(struct archive *a, void *client_data)
640
+ {
641
+ struct read_file_data *mine = (struct read_file_data *)client_data;
642
+ file_close2(a, client_data);
643
+ free(mine);
644
+ return (ARCHIVE_OK);
645
+ }
646
+
647
+ static int
648
+ file_switch(struct archive *a, void *client_data1, void *client_data2)
649
+ {
650
+ file_close2(a, client_data1);
651
+ return file_open(a, client_data2);
652
+ }