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

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 (274) hide show
  1. package/android/build.gradle +0 -1
  2. package/android/src/main/cpp/CMakeLists.txt +0 -137
  3. package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +35 -305
  4. package/android/src/main/java/com/papyrus/engine/PapyrusPackage.java +1 -3
  5. package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerView.java +5 -195
  6. package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerViewManager.java +1 -20
  7. package/dist/index.d.mts +4 -608
  8. package/dist/index.d.ts +4 -608
  9. package/dist/index.js +8 -463
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +7 -456
  12. package/dist/index.mjs.map +1 -1
  13. package/ios/PapyrusEngineStore.h +0 -3
  14. package/ios/PapyrusEngineStore.m +6 -32
  15. package/ios/PapyrusNativeEngine.m +5 -684
  16. package/ios/PapyrusNativeEngine.podspec +15 -0
  17. package/ios/PapyrusPageView.m +11 -38
  18. package/package.json +4 -6
  19. package/react-native.config.js +1 -1
  20. package/PapyrusNativeEngine.podspec +0 -45
  21. package/android/src/main/cpp/PapyrusComicArchiveJni.cpp +0 -68
  22. package/android/src/main/cpp/PapyrusComicArchiveTest.cpp +0 -55
  23. package/android/src/main/java/com/papyrus/engine/PapyrusComicArchiveNative.java +0 -14
  24. package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentView.java +0 -491
  25. package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentViewManager.java +0 -32
  26. package/android/src/main/java/com/papyrus/engine/PapyrusComicPageLayout.java +0 -38
  27. package/android/src/main/java/com/papyrus/engine/PapyrusNativeTextModel.java +0 -195
  28. package/android/src/main/java/com/papyrus/engine/PapyrusSelectionMenuIcon.java +0 -48
  29. package/android/src/main/java/com/papyrus/engine/PapyrusTextAnnotationModel.java +0 -22
  30. package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentView.java +0 -661
  31. package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentViewManager.java +0 -49
  32. package/android/src/main/java/com/papyrus/engine/PapyrusTextStore.java +0 -43
  33. package/ios/PapyrusComicDocumentView.h +0 -21
  34. package/ios/PapyrusComicDocumentView.m +0 -547
  35. package/ios/PapyrusComicDocumentViewManager.m +0 -23
  36. package/ios/PapyrusPageRotationRegistry.h +0 -29
  37. package/ios/PapyrusPageRotationRegistry.m +0 -179
  38. package/ios/PapyrusPdfDocumentView.h +0 -55
  39. package/ios/PapyrusPdfDocumentView.m +0 -2338
  40. package/ios/PapyrusPdfDocumentViewManager.m +0 -61
  41. package/ios/PapyrusPdfPageTheme.h +0 -15
  42. package/ios/PapyrusPdfPageTheme.m +0 -218
  43. package/ios/PapyrusSelectionMenu.h +0 -27
  44. package/ios/PapyrusTextAnnotationRange.h +0 -2
  45. package/ios/PapyrusTextAnnotationRange.m +0 -29
  46. package/ios/PapyrusTextDocumentView.h +0 -32
  47. package/ios/PapyrusTextDocumentView.m +0 -518
  48. package/ios/PapyrusTextDocumentViewManager.m +0 -34
  49. package/ios/PapyrusTextStore.h +0 -13
  50. package/ios/PapyrusTextStore.m +0 -73
  51. package/third_party_licenses/BLAKE2-NOTICE.txt +0 -11
  52. package/third_party_licenses/libarchive-COPYING +0 -65
  53. package/vendor/libarchive/PapyrusComicArchive.cpp +0 -376
  54. package/vendor/libarchive/PapyrusComicArchive.h +0 -30
  55. package/vendor/libarchive/README.papyrus.md +0 -15
  56. package/vendor/libarchive/android.h +0 -192
  57. package/vendor/libarchive/config/PapyrusArchiveConfig.h +0 -71
  58. package/vendor/libarchive/libarchive/CMakeLists.txt +0 -293
  59. package/vendor/libarchive/libarchive/android_lf.h +0 -36
  60. package/vendor/libarchive/libarchive/archive.h +0 -1266
  61. package/vendor/libarchive/libarchive/archive_acl.c +0 -2025
  62. package/vendor/libarchive/libarchive/archive_acl_private.h +0 -85
  63. package/vendor/libarchive/libarchive/archive_blake2.h +0 -197
  64. package/vendor/libarchive/libarchive/archive_blake2_impl.h +0 -161
  65. package/vendor/libarchive/libarchive/archive_blake2s_ref.c +0 -369
  66. package/vendor/libarchive/libarchive/archive_blake2sp_ref.c +0 -361
  67. package/vendor/libarchive/libarchive/archive_check_magic.c +0 -183
  68. package/vendor/libarchive/libarchive/archive_cmdline.c +0 -211
  69. package/vendor/libarchive/libarchive/archive_cmdline_private.h +0 -45
  70. package/vendor/libarchive/libarchive/archive_crc32.h +0 -123
  71. package/vendor/libarchive/libarchive/archive_cryptor.c +0 -534
  72. package/vendor/libarchive/libarchive/archive_cryptor_private.h +0 -199
  73. package/vendor/libarchive/libarchive/archive_digest.c +0 -1584
  74. package/vendor/libarchive/libarchive/archive_digest_private.h +0 -431
  75. package/vendor/libarchive/libarchive/archive_disk_acl_darwin.c +0 -558
  76. package/vendor/libarchive/libarchive/archive_disk_acl_freebsd.c +0 -712
  77. package/vendor/libarchive/libarchive/archive_disk_acl_linux.c +0 -760
  78. package/vendor/libarchive/libarchive/archive_disk_acl_sunos.c +0 -824
  79. package/vendor/libarchive/libarchive/archive_endian.h +0 -234
  80. package/vendor/libarchive/libarchive/archive_entry.3 +0 -147
  81. package/vendor/libarchive/libarchive/archive_entry.c +0 -2297
  82. package/vendor/libarchive/libarchive/archive_entry.h +0 -763
  83. package/vendor/libarchive/libarchive/archive_entry_acl.3 +0 -458
  84. package/vendor/libarchive/libarchive/archive_entry_copy_bhfi.c +0 -55
  85. package/vendor/libarchive/libarchive/archive_entry_copy_stat.c +0 -82
  86. package/vendor/libarchive/libarchive/archive_entry_link_resolver.c +0 -472
  87. package/vendor/libarchive/libarchive/archive_entry_linkify.3 +0 -224
  88. package/vendor/libarchive/libarchive/archive_entry_locale.h +0 -90
  89. package/vendor/libarchive/libarchive/archive_entry_misc.3 +0 -63
  90. package/vendor/libarchive/libarchive/archive_entry_paths.3 +0 -153
  91. package/vendor/libarchive/libarchive/archive_entry_perms.3 +0 -210
  92. package/vendor/libarchive/libarchive/archive_entry_private.h +0 -205
  93. package/vendor/libarchive/libarchive/archive_entry_sparse.c +0 -156
  94. package/vendor/libarchive/libarchive/archive_entry_stat.3 +0 -274
  95. package/vendor/libarchive/libarchive/archive_entry_stat.c +0 -121
  96. package/vendor/libarchive/libarchive/archive_entry_strmode.c +0 -69
  97. package/vendor/libarchive/libarchive/archive_entry_time.3 +0 -127
  98. package/vendor/libarchive/libarchive/archive_entry_xattr.c +0 -155
  99. package/vendor/libarchive/libarchive/archive_hmac.c +0 -345
  100. package/vendor/libarchive/libarchive/archive_hmac_private.h +0 -119
  101. package/vendor/libarchive/libarchive/archive_integer.h +0 -267
  102. package/vendor/libarchive/libarchive/archive_match.c +0 -1869
  103. package/vendor/libarchive/libarchive/archive_openssl_evp_private.h +0 -54
  104. package/vendor/libarchive/libarchive/archive_openssl_hmac_private.h +0 -54
  105. package/vendor/libarchive/libarchive/archive_options.c +0 -219
  106. package/vendor/libarchive/libarchive/archive_options_private.h +0 -49
  107. package/vendor/libarchive/libarchive/archive_pack_dev.c +0 -330
  108. package/vendor/libarchive/libarchive/archive_pack_dev.h +0 -49
  109. package/vendor/libarchive/libarchive/archive_parse_date.c +0 -1173
  110. package/vendor/libarchive/libarchive/archive_pathmatch.c +0 -480
  111. package/vendor/libarchive/libarchive/archive_pathmatch.h +0 -50
  112. package/vendor/libarchive/libarchive/archive_platform.h +0 -213
  113. package/vendor/libarchive/libarchive/archive_platform_acl.h +0 -53
  114. package/vendor/libarchive/libarchive/archive_platform_stat.h +0 -45
  115. package/vendor/libarchive/libarchive/archive_platform_xattr.h +0 -45
  116. package/vendor/libarchive/libarchive/archive_ppmd7.c +0 -1173
  117. package/vendor/libarchive/libarchive/archive_ppmd7_private.h +0 -119
  118. package/vendor/libarchive/libarchive/archive_ppmd8.c +0 -1293
  119. package/vendor/libarchive/libarchive/archive_ppmd8_private.h +0 -123
  120. package/vendor/libarchive/libarchive/archive_ppmd_private.h +0 -159
  121. package/vendor/libarchive/libarchive/archive_private.h +0 -209
  122. package/vendor/libarchive/libarchive/archive_random.c +0 -274
  123. package/vendor/libarchive/libarchive/archive_random_private.h +0 -36
  124. package/vendor/libarchive/libarchive/archive_rb.c +0 -709
  125. package/vendor/libarchive/libarchive/archive_rb.h +0 -113
  126. package/vendor/libarchive/libarchive/archive_read.3 +0 -250
  127. package/vendor/libarchive/libarchive/archive_read.c +0 -1814
  128. package/vendor/libarchive/libarchive/archive_read_add_passphrase.3 +0 -72
  129. package/vendor/libarchive/libarchive/archive_read_add_passphrase.c +0 -189
  130. package/vendor/libarchive/libarchive/archive_read_append_filter.c +0 -209
  131. package/vendor/libarchive/libarchive/archive_read_data.3 +0 -128
  132. package/vendor/libarchive/libarchive/archive_read_data_into_fd.c +0 -207
  133. package/vendor/libarchive/libarchive/archive_read_disk.3 +0 -422
  134. package/vendor/libarchive/libarchive/archive_read_disk_entry_from_file.c +0 -1086
  135. package/vendor/libarchive/libarchive/archive_read_disk_posix.c +0 -2639
  136. package/vendor/libarchive/libarchive/archive_read_disk_private.h +0 -97
  137. package/vendor/libarchive/libarchive/archive_read_disk_set_standard_lookup.c +0 -315
  138. package/vendor/libarchive/libarchive/archive_read_disk_windows.c +0 -2603
  139. package/vendor/libarchive/libarchive/archive_read_extract.3 +0 -135
  140. package/vendor/libarchive/libarchive/archive_read_extract.c +0 -59
  141. package/vendor/libarchive/libarchive/archive_read_extract2.c +0 -154
  142. package/vendor/libarchive/libarchive/archive_read_filter.3 +0 -163
  143. package/vendor/libarchive/libarchive/archive_read_format.3 +0 -190
  144. package/vendor/libarchive/libarchive/archive_read_free.3 +0 -91
  145. package/vendor/libarchive/libarchive/archive_read_header.3 +0 -89
  146. package/vendor/libarchive/libarchive/archive_read_new.3 +0 -57
  147. package/vendor/libarchive/libarchive/archive_read_open.3 +0 -247
  148. package/vendor/libarchive/libarchive/archive_read_open_fd.c +0 -236
  149. package/vendor/libarchive/libarchive/archive_read_open_file.c +0 -257
  150. package/vendor/libarchive/libarchive/archive_read_open_filename.c +0 -652
  151. package/vendor/libarchive/libarchive/archive_read_open_memory.c +0 -188
  152. package/vendor/libarchive/libarchive/archive_read_private.h +0 -274
  153. package/vendor/libarchive/libarchive/archive_read_set_format.c +0 -116
  154. package/vendor/libarchive/libarchive/archive_read_set_options.3 +0 -290
  155. package/vendor/libarchive/libarchive/archive_read_set_options.c +0 -132
  156. package/vendor/libarchive/libarchive/archive_read_support_filter_all.c +0 -84
  157. package/vendor/libarchive/libarchive/archive_read_support_filter_by_code.c +0 -68
  158. package/vendor/libarchive/libarchive/archive_read_support_filter_bzip2.c +0 -360
  159. package/vendor/libarchive/libarchive/archive_read_support_filter_compress.c +0 -457
  160. package/vendor/libarchive/libarchive/archive_read_support_filter_grzip.c +0 -108
  161. package/vendor/libarchive/libarchive/archive_read_support_filter_gzip.c +0 -538
  162. package/vendor/libarchive/libarchive/archive_read_support_filter_lrzip.c +0 -119
  163. package/vendor/libarchive/libarchive/archive_read_support_filter_lz4.c +0 -829
  164. package/vendor/libarchive/libarchive/archive_read_support_filter_lzop.c +0 -493
  165. package/vendor/libarchive/libarchive/archive_read_support_filter_none.c +0 -51
  166. package/vendor/libarchive/libarchive/archive_read_support_filter_program.c +0 -497
  167. package/vendor/libarchive/libarchive/archive_read_support_filter_rpm.c +0 -249
  168. package/vendor/libarchive/libarchive/archive_read_support_filter_uu.c +0 -739
  169. package/vendor/libarchive/libarchive/archive_read_support_filter_xz.c +0 -792
  170. package/vendor/libarchive/libarchive/archive_read_support_filter_zstd.c +0 -356
  171. package/vendor/libarchive/libarchive/archive_read_support_format_7zip.c +0 -4650
  172. package/vendor/libarchive/libarchive/archive_read_support_format_all.c +0 -88
  173. package/vendor/libarchive/libarchive/archive_read_support_format_ar.c +0 -597
  174. package/vendor/libarchive/libarchive/archive_read_support_format_by_code.c +0 -76
  175. package/vendor/libarchive/libarchive/archive_read_support_format_cab.c +0 -3410
  176. package/vendor/libarchive/libarchive/archive_read_support_format_cpio.c +0 -1152
  177. package/vendor/libarchive/libarchive/archive_read_support_format_empty.c +0 -95
  178. package/vendor/libarchive/libarchive/archive_read_support_format_iso9660.c +0 -3516
  179. package/vendor/libarchive/libarchive/archive_read_support_format_lha.c +0 -2931
  180. package/vendor/libarchive/libarchive/archive_read_support_format_mtree.c +0 -2113
  181. package/vendor/libarchive/libarchive/archive_read_support_format_rar.c +0 -3932
  182. package/vendor/libarchive/libarchive/archive_read_support_format_rar5.c +0 -4501
  183. package/vendor/libarchive/libarchive/archive_read_support_format_raw.c +0 -194
  184. package/vendor/libarchive/libarchive/archive_read_support_format_tar.c +0 -3785
  185. package/vendor/libarchive/libarchive/archive_read_support_format_warc.c +0 -875
  186. package/vendor/libarchive/libarchive/archive_read_support_format_xar.c +0 -3770
  187. package/vendor/libarchive/libarchive/archive_read_support_format_zip.c +0 -4710
  188. package/vendor/libarchive/libarchive/archive_string.c +0 -4391
  189. package/vendor/libarchive/libarchive/archive_string.h +0 -244
  190. package/vendor/libarchive/libarchive/archive_string_composition.h +0 -2289
  191. package/vendor/libarchive/libarchive/archive_string_sprintf.c +0 -200
  192. package/vendor/libarchive/libarchive/archive_time.c +0 -168
  193. package/vendor/libarchive/libarchive/archive_time_private.h +0 -47
  194. package/vendor/libarchive/libarchive/archive_util.3 +0 -239
  195. package/vendor/libarchive/libarchive/archive_util.c +0 -668
  196. package/vendor/libarchive/libarchive/archive_version_details.c +0 -516
  197. package/vendor/libarchive/libarchive/archive_virtual.c +0 -162
  198. package/vendor/libarchive/libarchive/archive_windows.c +0 -1035
  199. package/vendor/libarchive/libarchive/archive_windows.h +0 -332
  200. package/vendor/libarchive/libarchive/archive_write.3 +0 -266
  201. package/vendor/libarchive/libarchive/archive_write.c +0 -896
  202. package/vendor/libarchive/libarchive/archive_write_add_filter.c +0 -71
  203. package/vendor/libarchive/libarchive/archive_write_add_filter_b64encode.c +0 -329
  204. package/vendor/libarchive/libarchive/archive_write_add_filter_by_name.c +0 -76
  205. package/vendor/libarchive/libarchive/archive_write_add_filter_bzip2.c +0 -411
  206. package/vendor/libarchive/libarchive/archive_write_add_filter_compress.c +0 -459
  207. package/vendor/libarchive/libarchive/archive_write_add_filter_grzip.c +0 -143
  208. package/vendor/libarchive/libarchive/archive_write_add_filter_gzip.c +0 -493
  209. package/vendor/libarchive/libarchive/archive_write_add_filter_lrzip.c +0 -214
  210. package/vendor/libarchive/libarchive/archive_write_add_filter_lz4.c +0 -710
  211. package/vendor/libarchive/libarchive/archive_write_add_filter_lzop.c +0 -500
  212. package/vendor/libarchive/libarchive/archive_write_add_filter_none.c +0 -42
  213. package/vendor/libarchive/libarchive/archive_write_add_filter_program.c +0 -398
  214. package/vendor/libarchive/libarchive/archive_write_add_filter_uuencode.c +0 -320
  215. package/vendor/libarchive/libarchive/archive_write_add_filter_xz.c +0 -547
  216. package/vendor/libarchive/libarchive/archive_write_add_filter_zstd.c +0 -608
  217. package/vendor/libarchive/libarchive/archive_write_blocksize.3 +0 -112
  218. package/vendor/libarchive/libarchive/archive_write_data.3 +0 -88
  219. package/vendor/libarchive/libarchive/archive_write_disk.3 +0 -360
  220. package/vendor/libarchive/libarchive/archive_write_disk_posix.c +0 -4789
  221. package/vendor/libarchive/libarchive/archive_write_disk_private.h +0 -43
  222. package/vendor/libarchive/libarchive/archive_write_disk_set_standard_lookup.c +0 -265
  223. package/vendor/libarchive/libarchive/archive_write_disk_windows.c +0 -2952
  224. package/vendor/libarchive/libarchive/archive_write_filter.3 +0 -140
  225. package/vendor/libarchive/libarchive/archive_write_finish_entry.3 +0 -77
  226. package/vendor/libarchive/libarchive/archive_write_format.3 +0 -187
  227. package/vendor/libarchive/libarchive/archive_write_free.3 +0 -94
  228. package/vendor/libarchive/libarchive/archive_write_header.3 +0 -71
  229. package/vendor/libarchive/libarchive/archive_write_new.3 +0 -56
  230. package/vendor/libarchive/libarchive/archive_write_open.3 +0 -270
  231. package/vendor/libarchive/libarchive/archive_write_open_fd.c +0 -141
  232. package/vendor/libarchive/libarchive/archive_write_open_file.c +0 -102
  233. package/vendor/libarchive/libarchive/archive_write_open_filename.c +0 -272
  234. package/vendor/libarchive/libarchive/archive_write_open_memory.c +0 -110
  235. package/vendor/libarchive/libarchive/archive_write_private.h +0 -166
  236. package/vendor/libarchive/libarchive/archive_write_set_format.c +0 -124
  237. package/vendor/libarchive/libarchive/archive_write_set_format_7zip.c +0 -2571
  238. package/vendor/libarchive/libarchive/archive_write_set_format_ar.c +0 -540
  239. package/vendor/libarchive/libarchive/archive_write_set_format_by_name.c +0 -93
  240. package/vendor/libarchive/libarchive/archive_write_set_format_cpio.c +0 -11
  241. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_binary.c +0 -618
  242. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_newc.c +0 -457
  243. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_odc.c +0 -508
  244. package/vendor/libarchive/libarchive/archive_write_set_format_filter_by_ext.c +0 -141
  245. package/vendor/libarchive/libarchive/archive_write_set_format_gnutar.c +0 -790
  246. package/vendor/libarchive/libarchive/archive_write_set_format_iso9660.c +0 -8216
  247. package/vendor/libarchive/libarchive/archive_write_set_format_mtree.c +0 -2307
  248. package/vendor/libarchive/libarchive/archive_write_set_format_pax.c +0 -2249
  249. package/vendor/libarchive/libarchive/archive_write_set_format_private.h +0 -40
  250. package/vendor/libarchive/libarchive/archive_write_set_format_raw.c +0 -123
  251. package/vendor/libarchive/libarchive/archive_write_set_format_shar.c +0 -650
  252. package/vendor/libarchive/libarchive/archive_write_set_format_ustar.c +0 -768
  253. package/vendor/libarchive/libarchive/archive_write_set_format_v7tar.c +0 -648
  254. package/vendor/libarchive/libarchive/archive_write_set_format_warc.c +0 -491
  255. package/vendor/libarchive/libarchive/archive_write_set_format_xar.c +0 -3799
  256. package/vendor/libarchive/libarchive/archive_write_set_format_zip.c +0 -2548
  257. package/vendor/libarchive/libarchive/archive_write_set_options.3 +0 -779
  258. package/vendor/libarchive/libarchive/archive_write_set_options.c +0 -129
  259. package/vendor/libarchive/libarchive/archive_write_set_passphrase.3 +0 -72
  260. package/vendor/libarchive/libarchive/archive_write_set_passphrase.c +0 -95
  261. package/vendor/libarchive/libarchive/archive_xxhash.h +0 -48
  262. package/vendor/libarchive/libarchive/config_freebsd.h +0 -275
  263. package/vendor/libarchive/libarchive/cpio.5 +0 -389
  264. package/vendor/libarchive/libarchive/filter_fork.h +0 -44
  265. package/vendor/libarchive/libarchive/filter_fork_posix.c +0 -269
  266. package/vendor/libarchive/libarchive/filter_fork_windows.c +0 -270
  267. package/vendor/libarchive/libarchive/libarchive-formats.5 +0 -478
  268. package/vendor/libarchive/libarchive/libarchive.3 +0 -297
  269. package/vendor/libarchive/libarchive/libarchive_changes.3 +0 -339
  270. package/vendor/libarchive/libarchive/libarchive_internals.3 +0 -363
  271. package/vendor/libarchive/libarchive/module.modulemap +0 -34
  272. package/vendor/libarchive/libarchive/mtree.5 +0 -323
  273. package/vendor/libarchive/libarchive/tar.5 +0 -947
  274. package/vendor/libarchive/libarchive/xxhash.c +0 -531
