@papyrus-sdk/engine-native 0.2.22-beta.9.epub.2 → 0.2.23

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 (276) hide show
  1. package/PapyrusNativeEngine.podspec +45 -0
  2. package/android/build.gradle +1 -0
  3. package/android/src/main/cpp/CMakeLists.txt +137 -0
  4. package/android/src/main/cpp/PapyrusComicArchiveJni.cpp +68 -0
  5. package/android/src/main/cpp/PapyrusComicArchiveTest.cpp +55 -0
  6. package/android/src/main/cpp/papyrus_outline_loader_test.cpp +240 -0
  7. package/android/src/main/cpp/papyrus_text_word_test.cpp +72 -0
  8. package/android/src/main/java/com/papyrus/engine/PapyrusComicArchiveNative.java +14 -0
  9. package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentView.java +491 -0
  10. package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentViewManager.java +32 -0
  11. package/android/src/main/java/com/papyrus/engine/PapyrusComicPageLayout.java +38 -0
  12. package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +305 -35
  13. package/android/src/main/java/com/papyrus/engine/PapyrusNativeTextModel.java +195 -0
  14. package/android/src/main/java/com/papyrus/engine/PapyrusPackage.java +3 -1
  15. package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerView.java +195 -5
  16. package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerViewManager.java +20 -1
  17. package/android/src/main/java/com/papyrus/engine/PapyrusSelectionMenuIcon.java +48 -0
  18. package/android/src/main/java/com/papyrus/engine/PapyrusTextAnnotationModel.java +22 -0
  19. package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentView.java +661 -0
  20. package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentViewManager.java +49 -0
  21. package/android/src/main/java/com/papyrus/engine/PapyrusTextStore.java +43 -0
  22. package/dist/index.d.mts +614 -4
  23. package/dist/index.d.ts +614 -4
  24. package/dist/index.js +484 -8
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.mjs +477 -7
  27. package/dist/index.mjs.map +1 -1
  28. package/ios/PapyrusComicDocumentView.h +21 -0
  29. package/ios/PapyrusComicDocumentView.m +554 -0
  30. package/ios/PapyrusComicDocumentViewManager.m +23 -0
  31. package/ios/PapyrusEngineStore.h +3 -0
  32. package/ios/PapyrusEngineStore.m +32 -6
  33. package/ios/PapyrusNativeEngine.m +684 -5
  34. package/ios/PapyrusPageRotationRegistry.h +29 -0
  35. package/ios/PapyrusPageRotationRegistry.m +179 -0
  36. package/ios/PapyrusPageView.m +38 -11
  37. package/ios/PapyrusPdfDocumentView.h +55 -0
  38. package/ios/PapyrusPdfDocumentView.m +2370 -0
  39. package/ios/PapyrusPdfDocumentViewManager.m +61 -0
  40. package/ios/PapyrusPdfPageTheme.h +15 -0
  41. package/ios/PapyrusPdfPageTheme.m +218 -0
  42. package/ios/PapyrusSelectionMenu.h +27 -0
  43. package/ios/PapyrusTextAnnotationRange.h +2 -0
  44. package/ios/PapyrusTextAnnotationRange.m +29 -0
  45. package/ios/PapyrusTextDocumentView.h +32 -0
  46. package/ios/PapyrusTextDocumentView.m +518 -0
  47. package/ios/PapyrusTextDocumentViewManager.m +34 -0
  48. package/ios/PapyrusTextStore.h +13 -0
  49. package/ios/PapyrusTextStore.m +73 -0
  50. package/package.json +12 -10
  51. package/react-native.config.js +1 -1
  52. package/third_party_licenses/BLAKE2-NOTICE.txt +11 -0
  53. package/third_party_licenses/libarchive-COPYING +65 -0
  54. package/vendor/libarchive/PapyrusComicArchive.cpp +376 -0
  55. package/vendor/libarchive/PapyrusComicArchive.h +30 -0
  56. package/vendor/libarchive/README.papyrus.md +15 -0
  57. package/vendor/libarchive/android.h +192 -0
  58. package/vendor/libarchive/config/PapyrusArchiveConfig.h +71 -0
  59. package/vendor/libarchive/libarchive/CMakeLists.txt +293 -0
  60. package/vendor/libarchive/libarchive/android_lf.h +36 -0
  61. package/vendor/libarchive/libarchive/archive.h +1266 -0
  62. package/vendor/libarchive/libarchive/archive_acl.c +2025 -0
  63. package/vendor/libarchive/libarchive/archive_acl_private.h +85 -0
  64. package/vendor/libarchive/libarchive/archive_blake2.h +197 -0
  65. package/vendor/libarchive/libarchive/archive_blake2_impl.h +161 -0
  66. package/vendor/libarchive/libarchive/archive_blake2s_ref.c +369 -0
  67. package/vendor/libarchive/libarchive/archive_blake2sp_ref.c +361 -0
  68. package/vendor/libarchive/libarchive/archive_check_magic.c +183 -0
  69. package/vendor/libarchive/libarchive/archive_cmdline.c +211 -0
  70. package/vendor/libarchive/libarchive/archive_cmdline_private.h +45 -0
  71. package/vendor/libarchive/libarchive/archive_crc32.h +123 -0
  72. package/vendor/libarchive/libarchive/archive_cryptor.c +534 -0
  73. package/vendor/libarchive/libarchive/archive_cryptor_private.h +199 -0
  74. package/vendor/libarchive/libarchive/archive_digest.c +1584 -0
  75. package/vendor/libarchive/libarchive/archive_digest_private.h +431 -0
  76. package/vendor/libarchive/libarchive/archive_disk_acl_darwin.c +558 -0
  77. package/vendor/libarchive/libarchive/archive_disk_acl_freebsd.c +712 -0
  78. package/vendor/libarchive/libarchive/archive_disk_acl_linux.c +760 -0
  79. package/vendor/libarchive/libarchive/archive_disk_acl_sunos.c +824 -0
  80. package/vendor/libarchive/libarchive/archive_endian.h +234 -0
  81. package/vendor/libarchive/libarchive/archive_entry.3 +147 -0
  82. package/vendor/libarchive/libarchive/archive_entry.c +2297 -0
  83. package/vendor/libarchive/libarchive/archive_entry.h +763 -0
  84. package/vendor/libarchive/libarchive/archive_entry_acl.3 +458 -0
  85. package/vendor/libarchive/libarchive/archive_entry_copy_bhfi.c +55 -0
  86. package/vendor/libarchive/libarchive/archive_entry_copy_stat.c +82 -0
  87. package/vendor/libarchive/libarchive/archive_entry_link_resolver.c +472 -0
  88. package/vendor/libarchive/libarchive/archive_entry_linkify.3 +224 -0
  89. package/vendor/libarchive/libarchive/archive_entry_locale.h +90 -0
  90. package/vendor/libarchive/libarchive/archive_entry_misc.3 +63 -0
  91. package/vendor/libarchive/libarchive/archive_entry_paths.3 +153 -0
  92. package/vendor/libarchive/libarchive/archive_entry_perms.3 +210 -0
  93. package/vendor/libarchive/libarchive/archive_entry_private.h +205 -0
  94. package/vendor/libarchive/libarchive/archive_entry_sparse.c +156 -0
  95. package/vendor/libarchive/libarchive/archive_entry_stat.3 +274 -0
  96. package/vendor/libarchive/libarchive/archive_entry_stat.c +121 -0
  97. package/vendor/libarchive/libarchive/archive_entry_strmode.c +69 -0
  98. package/vendor/libarchive/libarchive/archive_entry_time.3 +127 -0
  99. package/vendor/libarchive/libarchive/archive_entry_xattr.c +155 -0
  100. package/vendor/libarchive/libarchive/archive_hmac.c +345 -0
  101. package/vendor/libarchive/libarchive/archive_hmac_private.h +119 -0
  102. package/vendor/libarchive/libarchive/archive_integer.h +267 -0
  103. package/vendor/libarchive/libarchive/archive_match.c +1869 -0
  104. package/vendor/libarchive/libarchive/archive_openssl_evp_private.h +54 -0
  105. package/vendor/libarchive/libarchive/archive_openssl_hmac_private.h +54 -0
  106. package/vendor/libarchive/libarchive/archive_options.c +219 -0
  107. package/vendor/libarchive/libarchive/archive_options_private.h +49 -0
  108. package/vendor/libarchive/libarchive/archive_pack_dev.c +330 -0
  109. package/vendor/libarchive/libarchive/archive_pack_dev.h +49 -0
  110. package/vendor/libarchive/libarchive/archive_parse_date.c +1173 -0
  111. package/vendor/libarchive/libarchive/archive_pathmatch.c +480 -0
  112. package/vendor/libarchive/libarchive/archive_pathmatch.h +50 -0
  113. package/vendor/libarchive/libarchive/archive_platform.h +213 -0
  114. package/vendor/libarchive/libarchive/archive_platform_acl.h +53 -0
  115. package/vendor/libarchive/libarchive/archive_platform_stat.h +45 -0
  116. package/vendor/libarchive/libarchive/archive_platform_xattr.h +45 -0
  117. package/vendor/libarchive/libarchive/archive_ppmd7.c +1173 -0
  118. package/vendor/libarchive/libarchive/archive_ppmd7_private.h +119 -0
  119. package/vendor/libarchive/libarchive/archive_ppmd8.c +1293 -0
  120. package/vendor/libarchive/libarchive/archive_ppmd8_private.h +123 -0
  121. package/vendor/libarchive/libarchive/archive_ppmd_private.h +159 -0
  122. package/vendor/libarchive/libarchive/archive_private.h +209 -0
  123. package/vendor/libarchive/libarchive/archive_random.c +274 -0
  124. package/vendor/libarchive/libarchive/archive_random_private.h +36 -0
  125. package/vendor/libarchive/libarchive/archive_rb.c +709 -0
  126. package/vendor/libarchive/libarchive/archive_rb.h +113 -0
  127. package/vendor/libarchive/libarchive/archive_read.3 +250 -0
  128. package/vendor/libarchive/libarchive/archive_read.c +1814 -0
  129. package/vendor/libarchive/libarchive/archive_read_add_passphrase.3 +72 -0
  130. package/vendor/libarchive/libarchive/archive_read_add_passphrase.c +189 -0
  131. package/vendor/libarchive/libarchive/archive_read_append_filter.c +209 -0
  132. package/vendor/libarchive/libarchive/archive_read_data.3 +128 -0
  133. package/vendor/libarchive/libarchive/archive_read_data_into_fd.c +207 -0
  134. package/vendor/libarchive/libarchive/archive_read_disk.3 +422 -0
  135. package/vendor/libarchive/libarchive/archive_read_disk_entry_from_file.c +1086 -0
  136. package/vendor/libarchive/libarchive/archive_read_disk_posix.c +2639 -0
  137. package/vendor/libarchive/libarchive/archive_read_disk_private.h +97 -0
  138. package/vendor/libarchive/libarchive/archive_read_disk_set_standard_lookup.c +315 -0
  139. package/vendor/libarchive/libarchive/archive_read_disk_windows.c +2603 -0
  140. package/vendor/libarchive/libarchive/archive_read_extract.3 +135 -0
  141. package/vendor/libarchive/libarchive/archive_read_extract.c +59 -0
  142. package/vendor/libarchive/libarchive/archive_read_extract2.c +154 -0
  143. package/vendor/libarchive/libarchive/archive_read_filter.3 +163 -0
  144. package/vendor/libarchive/libarchive/archive_read_format.3 +190 -0
  145. package/vendor/libarchive/libarchive/archive_read_free.3 +91 -0
  146. package/vendor/libarchive/libarchive/archive_read_header.3 +89 -0
  147. package/vendor/libarchive/libarchive/archive_read_new.3 +57 -0
  148. package/vendor/libarchive/libarchive/archive_read_open.3 +247 -0
  149. package/vendor/libarchive/libarchive/archive_read_open_fd.c +236 -0
  150. package/vendor/libarchive/libarchive/archive_read_open_file.c +257 -0
  151. package/vendor/libarchive/libarchive/archive_read_open_filename.c +652 -0
  152. package/vendor/libarchive/libarchive/archive_read_open_memory.c +188 -0
  153. package/vendor/libarchive/libarchive/archive_read_private.h +274 -0
  154. package/vendor/libarchive/libarchive/archive_read_set_format.c +116 -0
  155. package/vendor/libarchive/libarchive/archive_read_set_options.3 +290 -0
  156. package/vendor/libarchive/libarchive/archive_read_set_options.c +132 -0
  157. package/vendor/libarchive/libarchive/archive_read_support_filter_all.c +84 -0
  158. package/vendor/libarchive/libarchive/archive_read_support_filter_by_code.c +68 -0
  159. package/vendor/libarchive/libarchive/archive_read_support_filter_bzip2.c +360 -0
  160. package/vendor/libarchive/libarchive/archive_read_support_filter_compress.c +457 -0
  161. package/vendor/libarchive/libarchive/archive_read_support_filter_grzip.c +108 -0
  162. package/vendor/libarchive/libarchive/archive_read_support_filter_gzip.c +538 -0
  163. package/vendor/libarchive/libarchive/archive_read_support_filter_lrzip.c +119 -0
  164. package/vendor/libarchive/libarchive/archive_read_support_filter_lz4.c +829 -0
  165. package/vendor/libarchive/libarchive/archive_read_support_filter_lzop.c +493 -0
  166. package/vendor/libarchive/libarchive/archive_read_support_filter_none.c +51 -0
  167. package/vendor/libarchive/libarchive/archive_read_support_filter_program.c +497 -0
  168. package/vendor/libarchive/libarchive/archive_read_support_filter_rpm.c +249 -0
  169. package/vendor/libarchive/libarchive/archive_read_support_filter_uu.c +739 -0
  170. package/vendor/libarchive/libarchive/archive_read_support_filter_xz.c +792 -0
  171. package/vendor/libarchive/libarchive/archive_read_support_filter_zstd.c +356 -0
  172. package/vendor/libarchive/libarchive/archive_read_support_format_7zip.c +4650 -0
  173. package/vendor/libarchive/libarchive/archive_read_support_format_all.c +88 -0
  174. package/vendor/libarchive/libarchive/archive_read_support_format_ar.c +597 -0
  175. package/vendor/libarchive/libarchive/archive_read_support_format_by_code.c +76 -0
  176. package/vendor/libarchive/libarchive/archive_read_support_format_cab.c +3410 -0
  177. package/vendor/libarchive/libarchive/archive_read_support_format_cpio.c +1152 -0
  178. package/vendor/libarchive/libarchive/archive_read_support_format_empty.c +95 -0
  179. package/vendor/libarchive/libarchive/archive_read_support_format_iso9660.c +3516 -0
  180. package/vendor/libarchive/libarchive/archive_read_support_format_lha.c +2931 -0
  181. package/vendor/libarchive/libarchive/archive_read_support_format_mtree.c +2113 -0
  182. package/vendor/libarchive/libarchive/archive_read_support_format_rar.c +3932 -0
  183. package/vendor/libarchive/libarchive/archive_read_support_format_rar5.c +4501 -0
  184. package/vendor/libarchive/libarchive/archive_read_support_format_raw.c +194 -0
  185. package/vendor/libarchive/libarchive/archive_read_support_format_tar.c +3785 -0
  186. package/vendor/libarchive/libarchive/archive_read_support_format_warc.c +875 -0
  187. package/vendor/libarchive/libarchive/archive_read_support_format_xar.c +3770 -0
  188. package/vendor/libarchive/libarchive/archive_read_support_format_zip.c +4710 -0
  189. package/vendor/libarchive/libarchive/archive_string.c +4391 -0
  190. package/vendor/libarchive/libarchive/archive_string.h +244 -0
  191. package/vendor/libarchive/libarchive/archive_string_composition.h +2289 -0
  192. package/vendor/libarchive/libarchive/archive_string_sprintf.c +200 -0
  193. package/vendor/libarchive/libarchive/archive_time.c +168 -0
  194. package/vendor/libarchive/libarchive/archive_time_private.h +47 -0
  195. package/vendor/libarchive/libarchive/archive_util.3 +239 -0
  196. package/vendor/libarchive/libarchive/archive_util.c +668 -0
  197. package/vendor/libarchive/libarchive/archive_version_details.c +516 -0
  198. package/vendor/libarchive/libarchive/archive_virtual.c +162 -0
  199. package/vendor/libarchive/libarchive/archive_windows.c +1035 -0
  200. package/vendor/libarchive/libarchive/archive_windows.h +332 -0
  201. package/vendor/libarchive/libarchive/archive_write.3 +266 -0
  202. package/vendor/libarchive/libarchive/archive_write.c +896 -0
  203. package/vendor/libarchive/libarchive/archive_write_add_filter.c +71 -0
  204. package/vendor/libarchive/libarchive/archive_write_add_filter_b64encode.c +329 -0
  205. package/vendor/libarchive/libarchive/archive_write_add_filter_by_name.c +76 -0
  206. package/vendor/libarchive/libarchive/archive_write_add_filter_bzip2.c +411 -0
  207. package/vendor/libarchive/libarchive/archive_write_add_filter_compress.c +459 -0
  208. package/vendor/libarchive/libarchive/archive_write_add_filter_grzip.c +143 -0
  209. package/vendor/libarchive/libarchive/archive_write_add_filter_gzip.c +493 -0
  210. package/vendor/libarchive/libarchive/archive_write_add_filter_lrzip.c +214 -0
  211. package/vendor/libarchive/libarchive/archive_write_add_filter_lz4.c +710 -0
  212. package/vendor/libarchive/libarchive/archive_write_add_filter_lzop.c +500 -0
  213. package/vendor/libarchive/libarchive/archive_write_add_filter_none.c +42 -0
  214. package/vendor/libarchive/libarchive/archive_write_add_filter_program.c +398 -0
  215. package/vendor/libarchive/libarchive/archive_write_add_filter_uuencode.c +320 -0
  216. package/vendor/libarchive/libarchive/archive_write_add_filter_xz.c +547 -0
  217. package/vendor/libarchive/libarchive/archive_write_add_filter_zstd.c +608 -0
  218. package/vendor/libarchive/libarchive/archive_write_blocksize.3 +112 -0
  219. package/vendor/libarchive/libarchive/archive_write_data.3 +88 -0
  220. package/vendor/libarchive/libarchive/archive_write_disk.3 +360 -0
  221. package/vendor/libarchive/libarchive/archive_write_disk_posix.c +4789 -0
  222. package/vendor/libarchive/libarchive/archive_write_disk_private.h +43 -0
  223. package/vendor/libarchive/libarchive/archive_write_disk_set_standard_lookup.c +265 -0
  224. package/vendor/libarchive/libarchive/archive_write_disk_windows.c +2952 -0
  225. package/vendor/libarchive/libarchive/archive_write_filter.3 +140 -0
  226. package/vendor/libarchive/libarchive/archive_write_finish_entry.3 +77 -0
  227. package/vendor/libarchive/libarchive/archive_write_format.3 +187 -0
  228. package/vendor/libarchive/libarchive/archive_write_free.3 +94 -0
  229. package/vendor/libarchive/libarchive/archive_write_header.3 +71 -0
  230. package/vendor/libarchive/libarchive/archive_write_new.3 +56 -0
  231. package/vendor/libarchive/libarchive/archive_write_open.3 +270 -0
  232. package/vendor/libarchive/libarchive/archive_write_open_fd.c +141 -0
  233. package/vendor/libarchive/libarchive/archive_write_open_file.c +102 -0
  234. package/vendor/libarchive/libarchive/archive_write_open_filename.c +272 -0
  235. package/vendor/libarchive/libarchive/archive_write_open_memory.c +110 -0
  236. package/vendor/libarchive/libarchive/archive_write_private.h +166 -0
  237. package/vendor/libarchive/libarchive/archive_write_set_format.c +124 -0
  238. package/vendor/libarchive/libarchive/archive_write_set_format_7zip.c +2571 -0
  239. package/vendor/libarchive/libarchive/archive_write_set_format_ar.c +540 -0
  240. package/vendor/libarchive/libarchive/archive_write_set_format_by_name.c +93 -0
  241. package/vendor/libarchive/libarchive/archive_write_set_format_cpio.c +11 -0
  242. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_binary.c +618 -0
  243. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_newc.c +457 -0
  244. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_odc.c +508 -0
  245. package/vendor/libarchive/libarchive/archive_write_set_format_filter_by_ext.c +141 -0
  246. package/vendor/libarchive/libarchive/archive_write_set_format_gnutar.c +790 -0
  247. package/vendor/libarchive/libarchive/archive_write_set_format_iso9660.c +8216 -0
  248. package/vendor/libarchive/libarchive/archive_write_set_format_mtree.c +2307 -0
  249. package/vendor/libarchive/libarchive/archive_write_set_format_pax.c +2249 -0
  250. package/vendor/libarchive/libarchive/archive_write_set_format_private.h +40 -0
  251. package/vendor/libarchive/libarchive/archive_write_set_format_raw.c +123 -0
  252. package/vendor/libarchive/libarchive/archive_write_set_format_shar.c +650 -0
  253. package/vendor/libarchive/libarchive/archive_write_set_format_ustar.c +768 -0
  254. package/vendor/libarchive/libarchive/archive_write_set_format_v7tar.c +648 -0
  255. package/vendor/libarchive/libarchive/archive_write_set_format_warc.c +491 -0
  256. package/vendor/libarchive/libarchive/archive_write_set_format_xar.c +3799 -0
  257. package/vendor/libarchive/libarchive/archive_write_set_format_zip.c +2548 -0
  258. package/vendor/libarchive/libarchive/archive_write_set_options.3 +779 -0
  259. package/vendor/libarchive/libarchive/archive_write_set_options.c +129 -0
  260. package/vendor/libarchive/libarchive/archive_write_set_passphrase.3 +72 -0
  261. package/vendor/libarchive/libarchive/archive_write_set_passphrase.c +95 -0
  262. package/vendor/libarchive/libarchive/archive_xxhash.h +48 -0
  263. package/vendor/libarchive/libarchive/config_freebsd.h +275 -0
  264. package/vendor/libarchive/libarchive/cpio.5 +389 -0
  265. package/vendor/libarchive/libarchive/filter_fork.h +44 -0
  266. package/vendor/libarchive/libarchive/filter_fork_posix.c +269 -0
  267. package/vendor/libarchive/libarchive/filter_fork_windows.c +270 -0
  268. package/vendor/libarchive/libarchive/libarchive-formats.5 +478 -0
  269. package/vendor/libarchive/libarchive/libarchive.3 +297 -0
  270. package/vendor/libarchive/libarchive/libarchive_changes.3 +339 -0
  271. package/vendor/libarchive/libarchive/libarchive_internals.3 +363 -0
  272. package/vendor/libarchive/libarchive/module.modulemap +34 -0
  273. package/vendor/libarchive/libarchive/mtree.5 +323 -0
  274. package/vendor/libarchive/libarchive/tar.5 +947 -0
  275. package/vendor/libarchive/libarchive/xxhash.c +531 -0
  276. package/ios/PapyrusNativeEngine.podspec +0 -15
