@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,790 +0,0 @@
1
- /*-
2
- * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
3
- * Author: Jonas Gastal <jgastal@profusion.mobi>
4
- * Copyright (c) 2011-2012 Michihiro NAKAJIMA
5
- *
6
- * All rights reserved.
7
- *
8
- * Redistribution and use in source and binary forms, with or without
9
- * modification, are permitted provided that the following conditions
10
- * are met:
11
- * 1. Redistributions of source code must retain the above copyright
12
- * notice, this list of conditions and the following disclaimer.
13
- * 2. Redistributions in binary form must reproduce the above copyright
14
- * notice, this list of conditions and the following disclaimer in the
15
- * documentation and/or other materials provided with the distribution.
16
- *
17
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
18
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
- * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
21
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
- */
28
-
29
- #include "archive_platform.h"
30
-
31
- #ifdef HAVE_ERRNO_H
32
- #include <errno.h>
33
- #endif
34
- #include <stdio.h>
35
- #ifdef HAVE_STDLIB_H
36
- #include <stdlib.h>
37
- #endif
38
- #ifdef HAVE_STRING_H
39
- #include <string.h>
40
- #endif
41
-
42
- #include "archive.h"
43
- #include "archive_entry.h"
44
- #include "archive_entry_locale.h"
45
- #include "archive_private.h"
46
- #include "archive_write_private.h"
47
- #include "archive_write_set_format_private.h"
48
-
49
- struct gnutar {
50
- uint64_t entry_bytes_remaining;
51
- uint64_t entry_padding;
52
- const char * linkname;
53
- size_t linkname_length;
54
- const char * pathname;
55
- size_t pathname_length;
56
- const char * uname;
57
- size_t uname_length;
58
- const char * gname;
59
- size_t gname_length;
60
- struct archive_string_conv *opt_sconv;
61
- struct archive_string_conv *sconv_default;
62
- int init_default_conversion;
63
- };
64
-
65
- /*
66
- * Define structure of GNU tar header.
67
- */
68
- #define GNUTAR_name_offset 0
69
- #define GNUTAR_name_size 100
70
- #define GNUTAR_mode_offset 100
71
- #define GNUTAR_mode_size 7
72
- #define GNUTAR_mode_max_size 8
73
- #define GNUTAR_uid_offset 108
74
- #define GNUTAR_uid_size 7
75
- #define GNUTAR_uid_max_size 8
76
- #define GNUTAR_gid_offset 116
77
- #define GNUTAR_gid_size 7
78
- #define GNUTAR_gid_max_size 8
79
- #define GNUTAR_size_offset 124
80
- #define GNUTAR_size_size 11
81
- #define GNUTAR_size_max_size 12
82
- #define GNUTAR_mtime_offset 136
83
- #define GNUTAR_mtime_size 11
84
- #define GNUTAR_mtime_max_size 11
85
- #define GNUTAR_checksum_offset 148
86
- #define GNUTAR_checksum_size 8
87
- #define GNUTAR_typeflag_offset 156
88
- #define GNUTAR_typeflag_size 1
89
- #define GNUTAR_linkname_offset 157
90
- #define GNUTAR_linkname_size 100
91
- #define GNUTAR_magic_offset 257
92
- #define GNUTAR_magic_size 6
93
- #define GNUTAR_version_offset 263
94
- #define GNUTAR_version_size 2
95
- #define GNUTAR_uname_offset 265
96
- #define GNUTAR_uname_size 32
97
- #define GNUTAR_gname_offset 297
98
- #define GNUTAR_gname_size 32
99
- #define GNUTAR_rdevmajor_offset 329
100
- #define GNUTAR_rdevmajor_size 6
101
- #define GNUTAR_rdevmajor_max_size 8
102
- #define GNUTAR_rdevminor_offset 337
103
- #define GNUTAR_rdevminor_size 6
104
- #define GNUTAR_rdevminor_max_size 8
105
-
106
- /*
107
- * A filled-in copy of the header for initialization.
108
- */
109
- static const char template_header[] = {
110
- /* name: 100 bytes */
111
- 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
112
- 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
113
- 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
114
- 0,0,0,0,
115
- /* Mode, null termination: 8 bytes */
116
- '0','0','0','0','0','0', '0','\0',
117
- /* uid, null termination: 8 bytes */
118
- '0','0','0','0','0','0', '0','\0',
119
- /* gid, null termination: 8 bytes */
120
- '0','0','0','0','0','0', '0','\0',
121
- /* size, space termination: 12 bytes */
122
- '0','0','0','0','0','0','0','0','0','0','0', '\0',
123
- /* mtime, space termination: 12 bytes */
124
- '0','0','0','0','0','0','0','0','0','0','0', '\0',
125
- /* Initial checksum value: 8 spaces */
126
- ' ',' ',' ',' ',' ',' ',' ',' ',
127
- /* Typeflag: 1 byte */
128
- '0', /* '0' = regular file */
129
- /* Linkname: 100 bytes */
130
- 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
131
- 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
132
- 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
133
- 0,0,0,0,
134
- /* Magic: 8 bytes */
135
- 'u','s','t','a','r',' ', ' ','\0',
136
- /* Uname: 32 bytes */
137
- 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
138
- /* Gname: 32 bytes */
139
- 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
140
- /* rdevmajor + null padding: 8 bytes */
141
- '\0','\0','\0','\0','\0','\0', '\0','\0',
142
- /* rdevminor + null padding: 8 bytes */
143
- '\0','\0','\0','\0','\0','\0', '\0','\0',
144
- /* Padding: 167 bytes */
145
- 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
146
- 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
147
- 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
148
- 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
149
- 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
150
- 0,0,0,0,0,0,0
151
- };
152
-
153
- static int archive_write_gnutar_options(struct archive_write *,
154
- const char *, const char *);
155
- static int archive_format_gnutar_header(struct archive_write *, char h[512],
156
- struct archive_entry *, char tartype);
157
- static int archive_write_gnutar_header(struct archive_write *,
158
- struct archive_entry *entry);
159
- static ssize_t archive_write_gnutar_data(struct archive_write *a, const void *buff,
160
- size_t s);
161
- static int archive_write_gnutar_free(struct archive_write *);
162
- static int archive_write_gnutar_close(struct archive_write *);
163
- static int archive_write_gnutar_finish_entry(struct archive_write *);
164
- static int format_256(int64_t, char *, int);
165
- static int format_number(int64_t, char *, int size, int maxsize);
166
- static int format_octal(int64_t, char *, int);
167
-
168
- /*
169
- * Set output format to 'GNU tar' format.
170
- */
171
- int
172
- archive_write_set_format_gnutar(struct archive *_a)
173
- {
174
- struct archive_write *a = (struct archive_write *)_a;
175
- struct gnutar *gnutar;
176
-
177
- archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
178
- ARCHIVE_STATE_NEW, "archive_write_set_format_gnutar");
179
-
180
- (void)__archive_write_unregister_format(a);
181
-
182
- gnutar = calloc(1, sizeof(*gnutar));
183
- if (gnutar == NULL) {
184
- archive_set_error(&a->archive, ENOMEM,
185
- "Can't allocate gnutar data");
186
- return (ARCHIVE_FATAL);
187
- }
188
- a->format_data = gnutar;
189
- a->format_name = "gnutar";
190
- a->format_options = archive_write_gnutar_options;
191
- a->format_write_header = archive_write_gnutar_header;
192
- a->format_write_data = archive_write_gnutar_data;
193
- a->format_close = archive_write_gnutar_close;
194
- a->format_free = archive_write_gnutar_free;
195
- a->format_finish_entry = archive_write_gnutar_finish_entry;
196
- a->archive.archive_format = ARCHIVE_FORMAT_TAR_GNUTAR;
197
- a->archive.archive_format_name = "GNU tar";
198
- return (ARCHIVE_OK);
199
- }
200
-
201
- static int
202
- archive_write_gnutar_options(struct archive_write *a, const char *key,
203
- const char *val)
204
- {
205
- struct gnutar *gnutar = a->format_data;
206
- int ret = ARCHIVE_FAILED;
207
-
208
- if (strcmp(key, "hdrcharset") == 0) {
209
- if (val == NULL || val[0] == 0)
210
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
211
- "%s: hdrcharset option needs a character-set name",
212
- a->format_name);
213
- else {
214
- gnutar->opt_sconv = archive_string_conversion_to_charset(
215
- &a->archive, val, 0);
216
- if (gnutar->opt_sconv != NULL)
217
- ret = ARCHIVE_OK;
218
- else
219
- ret = ARCHIVE_FATAL;
220
- }
221
- return (ret);
222
- }
223
-
224
- /* Note: The "warn" return is just to inform the options
225
- * supervisor that we didn't handle it. It will generate
226
- * a suitable error if no one used this option. */
227
- return (ARCHIVE_WARN);
228
- }
229
-
230
- static int
231
- archive_write_gnutar_close(struct archive_write *a)
232
- {
233
- return (__archive_write_nulls(a, 512*2));
234
- }
235
-
236
- static int
237
- archive_write_gnutar_free(struct archive_write *a)
238
- {
239
- struct gnutar *gnutar = a->format_data;
240
-
241
- free(gnutar);
242
- a->format_data = NULL;
243
- return (ARCHIVE_OK);
244
- }
245
-
246
- static int
247
- archive_write_gnutar_finish_entry(struct archive_write *a)
248
- {
249
- struct gnutar *gnutar = a->format_data;
250
- int ret;
251
-
252
- ret = __archive_write_nulls(a,
253
- gnutar->entry_bytes_remaining + gnutar->entry_padding);
254
- gnutar->entry_bytes_remaining = gnutar->entry_padding = 0;
255
- return (ret);
256
- }
257
-
258
- static ssize_t
259
- archive_write_gnutar_data(struct archive_write *a, const void *buff, size_t s)
260
- {
261
- struct gnutar *gnutar = a->format_data;
262
- int ret;
263
-
264
- if (s > gnutar->entry_bytes_remaining)
265
- s = (size_t)gnutar->entry_bytes_remaining;
266
- ret = __archive_write_output(a, buff, s);
267
- gnutar->entry_bytes_remaining -= s;
268
- if (ret != ARCHIVE_OK)
269
- return (ret);
270
- return (s);
271
- }
272
-
273
- static int
274
- archive_write_gnutar_header(struct archive_write *a,
275
- struct archive_entry *entry)
276
- {
277
- struct gnutar *gnutar = a->format_data;
278
- char buff[512];
279
- int r, ret, ret2 = ARCHIVE_OK;
280
- char tartype;
281
- struct archive_string_conv *sconv;
282
- struct archive_entry *entry_main;
283
-
284
- /* Setup default string conversion. */
285
- if (gnutar->opt_sconv == NULL) {
286
- if (!gnutar->init_default_conversion) {
287
- gnutar->sconv_default =
288
- archive_string_default_conversion_for_write(
289
- &(a->archive));
290
- gnutar->init_default_conversion = 1;
291
- }
292
- sconv = gnutar->sconv_default;
293
- } else
294
- sconv = gnutar->opt_sconv;
295
-
296
- /* Sanity check. */
297
- if (archive_entry_pathname(entry) == NULL
298
- #if defined(_WIN32) && !defined(__CYGWIN__)
299
- && archive_entry_pathname_w(entry) == NULL
300
- #endif
301
- ) {
302
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
303
- "Can't record entry in tar file without pathname");
304
- return ARCHIVE_FAILED;
305
- }
306
-
307
- /* Only regular files (not hardlinks) have data. */
308
- if (archive_entry_hardlink(entry) != NULL ||
309
- archive_entry_symlink(entry) != NULL ||
310
- archive_entry_filetype(entry) != AE_IFREG)
311
- archive_entry_set_size(entry, 0);
312
-
313
- if (AE_IFDIR == archive_entry_filetype(entry)) {
314
- const char *p;
315
- size_t path_length;
316
- /*
317
- * Ensure a trailing '/'. Modify the entry so
318
- * the client sees the change.
319
- */
320
- #if defined(_WIN32) && !defined(__CYGWIN__)
321
- const wchar_t *wp;
322
-
323
- wp = archive_entry_pathname_w(entry);
324
- if (wp != NULL && wp[0] != L'\0' &&
325
- wp[wcslen(wp) - 1] != L'/') {
326
- struct archive_wstring ws;
327
-
328
- archive_string_init(&ws);
329
- path_length = wcslen(wp);
330
- if (archive_wstring_ensure(&ws,
331
- path_length + 2) == NULL) {
332
- archive_set_error(&a->archive, ENOMEM,
333
- "Can't allocate ustar data");
334
- archive_wstring_free(&ws);
335
- return(ARCHIVE_FATAL);
336
- }
337
- /* Should we keep '\' ? */
338
- if (wp[path_length -1] == L'\\')
339
- path_length--;
340
- archive_wstrncpy(&ws, wp, path_length);
341
- archive_wstrappend_wchar(&ws, L'/');
342
- archive_entry_copy_pathname_w(entry, ws.s);
343
- archive_wstring_free(&ws);
344
- p = NULL;
345
- } else
346
- #endif
347
- p = archive_entry_pathname(entry);
348
- /*
349
- * On Windows, this is a backup operation just in
350
- * case getting WCS failed. On POSIX, this is a
351
- * normal operation.
352
- */
353
- if (p != NULL && p[0] != '\0' && p[strlen(p) - 1] != '/') {
354
- struct archive_string as;
355
-
356
- archive_string_init(&as);
357
- path_length = strlen(p);
358
- if (archive_string_ensure(&as,
359
- path_length + 2) == NULL) {
360
- archive_set_error(&a->archive, ENOMEM,
361
- "Can't allocate ustar data");
362
- archive_string_free(&as);
363
- return(ARCHIVE_FATAL);
364
- }
365
- #if defined(_WIN32) && !defined(__CYGWIN__)
366
- /* NOTE: This might break the pathname
367
- * if the current code page is CP932 and
368
- * the pathname includes a character '\'
369
- * as a part of its multibyte pathname. */
370
- if (p[strlen(p) -1] == '\\')
371
- path_length--;
372
- else
373
- #endif
374
- archive_strncpy(&as, p, path_length);
375
- archive_strappend_char(&as, '/');
376
- archive_entry_copy_pathname(entry, as.s);
377
- archive_string_free(&as);
378
- }
379
- }
380
-
381
- #if defined(_WIN32) && !defined(__CYGWIN__)
382
- /* Make sure the path separators in pathname, hardlink and symlink
383
- * are all slash '/', not the Windows path separator '\'. */
384
- entry_main = __la_win_entry_in_posix_pathseparator(entry);
385
- if (entry_main == NULL) {
386
- archive_set_error(&a->archive, ENOMEM,
387
- "Can't allocate ustar data");
388
- return(ARCHIVE_FATAL);
389
- }
390
- if (entry != entry_main)
391
- entry = entry_main;
392
- else
393
- entry_main = NULL;
394
- #else
395
- entry_main = NULL;
396
- #endif
397
- r = archive_entry_pathname_l(entry, &(gnutar->pathname),
398
- &(gnutar->pathname_length), sconv);
399
- if (r != 0) {
400
- const char* p_mbs;
401
- if (errno == ENOMEM) {
402
- archive_set_error(&a->archive, ENOMEM,
403
- "Can't allocate memory for pathname");
404
- ret = ARCHIVE_FATAL;
405
- goto exit_write_header;
406
- }
407
- p_mbs = archive_entry_pathname(entry);
408
- if (p_mbs) {
409
- /* We have a wrongly-encoded MBS pathname.
410
- * Warn and use it. */
411
- archive_set_error(&a->archive,
412
- ARCHIVE_ERRNO_FILE_FORMAT,
413
- "Can't translate pathname '%s' to %s", p_mbs,
414
- archive_string_conversion_charset_name(sconv));
415
- ret2 = ARCHIVE_WARN;
416
- } else {
417
- /* We have no MBS pathname. Fail. */
418
- archive_set_error(&a->archive,
419
- ARCHIVE_ERRNO_FILE_FORMAT,
420
- "Can't translate pathname to %s",
421
- archive_string_conversion_charset_name(sconv));
422
- return ARCHIVE_FAILED;
423
- }
424
- }
425
- r = archive_entry_uname_l(entry, &(gnutar->uname),
426
- &(gnutar->uname_length), sconv);
427
- if (r != 0) {
428
- if (errno == ENOMEM) {
429
- archive_set_error(&a->archive, ENOMEM,
430
- "Can't allocate memory for Uname");
431
- ret = ARCHIVE_FATAL;
432
- goto exit_write_header;
433
- }
434
- archive_set_error(&a->archive,
435
- ARCHIVE_ERRNO_FILE_FORMAT,
436
- "Can't translate uname '%s' to %s",
437
- archive_entry_uname(entry),
438
- archive_string_conversion_charset_name(sconv));
439
- ret2 = ARCHIVE_WARN;
440
- }
441
- r = archive_entry_gname_l(entry, &(gnutar->gname),
442
- &(gnutar->gname_length), sconv);
443
- if (r != 0) {
444
- if (errno == ENOMEM) {
445
- archive_set_error(&a->archive, ENOMEM,
446
- "Can't allocate memory for Gname");
447
- ret = ARCHIVE_FATAL;
448
- goto exit_write_header;
449
- }
450
- archive_set_error(&a->archive,
451
- ARCHIVE_ERRNO_FILE_FORMAT,
452
- "Can't translate gname '%s' to %s",
453
- archive_entry_gname(entry),
454
- archive_string_conversion_charset_name(sconv));
455
- ret2 = ARCHIVE_WARN;
456
- }
457
-
458
- /* If linkname is longer than 100 chars we need to add a 'K' header. */
459
- r = archive_entry_hardlink_l(entry, &(gnutar->linkname),
460
- &(gnutar->linkname_length), sconv);
461
- if (r != 0) {
462
- if (errno == ENOMEM) {
463
- archive_set_error(&a->archive, ENOMEM,
464
- "Can't allocate memory for Linkname");
465
- ret = ARCHIVE_FATAL;
466
- goto exit_write_header;
467
- }
468
- archive_set_error(&a->archive,
469
- ARCHIVE_ERRNO_FILE_FORMAT,
470
- "Can't translate linkname '%s' to %s",
471
- archive_entry_hardlink(entry),
472
- archive_string_conversion_charset_name(sconv));
473
- ret2 = ARCHIVE_WARN;
474
- }
475
- if (gnutar->linkname_length == 0) {
476
- r = archive_entry_symlink_l(entry, &(gnutar->linkname),
477
- &(gnutar->linkname_length), sconv);
478
- if (r != 0) {
479
- if (errno == ENOMEM) {
480
- archive_set_error(&a->archive, ENOMEM,
481
- "Can't allocate memory for Linkname");
482
- ret = ARCHIVE_FATAL;
483
- goto exit_write_header;
484
- }
485
- archive_set_error(&a->archive,
486
- ARCHIVE_ERRNO_FILE_FORMAT,
487
- "Can't translate linkname '%s' to %s",
488
- archive_entry_hardlink(entry),
489
- archive_string_conversion_charset_name(sconv));
490
- ret2 = ARCHIVE_WARN;
491
- }
492
- }
493
- if (gnutar->linkname_length > GNUTAR_linkname_size) {
494
- size_t length = gnutar->linkname_length + 1;
495
- struct archive_entry *temp = archive_entry_new2(&a->archive);
496
-
497
- if (temp == NULL) {
498
- archive_set_error(&a->archive, ENOMEM,
499
- "Can't allocate memory for Linkname");
500
- ret = ARCHIVE_FATAL;
501
- goto exit_write_header;
502
- }
503
-
504
- /* Uname/gname here don't really matter since no one reads them;
505
- * these are the values that GNU tar happens to use on FreeBSD. */
506
- archive_entry_set_uname(temp, "root");
507
- archive_entry_set_gname(temp, "wheel");
508
-
509
- archive_entry_set_pathname(temp, "././@LongLink");
510
- archive_entry_set_size(temp, length);
511
- ret = archive_format_gnutar_header(a, buff, temp, 'K');
512
- archive_entry_free(temp);
513
- if (ret < ARCHIVE_WARN)
514
- goto exit_write_header;
515
- ret = __archive_write_output(a, buff, 512);
516
- if (ret < ARCHIVE_WARN)
517
- goto exit_write_header;
518
- /* Write name and trailing null byte. */
519
- ret = __archive_write_output(a, gnutar->linkname, length);
520
- if (ret < ARCHIVE_WARN)
521
- goto exit_write_header;
522
- /* Pad to 512 bytes */
523
- ret = __archive_write_nulls(a, 0x1ff & (-(ssize_t)length));
524
- if (ret < ARCHIVE_WARN)
525
- goto exit_write_header;
526
- }
527
-
528
- /* If pathname is longer than 100 chars we need to add an 'L' header. */
529
- if (gnutar->pathname_length > GNUTAR_name_size) {
530
- const char *pathname = gnutar->pathname;
531
- size_t length = gnutar->pathname_length + 1;
532
- struct archive_entry *temp = archive_entry_new2(&a->archive);
533
-
534
- if (temp == NULL) {
535
- archive_set_error(&a->archive, ENOMEM,
536
- "Can't allocate memory for Linkname");
537
- ret = ARCHIVE_FATAL;
538
- goto exit_write_header;
539
- }
540
-
541
- /* Uname/gname here don't really matter since no one reads them;
542
- * these are the values that GNU tar happens to use on FreeBSD. */
543
- archive_entry_set_uname(temp, "root");
544
- archive_entry_set_gname(temp, "wheel");
545
-
546
- archive_entry_set_pathname(temp, "././@LongName");
547
- archive_entry_set_size(temp, length);
548
- ret = archive_format_gnutar_header(a, buff, temp, 'L');
549
- archive_entry_free(temp);
550
- if (ret < ARCHIVE_WARN)
551
- goto exit_write_header;
552
- ret = __archive_write_output(a, buff, 512);
553
- if(ret < ARCHIVE_WARN)
554
- goto exit_write_header;
555
- /* Write pathname + trailing null byte. */
556
- ret = __archive_write_output(a, pathname, length);
557
- if(ret < ARCHIVE_WARN)
558
- goto exit_write_header;
559
- /* Pad to multiple of 512 bytes. */
560
- ret = __archive_write_nulls(a, 0x1ff & (-(ssize_t)length));
561
- if (ret < ARCHIVE_WARN)
562
- goto exit_write_header;
563
- }
564
-
565
- if (archive_entry_hardlink_is_set(entry)) {
566
- tartype = '1';
567
- } else
568
- switch (archive_entry_filetype(entry)) {
569
- case AE_IFREG: tartype = '0' ; break;
570
- case AE_IFLNK: tartype = '2' ; break;
571
- case AE_IFCHR: tartype = '3' ; break;
572
- case AE_IFBLK: tartype = '4' ; break;
573
- case AE_IFDIR: tartype = '5' ; break;
574
- case AE_IFIFO: tartype = '6' ; break;
575
- default: /* AE_IFSOCK and unknown */
576
- __archive_write_entry_filetype_unsupported(
577
- &a->archive, entry, "gnutar");
578
- ret = ARCHIVE_FAILED;
579
- goto exit_write_header;
580
- }
581
-
582
- ret = archive_format_gnutar_header(a, buff, entry, tartype);
583
- if (ret < ARCHIVE_WARN)
584
- goto exit_write_header;
585
- if (ret2 < ret)
586
- ret = ret2;
587
- ret2 = __archive_write_output(a, buff, 512);
588
- if (ret2 < ARCHIVE_WARN) {
589
- ret = ret2;
590
- goto exit_write_header;
591
- }
592
- if (ret2 < ret)
593
- ret = ret2;
594
-
595
- gnutar->entry_bytes_remaining = archive_entry_size(entry);
596
- gnutar->entry_padding = 0x1ff & (-(int64_t)gnutar->entry_bytes_remaining);
597
- exit_write_header:
598
- archive_entry_free(entry_main);
599
- return (ret);
600
- }
601
-
602
- static int
603
- archive_format_gnutar_header(struct archive_write *a, char h[512],
604
- struct archive_entry *entry, char tartype)
605
- {
606
- struct gnutar *gnutar = a->format_data;
607
- unsigned int checksum;
608
- int i, ret;
609
- size_t copy_length;
610
- const char *p;
611
-
612
- ret = 0;
613
-
614
- /*
615
- * The "template header" already includes the signature,
616
- * various end-of-field markers, and other required elements.
617
- */
618
- memcpy(h, &template_header, 512);
619
-
620
- /*
621
- * Because the block is already null-filled, and strings
622
- * are allowed to exactly fill their destination (without null),
623
- * I use memcpy(dest, src, strlen()) here a lot to copy strings.
624
- */
625
-
626
- if (tartype == 'K' || tartype == 'L') {
627
- p = archive_entry_pathname(entry);
628
- copy_length = strlen(p);
629
- } else {
630
- p = gnutar->pathname;
631
- copy_length = gnutar->pathname_length;
632
- }
633
- if (copy_length > GNUTAR_name_size)
634
- copy_length = GNUTAR_name_size;
635
- memcpy(h + GNUTAR_name_offset, p, copy_length);
636
-
637
- if ((copy_length = gnutar->linkname_length) > 0) {
638
- if (copy_length > GNUTAR_linkname_size)
639
- copy_length = GNUTAR_linkname_size;
640
- memcpy(h + GNUTAR_linkname_offset, gnutar->linkname,
641
- copy_length);
642
- }
643
-
644
- /* TODO: How does GNU tar handle unames longer than GNUTAR_uname_size? */
645
- if (tartype == 'K' || tartype == 'L') {
646
- p = archive_entry_uname(entry);
647
- copy_length = strlen(p);
648
- } else {
649
- p = gnutar->uname;
650
- copy_length = gnutar->uname_length;
651
- }
652
- if (copy_length > 0) {
653
- if (copy_length > GNUTAR_uname_size)
654
- copy_length = GNUTAR_uname_size;
655
- memcpy(h + GNUTAR_uname_offset, p, copy_length);
656
- }
657
-
658
- /* TODO: How does GNU tar handle gnames longer than GNUTAR_gname_size? */
659
- if (tartype == 'K' || tartype == 'L') {
660
- p = archive_entry_gname(entry);
661
- copy_length = strlen(p);
662
- } else {
663
- p = gnutar->gname;
664
- copy_length = gnutar->gname_length;
665
- }
666
- if (copy_length > 0) {
667
- if (copy_length > GNUTAR_gname_size)
668
- copy_length = GNUTAR_gname_size;
669
- memcpy(h + GNUTAR_gname_offset, p, copy_length);
670
- }
671
-
672
- /* By truncating the mode here, we ensure it always fits. */
673
- format_octal(archive_entry_mode(entry) & 07777,
674
- h + GNUTAR_mode_offset, GNUTAR_mode_size);
675
-
676
- /* GNU tar supports base-256 here, so should never overflow. */
677
- if (format_number(archive_entry_uid(entry), h + GNUTAR_uid_offset,
678
- GNUTAR_uid_size, GNUTAR_uid_max_size)) {
679
- archive_set_error(&a->archive, ERANGE,
680
- "Numeric user ID %jd too large for gnutar format",
681
- (intmax_t)archive_entry_uid(entry));
682
- ret = ARCHIVE_FAILED;
683
- }
684
-
685
- /* GNU tar supports base-256 here, so should never overflow. */
686
- if (format_number(archive_entry_gid(entry), h + GNUTAR_gid_offset,
687
- GNUTAR_gid_size, GNUTAR_gid_max_size)) {
688
- archive_set_error(&a->archive, ERANGE,
689
- "Numeric group ID %jd too large for gnutar format",
690
- (intmax_t)archive_entry_gid(entry));
691
- ret = ARCHIVE_FAILED;
692
- }
693
-
694
- /* GNU tar supports base-256 here, so should never overflow. */
695
- if (format_number(archive_entry_size(entry), h + GNUTAR_size_offset,
696
- GNUTAR_size_size, GNUTAR_size_max_size)) {
697
- archive_set_error(&a->archive, ERANGE,
698
- "File size out of range");
699
- ret = ARCHIVE_FAILED;
700
- }
701
-
702
- /* Shouldn't overflow before 2106, since mtime field is 33 bits. */
703
- format_octal(archive_entry_mtime(entry),
704
- h + GNUTAR_mtime_offset, GNUTAR_mtime_size);
705
-
706
- if (archive_entry_filetype(entry) == AE_IFBLK
707
- || archive_entry_filetype(entry) == AE_IFCHR) {
708
- if (format_octal(archive_entry_rdevmajor(entry),
709
- h + GNUTAR_rdevmajor_offset,
710
- GNUTAR_rdevmajor_size)) {
711
- archive_set_error(&a->archive, ERANGE,
712
- "Major device number too large for gnutar format");
713
- ret = ARCHIVE_FAILED;
714
- }
715
-
716
- if (format_octal(archive_entry_rdevminor(entry),
717
- h + GNUTAR_rdevminor_offset,
718
- GNUTAR_rdevminor_size)) {
719
- archive_set_error(&a->archive, ERANGE,
720
- "Minor device number too large for gnutar format");
721
- ret = ARCHIVE_FAILED;
722
- }
723
- }
724
-
725
- h[GNUTAR_typeflag_offset] = tartype;
726
-
727
- checksum = 0;
728
- for (i = 0; i < 512; i++)
729
- checksum += 255 & (unsigned int)h[i];
730
- h[GNUTAR_checksum_offset + 6] = '\0'; /* Can't be pre-set in the template. */
731
- /* h[GNUTAR_checksum_offset + 7] = ' '; */ /* This is pre-set in the template. */
732
- format_octal(checksum, h + GNUTAR_checksum_offset, 6);
733
- return (ret);
734
- }
735
-
736
- /*
737
- * Format a number into a field, falling back to base-256 if necessary.
738
- */
739
- static int
740
- format_number(int64_t v, char *p, int s, int maxsize)
741
- {
742
- int64_t limit = ((int64_t)1 << (s*3));
743
-
744
- if (v < limit)
745
- return (format_octal(v, p, s));
746
- return (format_256(v, p, maxsize));
747
- }
748
-
749
- /*
750
- * Format a number into the specified field using base-256.
751
- */
752
- static int
753
- format_256(int64_t v, char *p, int s)
754
- {
755
- p += s;
756
- while (s-- > 0) {
757
- *--p = (char)(v & 0xff);
758
- v >>= 8;
759
- }
760
- *p |= 0x80; /* Set the base-256 marker bit. */
761
- return (0);
762
- }
763
-
764
- /*
765
- * Format a number into the specified field using octal.
766
- */
767
- static int
768
- format_octal(int64_t v, char *p, int s)
769
- {
770
- int len = s;
771
-
772
- /* Octal values can't be negative, so use 0. */
773
- if (v < 0)
774
- v = 0;
775
-
776
- p += s; /* Start at the end and work backwards. */
777
- while (s-- > 0) {
778
- *--p = (char)('0' + (v & 7));
779
- v >>= 3;
780
- }
781
-
782
- if (v == 0)
783
- return (0);
784
-
785
- /* If it overflowed, fill field with max value. */
786
- while (len-- > 0)
787
- *p++ = '7';
788
-
789
- return (-1);
790
- }