@@ -1,1035 +0,0 @@
1
- /*-
2
- * Copyright (c) 2009-2011 Michihiro NAKAJIMA
3
- * Copyright (c) 2003-2007 Kees Zeelenberg
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
- /*
28
- * A set of compatibility glue for building libarchive on Windows platforms.
29
- *
30
- * Originally created as "libarchive-nonposix.c" by Kees Zeelenberg
31
- * for the GnuWin32 project, trimmed significantly by Tim Kientzle.
32
- *
33
- * Much of the original file was unnecessary for libarchive, because
34
- * many of the features it emulated were not strictly necessary for
35
- * libarchive. I hope for this to shrink further as libarchive
36
- * internals are gradually reworked to sit more naturally on both
37
- * POSIX and Windows. Any ideas for this are greatly appreciated.
38
- *
39
- * The biggest remaining issue is the dev/ino emulation; libarchive
40
- * has a couple of public APIs that rely on dev/ino uniquely
41
- * identifying a file. This doesn't match well with Windows. I'm
42
- * considering alternative APIs.
43
- */
44
-
45
- #if defined(_WIN32) && !defined(__CYGWIN__)
46
-
47
- #include "archive_platform.h"
48
- #include "archive_platform_stat.h"
49
- #include "archive_private.h"
50
- #include "archive_entry.h"
51
- #include "archive_time_private.h"
52
- #include <ctype.h>
53
- #include <errno.h>
54
- #include <stddef.h>
55
- #ifdef HAVE_SYS_UTIME_H
56
- #include <sys/utime.h>
57
- #endif
58
- #include <sys/stat.h>
59
- #include <locale.h>
60
- #include <process.h>
61
- #include <stdlib.h>
62
- #include <wchar.h>
63
- #include <windows.h>
64
- #include <share.h>
65
-
66
- struct ustat {
67
- int64_t st_atime;
68
- uint32_t st_atime_nsec;
69
- int64_t st_ctime;
70
- uint32_t st_ctime_nsec;
71
- int64_t st_mtime;
72
- uint32_t st_mtime_nsec;
73
- gid_t st_gid;
74
- /* 64bits ino */
75
- int64_t st_ino;
76
- mode_t st_mode;
77
- uint32_t st_nlink;
78
- uint64_t st_size;
79
- uid_t st_uid;
80
- dev_t st_dev;
81
- dev_t st_rdev;
82
- };
83
-
84
- /* Transform 64-bits ino into 32-bits by hashing.
85
- * You do not forget that really unique number size is 64-bits.
86
- */
87
- #define INOSIZE (8*sizeof(ino_t)) /* 32 */
88
- static __inline ino_t
89
- getino(struct ustat *ub)
90
- {
91
- ULARGE_INTEGER ino64;
92
- ino64.QuadPart = ub->st_ino;
93
- /* I don't know this hashing is correct way */
94
- return ((ino_t)(ino64.LowPart ^ (ino64.LowPart >> INOSIZE)));
95
- }
96
-
97
- /*
98
- * Prepend "\\?\" to the path name and convert it to unicode to permit
99
- * an extended-length path for a maximum total path length of 32767
100
- * characters.
101
- * see also http://msdn.microsoft.com/en-us/library/aa365247.aspx
102
- */
103
- wchar_t *
104
- __la_win_permissive_name(const char *name)
105
- {
106
- wchar_t *wn;
107
- wchar_t *ws;
108
- size_t ll;
109
-
110
- ll = strlen(name);
111
- wn = malloc((ll + 1) * sizeof(wchar_t));
112
- if (wn == NULL)
113
- return (NULL);
114
- ll = mbstowcs(wn, name, ll);
115
- if (ll == (size_t)-1) {
116
- free(wn);
117
- return (NULL);
118
- }
119
- wn[ll] = L'\0';
120
- ws = __la_win_permissive_name_w(wn);
121
- free(wn);
122
- return (ws);
123
- }
124
-
125
- wchar_t *
126
- __la_win_permissive_name_w(const wchar_t *wname)
127
- {
128
- wchar_t *wn, *wnp;
129
- wchar_t *ws, *wsp;
130
- DWORD l, len, slen;
131
- int unc;
132
-
133
- /* Get a full-pathname. */
134
- l = GetFullPathNameW(wname, 0, NULL, NULL);
135
- if (l == 0)
136
- return (NULL);
137
- /* NOTE: GetFullPathNameW has a bug that if the length of the file
138
- * name is just 1 then it returns incomplete buffer size. Thus, we
139
- * have to add three to the size to allocate a sufficient buffer
140
- * size for the full-pathname of the file name. */
141
- l += 3;
142
- wnp = malloc(l * sizeof(wchar_t));
143
- if (wnp == NULL)
144
- return (NULL);
145
- len = GetFullPathNameW(wname, l, wnp, NULL);
146
- wn = wnp;
147
-
148
- if (wnp[0] == L'\\' && wnp[1] == L'\\' &&
149
- wnp[2] == L'?' && wnp[3] == L'\\')
150
- /* We have already a permissive name. */
151
- return (wn);
152
-
153
- if (wnp[0] == L'\\' && wnp[1] == L'\\' &&
154
- wnp[2] == L'.' && wnp[3] == L'\\') {
155
- /* This is a device name */
156
- if (((wnp[4] >= L'a' && wnp[4] <= L'z') ||
157
- (wnp[4] >= L'A' && wnp[4] <= L'Z')) &&
158
- wnp[5] == L':' && wnp[6] == L'\\')
159
- wnp[2] = L'?';/* Not device name. */
160
- return (wn);
161
- }
162
-
163
- unc = 0;
164
- if (wnp[0] == L'\\' && wnp[1] == L'\\' && wnp[2] != L'\\') {
165
- wchar_t *p = &wnp[2];
166
-
167
- /* Skip server-name letters. */
168
- while (*p != L'\\' && *p != L'\0')
169
- ++p;
170
- if (*p == L'\\') {
171
- wchar_t *rp = ++p;
172
- /* Skip share-name letters. */
173
- while (*p != L'\\' && *p != L'\0')
174
- ++p;
175
- if (*p == L'\\' && p != rp) {
176
- /* Now, match patterns such as
177
- * "\\server-name\share-name\" */
178
- wnp += 2;
179
- len -= 2;
180
- unc = 1;
181
- }
182
- }
183
- }
184
-
185
- slen = 4 + (unc * 4) + len + 1;
186
- ws = wsp = malloc(slen * sizeof(wchar_t));
187
- if (ws == NULL) {
188
- free(wn);
189
- return (NULL);
190
- }
191
- /* prepend "\\?\" */
192
- wcsncpy(wsp, L"\\\\?\\", 4);
193
- wsp += 4;
194
- slen -= 4;
195
- if (unc) {
196
- /* append "UNC\" ---> "\\?\UNC\" */
197
- wcsncpy(wsp, L"UNC\\", 4);
198
- wsp += 4;
199
- slen -= 4;
200
- }
201
- wcsncpy(wsp, wnp, slen);
202
- wsp[slen - 1] = L'\0'; /* Ensure null termination. */
203
- free(wn);
204
- return (ws);
205
- }
206
-
207
- /*
208
- * Create a file handle.
209
- * This can exceed MAX_PATH limitation.
210
- */
211
- static HANDLE
212
- la_CreateFile(const char *path, DWORD dwDesiredAccess, DWORD dwShareMode,
213
- LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
214
- DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
215
- {
216
- wchar_t *wpath;
217
- HANDLE handle;
218
- # if _WIN32_WINNT >= 0x0602 /* _WIN32_WINNT_WIN8 */
219
- CREATEFILE2_EXTENDED_PARAMETERS createExParams;
220
- #endif
221
-
222
- #if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
223
- handle = CreateFileA(path, dwDesiredAccess, dwShareMode,
224
- lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes,
225
- hTemplateFile);
226
- if (handle != INVALID_HANDLE_VALUE)
227
- return (handle);
228
- if (GetLastError() != ERROR_PATH_NOT_FOUND)
229
- return (handle);
230
- #endif
231
- wpath = __la_win_permissive_name(path);
232
- if (wpath == NULL)
233
- return INVALID_HANDLE_VALUE;
234
- # if _WIN32_WINNT >= 0x0602 /* _WIN32_WINNT_WIN8 */
235
- ZeroMemory(&createExParams, sizeof(createExParams));
236
- createExParams.dwSize = sizeof(createExParams);
237
- createExParams.dwFileAttributes = dwFlagsAndAttributes & 0xFFFF;
238
- createExParams.dwFileFlags = dwFlagsAndAttributes & 0xFFF00000;
239
- createExParams.dwSecurityQosFlags = dwFlagsAndAttributes & 0x000F0000;
240
- createExParams.lpSecurityAttributes = lpSecurityAttributes;
241
- createExParams.hTemplateFile = hTemplateFile;
242
- handle = CreateFile2(wpath, dwDesiredAccess, dwShareMode,
243
- dwCreationDisposition, &createExParams);
244
- #else /* !WINAPI_PARTITION_DESKTOP */
245
- handle = CreateFileW(wpath, dwDesiredAccess, dwShareMode,
246
- lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes,
247
- hTemplateFile);
248
- #endif /* !WINAPI_PARTITION_DESKTOP */
249
- free(wpath);
250
- return (handle);
251
- }
252
-
253
- #if defined(__LA_LSEEK_NEEDED)
254
- __int64
255
- __la_lseek(int fd, __int64 offset, int whence)
256
- {
257
- LARGE_INTEGER distance;
258
- LARGE_INTEGER newpointer;
259
- HANDLE handle;
260
-
261
- if (fd < 0) {
262
- errno = EBADF;
263
- return (-1);
264
- }
265
- handle = (HANDLE)_get_osfhandle(fd);
266
- if (GetFileType(handle) != FILE_TYPE_DISK) {
267
- errno = EBADF;
268
- return (-1);
269
- }
270
- distance.QuadPart = offset;
271
- if (!SetFilePointerEx(handle, distance, &newpointer, whence)) {
272
- DWORD lasterr;
273
-
274
- lasterr = GetLastError();
275
- if (lasterr == ERROR_BROKEN_PIPE)
276
- return (0);
277
- if (lasterr == ERROR_ACCESS_DENIED)
278
- errno = EBADF;
279
- else
280
- la_dosmaperr(lasterr);
281
- return (-1);
282
- }
283
- return (newpointer.QuadPart);
284
- }
285
- #endif
286
-
287
- /* This can exceed MAX_PATH limitation. */
288
- int
289
- __la_open(const char *path, int flags, ...)
290
- {
291
- va_list ap;
292
- wchar_t *ws;
293
- int r, pmode;
294
- DWORD attr;
295
-
296
- va_start(ap, flags);
297
- pmode = va_arg(ap, int);
298
- va_end(ap);
299
- ws = NULL;
300
-
301
- /* _(w)sopen_s fails if we provide any other modes */
302
- pmode = pmode & (_S_IREAD | _S_IWRITE);
303
-
304
- if ((flags & ~O_BINARY) == O_RDONLY) {
305
- /*
306
- * When we open a directory, _open function returns
307
- * "Permission denied" error.
308
- */
309
- attr = GetFileAttributesA(path);
310
- #if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
311
- if (attr == (DWORD)-1 && GetLastError() == ERROR_PATH_NOT_FOUND)
312
- #endif
313
- {
314
- ws = __la_win_permissive_name(path);
315
- if (ws == NULL) {
316
- errno = EINVAL;
317
- return (-1);
318
- }
319
- attr = GetFileAttributesW(ws);
320
- }
321
- if (attr == (DWORD)-1) {
322
- la_dosmaperr(GetLastError());
323
- free(ws);
324
- return (-1);
325
- }
326
- if (attr & FILE_ATTRIBUTE_DIRECTORY) {
327
- HANDLE handle;
328
- #if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
329
- if (ws != NULL)
330
- handle = CreateFileW(ws, 0, 0, NULL,
331
- OPEN_EXISTING,
332
- FILE_FLAG_BACKUP_SEMANTICS |
333
- FILE_ATTRIBUTE_READONLY,
334
- NULL);
335
- else
336
- handle = CreateFileA(path, 0, 0, NULL,
337
- OPEN_EXISTING,
338
- FILE_FLAG_BACKUP_SEMANTICS |
339
- FILE_ATTRIBUTE_READONLY,
340
- NULL);
341
- #else /* !WINAPI_PARTITION_DESKTOP */
342
- CREATEFILE2_EXTENDED_PARAMETERS createExParams;
343
- ZeroMemory(&createExParams, sizeof(createExParams));
344
- createExParams.dwSize = sizeof(createExParams);
345
- createExParams.dwFileAttributes = FILE_ATTRIBUTE_READONLY;
346
- createExParams.dwFileFlags = FILE_FLAG_BACKUP_SEMANTICS;
347
- handle = CreateFile2(ws, 0, 0,
348
- OPEN_EXISTING, &createExParams);
349
- #endif /* !WINAPI_PARTITION_DESKTOP */
350
- free(ws);
351
- if (handle == INVALID_HANDLE_VALUE) {
352
- la_dosmaperr(GetLastError());
353
- return (-1);
354
- }
355
- r = _open_osfhandle((intptr_t)handle, _O_RDONLY);
356
- return (r);
357
- }
358
- }
359
- if (ws == NULL) {
360
- #if defined(__BORLANDC__)
361
- /* Borland has no mode argument.
362
- TODO: Fix mode of new file. */
363
- r = _open(path, flags);
364
- #else
365
- _sopen_s(&r, path, flags, _SH_DENYNO, pmode);
366
- #endif
367
- if (r < 0 && errno == EACCES && (flags & O_CREAT) != 0) {
368
- /* Simulate other POSIX system action to pass our test suite. */
369
- attr = GetFileAttributesA(path);
370
- if (attr == (DWORD)-1)
371
- la_dosmaperr(GetLastError());
372
- else if (attr & FILE_ATTRIBUTE_DIRECTORY)
373
- errno = EISDIR;
374
- else
375
- errno = EACCES;
376
- return (-1);
377
- }
378
- if (r >= 0 || errno != ENOENT)
379
- return (r);
380
- ws = __la_win_permissive_name(path);
381
- if (ws == NULL) {
382
- errno = EINVAL;
383
- return (-1);
384
- }
385
- }
386
- _wsopen_s(&r, ws, flags, _SH_DENYNO, pmode);
387
- if (r < 0 && errno == EACCES && (flags & O_CREAT) != 0) {
388
- /* Simulate other POSIX system action to pass our test suite. */
389
- attr = GetFileAttributesW(ws);
390
- if (attr == (DWORD)-1)
391
- la_dosmaperr(GetLastError());
392
- else if (attr & FILE_ATTRIBUTE_DIRECTORY)
393
- errno = EISDIR;
394
- else
395
- errno = EACCES;
396
- }
397
- free(ws);
398
- return (r);
399
- }
400
-
401
- int
402
- __la_wopen(const wchar_t *path, int flags, ...)
403
- {
404
- va_list ap;
405
- wchar_t *fullpath;
406
- int r, pmode;
407
- DWORD attr;
408
-
409
- va_start(ap, flags);
410
- pmode = va_arg(ap, int);
411
- va_end(ap);
412
- fullpath = NULL;
413
-
414
- /* _(w)sopen_s fails if we provide any other modes */
415
- pmode = pmode & (_S_IREAD | _S_IWRITE);
416
-
417
- if ((flags & ~O_BINARY) == O_RDONLY) {
418
- /*
419
- * When we open a directory, _open function returns
420
- * "Permission denied" error.
421
- */
422
- attr = GetFileAttributesW(path);
423
- #if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
424
- if (attr == (DWORD)-1 && GetLastError() == ERROR_PATH_NOT_FOUND)
425
- #endif
426
- {
427
- fullpath = __la_win_permissive_name_w(path);
428
- if (fullpath == NULL) {
429
- errno = EINVAL;
430
- return (-1);
431
- }
432
- path = fullpath;
433
- attr = GetFileAttributesW(fullpath);
434
- }
435
- if (attr == (DWORD)-1) {
436
- la_dosmaperr(GetLastError());
437
- free(fullpath);
438
- return (-1);
439
- }
440
- if (attr & FILE_ATTRIBUTE_DIRECTORY) {
441
- HANDLE handle;
442
- #if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
443
- if (fullpath != NULL)
444
- handle = CreateFileW(fullpath, 0, 0, NULL,
445
- OPEN_EXISTING,
446
- FILE_FLAG_BACKUP_SEMANTICS |
447
- FILE_ATTRIBUTE_READONLY,
448
- NULL);
449
- else
450
- handle = CreateFileW(path, 0, 0, NULL,
451
- OPEN_EXISTING,
452
- FILE_FLAG_BACKUP_SEMANTICS |
453
- FILE_ATTRIBUTE_READONLY,
454
- NULL);
455
- #else /* !WINAPI_PARTITION_DESKTOP */
456
- CREATEFILE2_EXTENDED_PARAMETERS createExParams;
457
- ZeroMemory(&createExParams, sizeof(createExParams));
458
- createExParams.dwSize = sizeof(createExParams);
459
- createExParams.dwFileAttributes = FILE_ATTRIBUTE_READONLY;
460
- createExParams.dwFileFlags = FILE_FLAG_BACKUP_SEMANTICS;
461
- handle = CreateFile2(fullpath, 0, 0,
462
- OPEN_EXISTING, &createExParams);
463
- #endif /* !WINAPI_PARTITION_DESKTOP */
464
- free(fullpath);
465
- if (handle == INVALID_HANDLE_VALUE) {
466
- la_dosmaperr(GetLastError());
467
- return (-1);
468
- }
469
- r = _open_osfhandle((intptr_t)handle, _O_RDONLY);
470
- return (r);
471
- }
472
- }
473
- _wsopen_s(&r, path, flags, _SH_DENYNO, pmode);
474
- if (r < 0 && errno == EACCES && (flags & O_CREAT) != 0) {
475
- /* Simulate other POSIX system action to pass our test suite. */
476
- attr = GetFileAttributesW(path);
477
- if (attr == (DWORD)-1)
478
- la_dosmaperr(GetLastError());
479
- else if (attr & FILE_ATTRIBUTE_DIRECTORY)
480
- errno = EISDIR;
481
- else
482
- errno = EACCES;
483
- }
484
- free(fullpath);
485
- return (r);
486
- }
487
-
488
- ssize_t
489
- __la_read(int fd, void *buf, size_t nbytes)
490
- {
491
- HANDLE handle;
492
- DWORD bytes_read, lasterr;
493
- int r;
494
-
495
- #ifdef _WIN64
496
- if (nbytes > UINT32_MAX)
497
- nbytes = UINT32_MAX;
498
- #endif
499
- if (fd < 0) {
500
- errno = EBADF;
501
- return (-1);
502
- }
503
- /* Do not pass 0 to third parameter of ReadFile(), read bytes.
504
- * This will not return to application side. */
505
- if (nbytes == 0)
506
- return (0);
507
- handle = (HANDLE)_get_osfhandle(fd);
508
- r = ReadFile(handle, buf, (uint32_t)nbytes,
509
- &bytes_read, NULL);
510
- if (r == 0) {
511
- lasterr = GetLastError();
512
- if (lasterr == ERROR_NO_DATA) {
513
- errno = EAGAIN;
514
- return (-1);
515
- }
516
- if (lasterr == ERROR_BROKEN_PIPE)
517
- return (0);
518
- if (lasterr == ERROR_ACCESS_DENIED)
519
- errno = EBADF;
520
- else
521
- la_dosmaperr(lasterr);
522
- return (-1);
523
- }
524
- return ((ssize_t)bytes_read);
525
- }
526
-
527
- /* Stat by handle
528
- * Windows' stat() does not accept the path added "\\?\" especially "?"
529
- * character.
530
- * It means we cannot access the long name path longer than MAX_PATH.
531
- * So I've implemented a function similar to Windows' stat() to access the
532
- * long name path.
533
- * And I've added some feature.
534
- * 1. set st_ino by nFileIndexHigh and nFileIndexLow of
535
- * BY_HANDLE_FILE_INFORMATION.
536
- * 2. set st_nlink by nNumberOfLinks of BY_HANDLE_FILE_INFORMATION.
537
- * 3. set st_dev by dwVolumeSerialNumber by BY_HANDLE_FILE_INFORMATION.
538
- */
539
- static int
540
- __hstat(HANDLE handle, struct ustat *st)
541
- {
542
- BY_HANDLE_FILE_INFORMATION info;
543
- ULARGE_INTEGER ino64;
544
- DWORD ftype;
545
- mode_t mode;
546
-
547
- switch (ftype = GetFileType(handle)) {
548
- case FILE_TYPE_UNKNOWN:
549
- errno = EBADF;
550
- return (-1);
551
- case FILE_TYPE_CHAR:
552
- case FILE_TYPE_PIPE:
553
- if (ftype == FILE_TYPE_CHAR) {
554
- st->st_mode = S_IFCHR;
555
- st->st_size = 0;
556
- } else {
557
- DWORD avail;
558
-
559
- st->st_mode = S_IFIFO;
560
- if (PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL))
561
- st->st_size = avail;
562
- else
563
- st->st_size = 0;
564
- }
565
- st->st_atime = 0;
566
- st->st_atime_nsec = 0;
567
- st->st_mtime = 0;
568
- st->st_mtime_nsec = 0;
569
- st->st_ctime = 0;
570
- st->st_ctime_nsec = 0;
571
- st->st_ino = 0;
572
- st->st_nlink = 1;
573
- st->st_uid = 0;
574
- st->st_gid = 0;
575
- st->st_rdev = 0;
576
- st->st_dev = 0;
577
- return (0);
578
- case FILE_TYPE_DISK:
579
- break;
580
- default:
581
- /* This ftype is undocumented type. */
582
- la_dosmaperr(GetLastError());
583
- return (-1);
584
- }
585
-
586
- ZeroMemory(&info, sizeof(info));
587
- if (!GetFileInformationByHandle (handle, &info)) {
588
- la_dosmaperr(GetLastError());
589
- return (-1);
590
- }
591
-
592
- mode = S_IRUSR | S_IRGRP | S_IROTH;
593
- if ((info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0)
594
- mode |= S_IWUSR | S_IWGRP | S_IWOTH;
595
- if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
596
- mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
597
- else
598
- mode |= S_IFREG;
599
- st->st_mode = mode;
600
-
601
- ntfs_to_unix(FILETIME_to_ntfs(&info.ftLastAccessTime), &st->st_atime, &st->st_atime_nsec);
602
- ntfs_to_unix(FILETIME_to_ntfs(&info.ftLastWriteTime), &st->st_mtime, &st->st_mtime_nsec);
603
- ntfs_to_unix(FILETIME_to_ntfs(&info.ftCreationTime), &st->st_ctime, &st->st_ctime_nsec);
604
- st->st_size =
605
- ((int64_t)(info.nFileSizeHigh) * ((int64_t)MAXDWORD + 1))
606
- + (int64_t)(info.nFileSizeLow);
607
- #ifdef SIMULATE_WIN_STAT
608
- st->st_ino = 0;
609
- st->st_nlink = 1;
610
- st->st_dev = 0;
611
- #else
612
- /* Getting FileIndex as i-node. We should remove a sequence which
613
- * is high-16-bits of nFileIndexHigh. */
614
- ino64.HighPart = info.nFileIndexHigh & 0x0000FFFFUL;
615
- ino64.LowPart = info.nFileIndexLow;
616
- st->st_ino = ino64.QuadPart;
617
- st->st_nlink = info.nNumberOfLinks;
618
- if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
619
- ++st->st_nlink;/* Add parent directory. */
620
- st->st_dev = info.dwVolumeSerialNumber;
621
- #endif
622
- st->st_uid = 0;
623
- st->st_gid = 0;
624
- st->st_rdev = 0;
625
- return (0);
626
- }
627
-
628
- static void
629
- copy_stat(struct stat *st, struct ustat *us)
630
- {
631
- st->st_atime = us->st_atime;
632
- st->st_ctime = us->st_ctime;
633
- st->st_mtime = us->st_mtime;
634
- st->st_gid = us->st_gid;
635
- st->st_ino = getino(us);
636
- st->st_mode = us->st_mode;
637
- st->st_nlink = us->st_nlink;
638
- st->st_size = (off_t)us->st_size;
639
- if (st->st_size < 0 || (uint64_t)st->st_size != us->st_size)
640
- st->st_size = 0;
641
- st->st_uid = us->st_uid;
642
- st->st_dev = us->st_dev;
643
- st->st_rdev = us->st_rdev;
644
- }
645
-
646
- /*
647
- * TODO: Remove a use of __la_fstat and __la_stat.
648
- * We should use GetFileInformationByHandle in place
649
- * where We still use the *stat functions.
650
- */
651
- int
652
- __la_fstat(int fd, struct stat *st)
653
- {
654
- struct ustat u;
655
- int ret;
656
-
657
- if (fd < 0) {
658
- errno = EBADF;
659
- return (-1);
660
- }
661
- ret = __hstat((HANDLE)_get_osfhandle(fd), &u);
662
- if (ret >= 0) {
663
- copy_stat(st, &u);
664
- if (u.st_mode & (S_IFCHR | S_IFIFO)) {
665
- st->st_dev = fd;
666
- st->st_rdev = fd;
667
- }
668
- }
669
- return (ret);
670
- }
671
-
672
- /* This can exceed MAX_PATH limitation. */
673
- int
674
- __la_stat(const char *path, struct stat *st)
675
- {
676
- HANDLE handle;
677
- struct ustat u;
678
- int ret;
679
-
680
- handle = la_CreateFile(path, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING,
681
- FILE_FLAG_BACKUP_SEMANTICS,
682
- NULL);
683
- if (handle == INVALID_HANDLE_VALUE) {
684
- la_dosmaperr(GetLastError());
685
- return (-1);
686
- }
687
- ret = __hstat(handle, &u);
688
- CloseHandle(handle);
689
- if (ret >= 0) {
690
- char *p;
691
-
692
- copy_stat(st, &u);
693
- p = strrchr(path, '.');
694
- if (p != NULL && strlen(p) == 4) {
695
- char exttype[4];
696
-
697
- ++ p;
698
- exttype[0] = toupper(*p++);
699
- exttype[1] = toupper(*p++);
700
- exttype[2] = toupper(*p++);
701
- exttype[3] = '\0';
702
- if (!strcmp(exttype, "EXE") || !strcmp(exttype, "CMD") ||
703
- !strcmp(exttype, "BAT") || !strcmp(exttype, "COM"))
704
- st->st_mode |= S_IXUSR | S_IXGRP | S_IXOTH;
705
- }
706
- }
707
- return (ret);
708
- }
709
-
710
- static void
711
- copy_seek_stat(la_seek_stat_t *st, struct ustat *us)
712
- {
713
- st->st_mtime = us->st_mtime;
714
- st->st_gid = us->st_gid;
715
- st->st_ino = getino(us);
716
- st->st_mode = us->st_mode;
717
- st->st_nlink = us->st_nlink;
718
- st->st_size = (la_seek_t)us->st_size;
719
- if (st->st_size < 0 || (uint64_t)st->st_size != us->st_size)
720
- st->st_size = -1;
721
- st->st_uid = us->st_uid;
722
- st->st_dev = us->st_dev;
723
- st->st_rdev = us->st_rdev;
724
- }
725
-
726
- int
727
- __la_seek_fstat(int fd, la_seek_stat_t *st)
728
- {
729
- struct ustat u;
730
- int ret;
731
-
732
- ret = __hstat((HANDLE)_get_osfhandle(fd), &u);
733
- if (ret >= 0)
734
- copy_seek_stat(st, &u);
735
- return (ret);
736
- }
737
-
738
- int
739
- __la_seek_stat(const char *path, la_seek_stat_t *st)
740
- {
741
- HANDLE handle;
742
- struct ustat u;
743
- int ret;
744
-
745
- handle = la_CreateFile(path, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING,
746
- FILE_FLAG_BACKUP_SEMANTICS,
747
- NULL);
748
- if (handle == INVALID_HANDLE_VALUE) {
749
- la_dosmaperr(GetLastError());
750
- return (-1);
751
- }
752
- ret = __hstat(handle, &u);
753
- CloseHandle(handle);
754
- copy_seek_stat(st, &u);
755
- return (ret);
756
- }
757
-
758
- /*
759
- * This waitpid is limited implementation.
760
- */
761
- pid_t
762
- __la_waitpid(HANDLE child, int *status, int option)
763
- {
764
- DWORD cs;
765
-
766
- (void)option;/* UNUSED */
767
- do {
768
- if (GetExitCodeProcess(child, &cs) == 0) {
769
- la_dosmaperr(GetLastError());
770
- CloseHandle(child);
771
- *status = 0;
772
- return (-1);
773
- }
774
- } while (cs == STILL_ACTIVE);
775
-
776
- CloseHandle(child);
777
- *status = (int)(cs & 0xff);
778
- return (0);
779
- }
780
-
781
- ssize_t
782
- __la_write(int fd, const void *buf, size_t nbytes)
783
- {
784
- DWORD bytes_written;
785
-
786
- #ifdef _WIN64
787
- if (nbytes > UINT32_MAX)
788
- nbytes = UINT32_MAX;
789
- #endif
790
- if (fd < 0) {
791
- errno = EBADF;
792
- return (-1);
793
- }
794
- if (!WriteFile((HANDLE)_get_osfhandle(fd), buf, (uint32_t)nbytes,
795
- &bytes_written, NULL)) {
796
- DWORD lasterr;
797
-
798
- lasterr = GetLastError();
799
- if (lasterr == ERROR_ACCESS_DENIED)
800
- errno = EBADF;
801
- else
802
- la_dosmaperr(lasterr);
803
- return (-1);
804
- }
805
- return (bytes_written);
806
- }
807
-
808
- /*
809
- * Replace the Windows path separator '\' with '/'.
810
- */
811
- static int
812
- replace_pathseparator(struct archive_wstring *ws, const wchar_t *wp)
813
- {
814
- wchar_t *w;
815
- size_t path_length;
816
-
817
- if (wp == NULL)
818
- return(0);
819
- if (wcschr(wp, L'\\') == NULL)
820
- return(0);
821
- path_length = wcslen(wp);
822
- if (archive_wstring_ensure(ws, path_length) == NULL)
823
- return(-1);
824
- archive_wstrncpy(ws, wp, path_length);
825
- for (w = ws->s; *w; w++) {
826
- if (*w == L'\\')
827
- *w = L'/';
828
- }
829
- return(1);
830
- }
831
-
832
- static int
833
- fix_pathseparator(struct archive_entry *entry)
834
- {
835
- struct archive_wstring ws;
836
- const wchar_t *wp;
837
- int ret = ARCHIVE_OK;
838
-
839
- archive_string_init(&ws);
840
- wp = archive_entry_pathname_w(entry);
841
- switch (replace_pathseparator(&ws, wp)) {
842
- case 0: /* Not replaced. */
843
- break;
844
- case 1: /* Replaced. */
845
- archive_entry_copy_pathname_w(entry, ws.s);
846
- break;
847
- default:
848
- ret = ARCHIVE_FAILED;
849
- }
850
- wp = archive_entry_hardlink_w(entry);
851
- switch (replace_pathseparator(&ws, wp)) {
852
- case 0: /* Not replaced. */
853
- break;
854
- case 1: /* Replaced. */
855
- archive_entry_copy_hardlink_w(entry, ws.s);
856
- break;
857
- default:
858
- ret = ARCHIVE_FAILED;
859
- }
860
- wp = archive_entry_symlink_w(entry);
861
- switch (replace_pathseparator(&ws, wp)) {
862
- case 0: /* Not replaced. */
863
- break;
864
- case 1: /* Replaced. */
865
- archive_entry_copy_symlink_w(entry, ws.s);
866
- break;
867
- default:
868
- ret = ARCHIVE_FAILED;
869
- }
870
- archive_wstring_free(&ws);
871
- return(ret);
872
- }
873
-
874
- struct archive_entry *
875
- __la_win_entry_in_posix_pathseparator(struct archive_entry *entry)
876
- {
877
- struct archive_entry *entry_main;
878
- const wchar_t *wp;
879
- int has_backslash = 0;
880
- int ret;
881
-
882
- wp = archive_entry_pathname_w(entry);
883
- if (wp != NULL && wcschr(wp, L'\\') != NULL)
884
- has_backslash = 1;
885
- if (!has_backslash) {
886
- wp = archive_entry_hardlink_w(entry);
887
- if (wp != NULL && wcschr(wp, L'\\') != NULL)
888
- has_backslash = 1;
889
- }
890
- if (!has_backslash) {
891
- wp = archive_entry_symlink_w(entry);
892
- if (wp != NULL && wcschr(wp, L'\\') != NULL)
893
- has_backslash = 1;
894
- }
895
- /*
896
- * If there is no backslash chars, return the original.
897
- */
898
- if (!has_backslash)
899
- return (entry);
900
-
901
- /* Copy entry so we can modify it as needed. */
902
- entry_main = archive_entry_clone(entry);
903
- if (entry_main == NULL)
904
- return (NULL);
905
- /* Replace the Windows path-separator '\' with '/'. */
906
- ret = fix_pathseparator(entry_main);
907
- if (ret < ARCHIVE_WARN) {
908
- archive_entry_free(entry_main);
909
- return (NULL);
910
- }
911
- return (entry_main);
912
- }
913
-
914
-
915
- /*
916
- * The following function was modified from PostgreSQL sources and is
917
- * subject to the copyright below.
918
- */
919
- /*-------------------------------------------------------------------------
920
- *
921
- * win32error.c
922
- * Map win32 error codes to errno values
923
- *
924
- * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
925
- *
926
- * IDENTIFICATION
927
- * $PostgreSQL: pgsql/src/port/win32error.c,v 1.4 2008/01/01 19:46:00 momjian Exp $
928
- *
929
- *-------------------------------------------------------------------------
930
- */
931
- /*
932
- PostgreSQL Database Management System
933
- (formerly known as Postgres, then as Postgres95)
934
-
935
- Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
936
-
937
- Portions Copyright (c) 1994, The Regents of the University of California
938
-
939
- Permission to use, copy, modify, and distribute this software and its
940
- documentation for any purpose, without fee, and without a written agreement
941
- is hereby granted, provided that the above copyright notice and this
942
- paragraph and the following two paragraphs appear in all copies.
943
-
944
- IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
945
- DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
946
- LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
947
- DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
948
- POSSIBILITY OF SUCH DAMAGE.
949
-
950
- THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
951
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
952
- AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
953
- ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO
954
- PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
955
- */
956
-
957
- static const struct {
958
- DWORD winerr;
959
- int doserr;
960
- } doserrors[] =
961
- {
962
- { ERROR_INVALID_FUNCTION, EINVAL },
963
- { ERROR_FILE_NOT_FOUND, ENOENT },
964
- { ERROR_PATH_NOT_FOUND, ENOENT },
965
- { ERROR_TOO_MANY_OPEN_FILES, EMFILE },
966
- { ERROR_ACCESS_DENIED, EACCES },
967
- { ERROR_INVALID_HANDLE, EBADF },
968
- { ERROR_ARENA_TRASHED, ENOMEM },
969
- { ERROR_NOT_ENOUGH_MEMORY, ENOMEM },
970
- { ERROR_INVALID_BLOCK, ENOMEM },
971
- { ERROR_BAD_ENVIRONMENT, E2BIG },
972
- { ERROR_BAD_FORMAT, ENOEXEC },
973
- { ERROR_INVALID_ACCESS, EINVAL },
974
- { ERROR_INVALID_DATA, EINVAL },
975
- { ERROR_INVALID_DRIVE, ENOENT },
976
- { ERROR_CURRENT_DIRECTORY, EACCES },
977
- { ERROR_NOT_SAME_DEVICE, EXDEV },
978
- { ERROR_NO_MORE_FILES, ENOENT },
979
- { ERROR_LOCK_VIOLATION, EACCES },
980
- { ERROR_SHARING_VIOLATION, EACCES },
981
- { ERROR_BAD_NETPATH, ENOENT },
982
- { ERROR_NETWORK_ACCESS_DENIED, EACCES },
983
- { ERROR_BAD_NET_NAME, ENOENT },
984
- { ERROR_FILE_EXISTS, EEXIST },
985
- { ERROR_CANNOT_MAKE, EACCES },
986
- { ERROR_FAIL_I24, EACCES },
987
- { ERROR_INVALID_PARAMETER, EINVAL },
988
- { ERROR_NO_PROC_SLOTS, EAGAIN },
989
- { ERROR_DRIVE_LOCKED, EACCES },
990
- { ERROR_BROKEN_PIPE, EPIPE },
991
- { ERROR_DISK_FULL, ENOSPC },
992
- { ERROR_INVALID_TARGET_HANDLE, EBADF },
993
- { ERROR_INVALID_HANDLE, EINVAL },
994
- { ERROR_WAIT_NO_CHILDREN, ECHILD },
995
- { ERROR_CHILD_NOT_COMPLETE, ECHILD },
996
- { ERROR_DIRECT_ACCESS_HANDLE, EBADF },
997
- { ERROR_NEGATIVE_SEEK, EINVAL },
998
- { ERROR_SEEK_ON_DEVICE, EACCES },
999
- { ERROR_DIR_NOT_EMPTY, ENOTEMPTY },
1000
- { ERROR_NOT_LOCKED, EACCES },
1001
- { ERROR_BAD_PATHNAME, ENOENT },
1002
- { ERROR_MAX_THRDS_REACHED, EAGAIN },
1003
- { ERROR_LOCK_FAILED, EACCES },
1004
- { ERROR_ALREADY_EXISTS, EEXIST },
1005
- { ERROR_FILENAME_EXCED_RANGE, ENOENT },
1006
- { ERROR_NESTING_NOT_ALLOWED, EAGAIN },
1007
- { ERROR_NOT_ENOUGH_QUOTA, ENOMEM }
1008
- };
1009
-
1010
- void
1011
- __la_dosmaperr(unsigned long e)
1012
- {
1013
- int i;
1014
-
1015
- if (e == 0)
1016
- {
1017
- errno = 0;
1018
- return;
1019
- }
1020
-
1021
- for (i = 0; i < (int)(sizeof(doserrors)/sizeof(doserrors[0])); i++)
1022
- {
1023
- if (doserrors[i].winerr == e)
1024
- {
1025
- errno = doserrors[i].doserr;
1026
- return;
1027
- }
1028
- }
1029
-
1030
- /* fprintf(stderr, "unrecognized win32 error code: %lu", e); */
1031
- errno = EINVAL;
1032
- return;
1033
- }
1034
-
1035
- #endif /* _WIN32 && !__CYGWIN__ */