@@ -0,0 +1,389 @@
1
+ .\" Copyright (c) 2007 Tim Kientzle
2
+ .\" All rights reserved.
3
+ .\"
4
+ .\" Redistribution and use in source and binary forms, with or without
5
+ .\" modification, are permitted provided that the following conditions
6
+ .\" are met:
7
+ .\" 1. Redistributions of source code must retain the above copyright
8
+ .\" notice, this list of conditions and the following disclaimer.
9
+ .\" 2. Redistributions in binary form must reproduce the above copyright
10
+ .\" notice, this list of conditions and the following disclaimer in the
11
+ .\" documentation and/or other materials provided with the distribution.
12
+ .\"
13
+ .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14
+ .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
+ .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16
+ .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17
+ .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18
+ .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19
+ .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20
+ .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21
+ .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22
+ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23
+ .\" SUCH DAMAGE.
24
+ .\"
25
+ .Dd December 23, 2011
26
+ .Dt CPIO 5
27
+ .Os
28
+ .Sh NAME
29
+ .Nm cpio
30
+ .Nd format of cpio archive files
31
+ .Sh DESCRIPTION
32
+ The
33
+ .Nm
34
+ archive format collects any number of files, directories, and other
35
+ file system objects (symbolic links, device nodes, etc.) into a single
36
+ stream of bytes.
37
+ .Ss General Format
38
+ Each file system object in a
39
+ .Nm
40
+ archive comprises a header record with basic numeric metadata
41
+ followed by the full pathname of the entry and the file data.
42
+ The header record stores a series of integer values that generally
43
+ follow the fields in
44
+ .Va struct stat .
45
+ (See
46
+ .Xr stat 2
47
+ for details.)
48
+ The variants differ primarily in how they store those integers
49
+ (binary, octal, or hexadecimal).
50
+ The header is followed by the pathname of the
51
+ entry (the length of the pathname is stored in the header)
52
+ and any file data.
53
+ The end of the archive is indicated by a special record with
54
+ the pathname
55
+ .Dq TRAILER!!! .
56
+ .Ss PWB format
57
+ The PWB binary
58
+ .Nm
59
+ format is the original format, when cpio was introduced as part of the
60
+ Programmer's Work Bench system, a variant of 6th Edition UNIX. It
61
+ stores numbers as 2-byte and 4-byte binary values.
62
+ Each entry begins with a header in the following format:
63
+ .Pp
64
+ .Bd -literal -offset indent
65
+ struct header_pwb_cpio {
66
+ short h_magic;
67
+ short h_dev;
68
+ short h_ino;
69
+ short h_mode;
70
+ short h_uid;
71
+ short h_gid;
72
+ short h_nlink;
73
+ short h_majmin;
74
+ long h_mtime;
75
+ short h_namesize;
76
+ long h_filesize;
77
+ };
78
+ .Ed
79
+ .Pp
80
+ The
81
+ .Va short
82
+ fields here are 16-bit integer values, while the
83
+ .Va long
84
+ fields are 32 bit integers. Since PWB UNIX, like the 6th Edition UNIX
85
+ it was based on, only ran on PDP-11 computers, they
86
+ are in PDP-endian format, which has little-endian shorts, and
87
+ big-endian longs. That is, the long integer whose hexadecimal
88
+ representation is 0x12345678 would be stored in four successive bytes
89
+ as 0x34, 0x12, 0x78, 0x56.
90
+ The fields are as follows:
91
+ .Bl -tag -width indent
92
+ .It Va h_magic
93
+ The integer value octal 070707.
94
+ .It Va h_dev , Va h_ino
95
+ The device and inode numbers from the disk.
96
+ These are used by programs that read
97
+ .Nm
98
+ archives to determine when two entries refer to the same file.
99
+ Programs that synthesize
100
+ .Nm
101
+ archives should be careful to set these to distinct values for each entry.
102
+ .It Va h_mode
103
+ The mode specifies both the regular permissions and the file type, and
104
+ it also holds a couple of bits that are irrelevant to the cpio format,
105
+ because the field is actually a raw copy of the mode field in the inode
106
+ representing the file. These are the IALLOC flag, which shows that
107
+ the inode entry is in use, and the ILARG flag, which shows that the
108
+ file it represents is large enough to have indirect blocks pointers in
109
+ the inode.
110
+ The mode is decoded as follows:
111
+ .Pp
112
+ .Bl -tag -width "MMMMMMM" -compact
113
+ .It 0100000
114
+ IALLOC flag - irrelevant to cpio.
115
+ .It 0060000
116
+ This masks the file type bits.
117
+ .It 0040000
118
+ File type value for directories.
119
+ .It 0020000
120
+ File type value for character special devices.
121
+ .It 0060000
122
+ File type value for block special devices.
123
+ .It 0010000
124
+ ILARG flag - irrelevant to cpio.
125
+ .It 0004000
126
+ SUID bit.
127
+ .It 0002000
128
+ SGID bit.
129
+ .It 0001000
130
+ Sticky bit.
131
+ .It 0000777
132
+ The lower 9 bits specify read/write/execute permissions
133
+ for world, group, and user following standard POSIX conventions.
134
+ .El
135
+ .It Va h_uid , Va h_gid
136
+ The numeric user id and group id of the owner.
137
+ .It Va h_nlink
138
+ The number of links to this file.
139
+ Directories always have a value of at least two here.
140
+ Note that hardlinked files include file data with every copy in the archive.
141
+ .It Va h_majmin
142
+ For block special and character special entries,
143
+ this field contains the associated device number, with the major
144
+ number in the high byte, and the minor number in the low byte.
145
+ For all other entry types, it should be set to zero by writers
146
+ and ignored by readers.
147
+ .It Va h_mtime
148
+ Modification time of the file, indicated as the number
149
+ of seconds since the start of the epoch,
150
+ 00:00:00 UTC January 1, 1970.
151
+ .It Va h_namesize
152
+ The number of bytes in the pathname that follows the header.
153
+ This count includes the trailing NUL byte.
154
+ .It Va h_filesize
155
+ The size of the file. Note that this archive format is limited to 16
156
+ megabyte file sizes, because PWB UNIX, like 6th Edition, only used
157
+ an unsigned 24 bit integer for the file size internally.
158
+ .El
159
+ .Pp
160
+ The pathname immediately follows the fixed header.
161
+ If
162
+ .Cm h_namesize
163
+ is odd, an additional NUL byte is added after the pathname.
164
+ The file data is then appended, again with an additional NUL
165
+ appended if needed to get the next header at an even offset.
166
+ .Pp
167
+ Hardlinked files are not given special treatment;
168
+ the full file contents are included with each copy of the
169
+ file.
170
+ .Ss New Binary Format
171
+ The new binary
172
+ .Nm
173
+ format showed up when cpio was adopted into late 7th Edition UNIX.
174
+ It is exactly like the PWB binary format, described above, except for
175
+ three changes:
176
+ .Pp
177
+ First, UNIX now ran on more than one hardware type, so the endianness
178
+ of 16 bit integers must be determined by observing the magic number at
179
+ the start of the header. The 32 bit integers are still always stored
180
+ with the most significant word first, though, so each of those two, in
181
+ the struct shown above, was stored as an array of two 16 bit integers,
182
+ in the traditional order. Those 16 bit integers, like all the others
183
+ in the struct, were accessed using a macro that byte swapped them if
184
+ necessary.
185
+ .Pp
186
+ Next, 7th Edition had more file types to store, and the IALLOC and ILARG
187
+ flag bits were re-purposed to accommodate these. The revised use of the
188
+ various bits is as follows:
189
+ .Pp
190
+ .Bl -tag -width "MMMMMMM" -compact
191
+ .It 0170000
192
+ This masks the file type bits.
193
+ .It 0140000
194
+ File type value for sockets.
195
+ .It 0120000
196
+ File type value for symbolic links.
197
+ For symbolic links, the link body is stored as file data.
198
+ .It 0100000
199
+ File type value for regular files.
200
+ .It 0060000
201
+ File type value for block special devices.
202
+ .It 0040000
203
+ File type value for directories.
204
+ .It 0020000
205
+ File type value for character special devices.
206
+ .It 0010000
207
+ File type value for named pipes or FIFOs.
208
+ .It 0004000
209
+ SUID bit.
210
+ .It 0002000
211
+ SGID bit.
212
+ .It 0001000
213
+ Sticky bit.
214
+ .It 0000777
215
+ The lower 9 bits specify read/write/execute permissions
216
+ for world, group, and user following standard POSIX conventions.
217
+ .El
218
+ .Pp
219
+ Finally, the file size field now represents a signed 32 bit integer in
220
+ the underlying file system, so the maximum file size has increased to
221
+ 2 gigabytes.
222
+ .Pp
223
+ Note that there is no obvious way to tell which of the two binary
224
+ formats an archive uses, other than to see which one makes more
225
+ sense. The typical error scenario is that a PWB format archive
226
+ unpacked as if it were in the new format will create named sockets
227
+ instead of directories, and then fail to unpack files that should
228
+ go in those directories. Running
229
+ .Va bsdcpio -itv
230
+ on an unknown archive will make it obvious which it is: if it's
231
+ PWB format, directories will be listed with an 's' instead of
232
+ a 'd' as the first character of the mode string, and the larger
233
+ files will have a '?' in that position.
234
+ .Ss Portable ASCII Format
235
+ .St -susv2
236
+ standardized an ASCII variant that is portable across all
237
+ platforms.
238
+ It is commonly known as the
239
+ .Dq old character
240
+ format or as the
241
+ .Dq odc
242
+ format.
243
+ It stores the same numeric fields as the old binary format, but
244
+ represents them as 6-character or 11-character octal values.
245
+ .Pp
246
+ .Bd -literal -offset indent
247
+ struct cpio_odc_header {
248
+ char c_magic[6];
249
+ char c_dev[6];
250
+ char c_ino[6];
251
+ char c_mode[6];
252
+ char c_uid[6];
253
+ char c_gid[6];
254
+ char c_nlink[6];
255
+ char c_rdev[6];
256
+ char c_mtime[11];
257
+ char c_namesize[6];
258
+ char c_filesize[11];
259
+ };
260
+ .Ed
261
+ .Pp
262
+ The fields are identical to those in the new binary format.
263
+ The name and file body follow the fixed header.
264
+ Unlike the binary formats, there is no additional padding
265
+ after the pathname or file contents.
266
+ If the files being archived are themselves entirely ASCII, then
267
+ the resulting archive will be entirely ASCII, except for the
268
+ NUL byte that terminates the name field.
269
+ .Ss New ASCII Format
270
+ The "new" ASCII format uses 8-byte hexadecimal fields for
271
+ all numbers and separates device numbers into separate fields
272
+ for major and minor numbers.
273
+ .Pp
274
+ .Bd -literal -offset indent
275
+ struct cpio_newc_header {
276
+ char c_magic[6];
277
+ char c_ino[8];
278
+ char c_mode[8];
279
+ char c_uid[8];
280
+ char c_gid[8];
281
+ char c_nlink[8];
282
+ char c_mtime[8];
283
+ char c_filesize[8];
284
+ char c_devmajor[8];
285
+ char c_devminor[8];
286
+ char c_rdevmajor[8];
287
+ char c_rdevminor[8];
288
+ char c_namesize[8];
289
+ char c_check[8];
290
+ };
291
+ .Ed
292
+ .Pp
293
+ Except as specified below, the fields here match those specified
294
+ for the new binary format above.
295
+ .Bl -tag -width indent
296
+ .It Va magic
297
+ The string
298
+ .Dq 070701 .
299
+ .It Va check
300
+ This field is always set to zero by writers and ignored by readers.
301
+ See the next section for more details.
302
+ .El
303
+ .Pp
304
+ The pathname is followed by NUL bytes so that the total size
305
+ of the fixed header plus pathname is a multiple of four.
306
+ Likewise, the file data is padded to a multiple of four bytes.
307
+ Note that this format supports only 4 gigabyte files (unlike the
308
+ older ASCII format, which supports 8 gigabyte files).
309
+ .Pp
310
+ In this format, hardlinked files are handled by setting the
311
+ filesize to zero for each entry except the first one that
312
+ appears in the archive.
313
+ .Ss New CRC Format
314
+ The CRC format is identical to the new ASCII format described
315
+ in the previous section except that the magic field is set
316
+ to
317
+ .Dq 070702
318
+ and the
319
+ .Va check
320
+ field is set to the sum of all bytes in the file data.
321
+ This sum is computed treating all bytes as unsigned values
322
+ and using unsigned arithmetic.
323
+ Only the least-significant 32 bits of the sum are stored.
324
+ .Ss HP variants
325
+ The
326
+ .Nm cpio
327
+ implementation distributed with HPUX used XXXX but stored
328
+ device numbers differently XXX.
329
+ .Ss Other Extensions and Variants
330
+ Sun Solaris uses additional file types to store extended file
331
+ data, including ACLs and extended attributes, as special
332
+ entries in cpio archives.
333
+ .Pp
334
+ XXX Others? XXX
335
+ .Sh SEE ALSO
336
+ .Xr cpio 1 ,
337
+ .Xr tar 5
338
+ .Sh STANDARDS
339
+ The
340
+ .Nm cpio
341
+ utility is no longer a part of POSIX or the Single Unix Standard.
342
+ It last appeared in
343
+ .St -susv2 .
344
+ It has been supplanted in subsequent standards by
345
+ .Xr pax 1 .
346
+ The portable ASCII format is currently part of the specification for the
347
+ .Xr pax 1
348
+ utility.
349
+ .Sh HISTORY
350
+ The original cpio utility was written by Dick Haight
351
+ while working in AT&T's Unix Support Group.
352
+ It appeared in 1977 as part of PWB/UNIX 1.0, the
353
+ .Dq Programmer's Work Bench
354
+ derived from
355
+ .At v6
356
+ that was used internally at AT&T.
357
+ Both the new binary and old character formats were in use
358
+ by 1980, according to the System III source released
359
+ by SCO under their
360
+ .Dq Ancient Unix
361
+ license.
362
+ The character format was adopted as part of
363
+ .St -p1003.1-88 .
364
+ XXX when did "newc" appear? Who invented it? When did HP come out with their variant? When did Sun introduce ACLs and extended attributes? XXX
365
+ .Sh BUGS
366
+ The
367
+ .Dq CRC
368
+ format is mis-named, as it uses a simple checksum and
369
+ not a cyclic redundancy check.
370
+ .Pp
371
+ The binary formats are limited to 16 bits for user id, group id,
372
+ device, and inode numbers. They are limited to 16 megabyte and 2
373
+ gigabyte file sizes for the older and newer variants, respectively.
374
+ .Pp
375
+ The old ASCII format is limited to 18 bits for
376
+ the user id, group id, device, and inode numbers.
377
+ It is limited to 8 gigabyte file sizes.
378
+ .Pp
379
+ The new ASCII format is limited to 4 gigabyte file sizes.
380
+ .Pp
381
+ None of the cpio formats store user or group names,
382
+ which are essential when moving files between systems with
383
+ dissimilar user or group numbering.
384
+ .Pp
385
+ Especially when writing older cpio variants, it may be necessary
386
+ to map actual device/inode values to synthesized values that
387
+ fit the available fields.
388
+ With very large filesystems, this may be necessary even for
389
+ the newer formats.
@@ -0,0 +1,44 @@
1
+ /*-
2
+ * Copyright (c) 2007 Joerg Sonnenberger
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
+ #ifndef FILTER_FORK_H
27
+ #define FILTER_FORK_H
28
+
29
+ #ifndef __LIBARCHIVE_BUILD
30
+ #error This header is only to be used internally to libarchive.
31
+ #endif
32
+
33
+ int
34
+ __archive_create_child(const char *cmd, int *child_stdin, int *child_stdout,
35
+ #if defined(_WIN32) && !defined(__CYGWIN__)
36
+ HANDLE *out_child);
37
+ #else
38
+ pid_t *out_child);
39
+ #endif
40
+
41
+ void
42
+ __archive_check_child(int in, int out);
43
+
44
+ #endif
@@ -0,0 +1,269 @@
1
+ /*-
2
+ * Copyright (c) 2007 Joerg Sonnenberger
3
+ * Copyright (c) 2012 Michihiro NAKAJIMA
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions
8
+ * are met:
9
+ * 1. Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ *
15
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ */
26
+
27
+ #include "archive_platform.h"
28
+
29
+ /* This capability is only available on POSIX systems. */
30
+ #if defined(HAVE_PIPE) && defined(HAVE_FCNTL) && \
31
+ (defined(HAVE_FORK) || defined(HAVE_VFORK) || defined(HAVE_POSIX_SPAWNP))
32
+
33
+ #if defined(HAVE_SYS_TYPES_H)
34
+ # include <sys/types.h>
35
+ #endif
36
+ #ifdef HAVE_ERRNO_H
37
+ # include <errno.h>
38
+ #endif
39
+ #ifdef HAVE_STRING_H
40
+ # include <string.h>
41
+ #endif
42
+ #if defined(HAVE_POLL) && (defined(HAVE_POLL_H) || defined(HAVE_SYS_POLL_H))
43
+ # if defined(HAVE_POLL_H)
44
+ # include <poll.h>
45
+ # elif defined(HAVE_SYS_POLL_H)
46
+ # include <sys/poll.h>
47
+ # endif
48
+ #elif defined(HAVE_SELECT)
49
+ # if defined(HAVE_SYS_SELECT_H)
50
+ # include <sys/select.h>
51
+ # elif defined(HAVE_UNISTD_H)
52
+ # include <unistd.h>
53
+ # endif
54
+ #endif
55
+ #ifdef HAVE_FCNTL_H
56
+ # include <fcntl.h>
57
+ #endif
58
+ #ifdef HAVE_SPAWN_H
59
+ # include <spawn.h>
60
+ #endif
61
+ #ifdef HAVE_STDLIB_H
62
+ # include <stdlib.h>
63
+ #endif
64
+ #ifdef HAVE_UNISTD_H
65
+ # include <unistd.h>
66
+ #endif
67
+
68
+ #include "archive.h"
69
+ #include "archive_cmdline_private.h"
70
+
71
+ #include "filter_fork.h"
72
+
73
+ int
74
+ __archive_create_child(const char *cmd, int *child_stdin, int *child_stdout,
75
+ pid_t *out_child)
76
+ {
77
+ pid_t child = -1;
78
+ int stdin_pipe[2], stdout_pipe[2], tmp;
79
+
80
+ #if !defined(POSIX_SPAWN_CLOEXEC_DEFAULT) && \
81
+ (HAVE_FORK || HAVE_VFORK) && \
82
+ (HAVE_CLOSEFROM || HAVE_CLOSE_RANGE || defined(_SC_OPEN_MAX))
83
+ #undef HAVE_POSIX_SPAWNP
84
+ #endif
85
+
86
+ #if HAVE_POSIX_SPAWNP
87
+ posix_spawnattr_t attr;
88
+ posix_spawn_file_actions_t actions;
89
+ int r;
90
+ #endif
91
+ struct archive_cmdline *cmdline;
92
+
93
+ cmdline = __archive_cmdline_allocate();
94
+ if (cmdline == NULL)
95
+ goto state_allocated;
96
+ if (__archive_cmdline_parse(cmdline, cmd) != ARCHIVE_OK)
97
+ goto state_allocated;
98
+
99
+ if (pipe(stdin_pipe) == -1)
100
+ goto state_allocated;
101
+ if (stdin_pipe[0] == 1 /* stdout */) {
102
+ if ((tmp = dup(stdin_pipe[0])) == -1)
103
+ goto stdin_opened;
104
+ close(stdin_pipe[0]);
105
+ stdin_pipe[0] = tmp;
106
+ }
107
+ if (pipe(stdout_pipe) == -1)
108
+ goto stdin_opened;
109
+ if (stdout_pipe[1] == 0 /* stdin */) {
110
+ if ((tmp = dup(stdout_pipe[1])) == -1)
111
+ goto stdout_opened;
112
+ close(stdout_pipe[1]);
113
+ stdout_pipe[1] = tmp;
114
+ }
115
+
116
+ #if HAVE_POSIX_SPAWNP
117
+
118
+ r = posix_spawnattr_init(&attr);
119
+ if (r != 0) {
120
+ errno = r;
121
+ goto stdout_opened;
122
+ }
123
+ r = posix_spawn_file_actions_init(&actions);
124
+ if (r != 0) {
125
+ errno = r;
126
+ goto attr_inited;
127
+ }
128
+ #ifdef POSIX_SPAWN_CLOEXEC_DEFAULT
129
+ r = posix_spawnattr_setflags(&attr, POSIX_SPAWN_CLOEXEC_DEFAULT);
130
+ if (r != 0)
131
+ goto actions_inited;
132
+ #endif
133
+ r = posix_spawn_file_actions_addclose(&actions, stdin_pipe[1]);
134
+ if (r != 0)
135
+ goto actions_inited;
136
+ r = posix_spawn_file_actions_addclose(&actions, stdout_pipe[0]);
137
+ if (r != 0)
138
+ goto actions_inited;
139
+ /* Setup for stdin. */
140
+ r = posix_spawn_file_actions_adddup2(&actions, stdin_pipe[0], 0);
141
+ if (r != 0)
142
+ goto actions_inited;
143
+ if (stdin_pipe[0] != 0 /* stdin */) {
144
+ r = posix_spawn_file_actions_addclose(&actions, stdin_pipe[0]);
145
+ if (r != 0)
146
+ goto actions_inited;
147
+ }
148
+ /* Setup for stdout. */
149
+ r = posix_spawn_file_actions_adddup2(&actions, stdout_pipe[1], 1);
150
+ if (r != 0)
151
+ goto actions_inited;
152
+ if (stdout_pipe[1] != 1 /* stdout */) {
153
+ r = posix_spawn_file_actions_addclose(&actions, stdout_pipe[1]);
154
+ if (r != 0)
155
+ goto actions_inited;
156
+ }
157
+ r = posix_spawnp(&child, cmdline->path, &actions, &attr,
158
+ cmdline->argv, NULL);
159
+ if (r != 0)
160
+ goto actions_inited;
161
+ posix_spawn_file_actions_destroy(&actions);
162
+ posix_spawnattr_destroy(&attr);
163
+
164
+ #else /* HAVE_POSIX_SPAWNP */
165
+
166
+ #if HAVE_VFORK
167
+ child = vfork();
168
+ #else
169
+ child = fork();
170
+ #endif
171
+ if (child == -1)
172
+ goto stdout_opened;
173
+ if (child == 0) {
174
+ close(stdin_pipe[1]);
175
+ close(stdout_pipe[0]);
176
+ if (dup2(stdin_pipe[0], 0 /* stdin */) == -1)
177
+ _exit(254);
178
+ if (stdin_pipe[0] != 0 /* stdin */)
179
+ close(stdin_pipe[0]);
180
+ if (dup2(stdout_pipe[1], 1 /* stdout */) == -1)
181
+ _exit(254);
182
+ if (stdout_pipe[1] != 1 /* stdout */)
183
+ close(stdout_pipe[1]);
184
+
185
+ #if HAVE_CLOSEFROM
186
+ closefrom(3);
187
+ #elif HAVE_CLOSE_RANGE
188
+ close_range(3, ~0U, 0);
189
+ #elif defined(_SC_OPEN_MAX)
190
+ for (int i = sysconf(_SC_OPEN_MAX); i > 3;)
191
+ close(--i);
192
+ #endif
193
+
194
+ execvp(cmdline->path, cmdline->argv);
195
+ _exit(254);
196
+ }
197
+ #endif /* HAVE_POSIX_SPAWNP */
198
+
199
+ close(stdin_pipe[0]);
200
+ close(stdout_pipe[1]);
201
+
202
+ *child_stdin = stdin_pipe[1];
203
+ fcntl(*child_stdin, F_SETFL, O_NONBLOCK);
204
+ *child_stdout = stdout_pipe[0];
205
+ fcntl(*child_stdout, F_SETFL, O_NONBLOCK);
206
+ __archive_cmdline_free(cmdline);
207
+
208
+ *out_child = child;
209
+ return ARCHIVE_OK;
210
+
211
+ #if HAVE_POSIX_SPAWNP
212
+ actions_inited:
213
+ errno = r;
214
+ posix_spawn_file_actions_destroy(&actions);
215
+ attr_inited:
216
+ posix_spawnattr_destroy(&attr);
217
+ #endif
218
+ stdout_opened:
219
+ close(stdout_pipe[0]);
220
+ close(stdout_pipe[1]);
221
+ stdin_opened:
222
+ close(stdin_pipe[0]);
223
+ close(stdin_pipe[1]);
224
+ state_allocated:
225
+ __archive_cmdline_free(cmdline);
226
+ return ARCHIVE_FAILED;
227
+ }
228
+
229
+ void
230
+ __archive_check_child(int in, int out)
231
+ {
232
+ #if defined(HAVE_POLL) && (defined(HAVE_POLL_H) || defined(HAVE_SYS_POLL_H))
233
+ struct pollfd fds[2];
234
+ int idx;
235
+
236
+ idx = 0;
237
+ if (in != -1) {
238
+ fds[idx].fd = in;
239
+ fds[idx].events = POLLOUT;
240
+ ++idx;
241
+ }
242
+ if (out != -1) {
243
+ fds[idx].fd = out;
244
+ fds[idx].events = POLLIN;
245
+ ++idx;
246
+ }
247
+
248
+ poll(fds, idx, -1); /* -1 == INFTIM, wait forever */
249
+ #elif defined(HAVE_SELECT)
250
+ fd_set fds_in, fds_out, fds_error;
251
+
252
+ FD_ZERO(&fds_in);
253
+ FD_ZERO(&fds_out);
254
+ FD_ZERO(&fds_error);
255
+ if (out != -1) {
256
+ FD_SET(out, &fds_in);
257
+ FD_SET(out, &fds_error);
258
+ }
259
+ if (in != -1) {
260
+ FD_SET(in, &fds_out);
261
+ FD_SET(in, &fds_error);
262
+ }
263
+ select(in < out ? out + 1 : in + 1, &fds_in, &fds_out, &fds_error, NULL);
264
+ #else
265
+ sleep(1);
266
+ #endif
267
+ }
268
+
269
+ #endif /* defined(HAVE_PIPE) && defined(HAVE_VFORK) && defined(HAVE_FCNTL) */