├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── android.yml ├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── build.gradle ├── docs └── contributing.md ├── fastlane └── metadata │ └── android │ └── en-US │ └── changelogs │ ├── 1.txt │ ├── 10.txt │ ├── 11.txt │ ├── 2.txt │ ├── 3.txt │ ├── 4.txt │ ├── 5.txt │ ├── 6.txt │ ├── 7.txt │ ├── 8.txt │ └── 9.txt ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── CMakeLists.txt ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── me │ │ └── zhanghai │ │ └── android │ │ └── libarchive │ │ ├── Archive.java │ │ ├── ArchiveEntry.java │ │ └── ArchiveException.java │ └── jni │ ├── LibarchiveChecks.cmake │ ├── archive-jni.c │ ├── libarchive.patch │ └── liblzma-config.h.in ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── me │ └── zhanghai │ └── android │ └── libarchive │ └── sample │ └── MainActivity.java ├── settings.gradle └── third_party └── libarchive ├── LICENSE └── LibarchiveChecks.cmake /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Expected Behavior 2 | 3 | 4 | ## Actual Behavior 5 | 6 | 7 | ## Steps to Reproduce the Problem 8 | 9 | 1. 10 | 1. 11 | 1. 12 | 13 | ## Specifications 14 | 15 | - Version: 16 | - Platform: -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Fixes # 2 | 3 | > It's a good idea to open an issue first for discussion. 4 | 5 | - [ ] Tests pass 6 | - [ ] Appropriate changes to README are included in PR -------------------------------------------------------------------------------- /.github/workflows/android.yml: -------------------------------------------------------------------------------- 1 | name: Android CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - name: Check out repository 12 | uses: actions/checkout@v3 13 | with: 14 | submodules: true 15 | - name: Set up JDK 17 16 | uses: actions/setup-java@v3 17 | with: 18 | distribution: 'temurin' 19 | java-version: '17' 20 | - name: Build with Gradle 21 | run: ./gradlew assembleDebug lintVitalRelease 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle/ 2 | /.idea/ 3 | /build/ 4 | /captures/ 5 | /local.properties 6 | .DS_Store 7 | *.iml 8 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "library/src/main/jni/external/libarchive"] 2 | path = library/src/main/jni/external/libarchive 3 | url = https://github.com/libarchive/libarchive.git 4 | [submodule "library/src/main/jni/external/bzip2"] 5 | path = library/src/main/jni/external/bzip2 6 | url = https://gitlab.com/bzip2/bzip2.git 7 | [submodule "library/src/main/jni/external/xz"] 8 | path = library/src/main/jni/external/xz 9 | url = https://github.com/tukaani-project/xz.git 10 | [submodule "library/src/main/jni/external/lz4"] 11 | path = library/src/main/jni/external/lz4 12 | url = https://github.com/lz4/lz4.git 13 | [submodule "library/src/main/jni/external/zstd"] 14 | path = library/src/main/jni/external/zstd 15 | url = https://github.com/facebook/zstd.git 16 | [submodule "library/src/main/jni/external/mbedtls"] 17 | path = library/src/main/jni/external/mbedtls 18 | url = https://github.com/Mbed-TLS/mbedtls.git 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libarchive-android 2 | 3 | [![Android CI status](https://github.com/zhanghai/libarchive-android/workflows/Android%20CI/badge.svg)](https://github.com/zhanghai/libarchive-android/actions) 4 | 5 | [libarchive](https://github.com/libarchive/libarchive) built with Android NDK, packaged as an 6 | Android library with some Java binding. 7 | 8 | The bundled [libarchive](https://github.com/libarchive/libarchive) is built with 9 | [libz](https://developer.android.com/ndk/guides/stable_apis#zlib_compression), 10 | [libbz2](https://gitlab.com/bzip2/bzip2), [liblzma](https://github.com/tukaani-project/xz), 11 | [liblz4](https://github.com/lz4/lz4), [libzstd](https://github.com/facebook/zstd) and 12 | [libmbedcrypto](https://github.com/Mbed-TLS/mbedtls). 13 | 14 | This is not an officially supported Google product. 15 | 16 | ## Integration 17 | 18 | Gradle: 19 | 20 | ```gradle 21 | implementation 'me.zhanghai.android.libarchive:library:1.1.6' 22 | ``` 23 | 24 | ## Usage 25 | 26 | See [`Archive.java`](library/src/main/java/me/zhanghai/android/libarchive/Archive.java) and 27 | [`ArchiveEntry.java`](library/src/main/java/me/zhanghai/android/libarchive/ArchiveEntry.java), which 28 | contain the Java bindings for 29 | [`archive.h`](https://github.com/libarchive/libarchive/blob/master/libarchive/archive.h) and 30 | [`archive_entry.h`](https://github.com/libarchive/libarchive/blob/master/libarchive/archive_entry.h) 31 | . 32 | 33 | See also 34 | [`MainActivity.java`](sample/src/main/java/me/zhanghai/android/libarchive/sample/MainActivity.java) 35 | for an example on how to use this library to read archive files. 36 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | buildscript { 18 | repositories { 19 | google() 20 | mavenCentral() 21 | } 22 | dependencies { 23 | classpath 'com.android.tools.build:gradle:8.10.0' 24 | classpath 'com.vanniktech:gradle-maven-publish-plugin:0.32.0' 25 | } 26 | } 27 | 28 | allprojects { 29 | repositories { 30 | google() 31 | mavenCentral() 32 | } 33 | } 34 | 35 | task clean(type: Delete) { 36 | delete rootProject.buildDir 37 | } 38 | -------------------------------------------------------------------------------- /docs/contributing.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution; 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. 24 | 25 | ## Community Guidelines 26 | 27 | This project follows [Google's Open Source Community 28 | Guidelines](https://opensource.google/conduct/). 29 | -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/changelogs/1.txt: -------------------------------------------------------------------------------- 1 | - Initial release. 2 | -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/changelogs/10.txt: -------------------------------------------------------------------------------- 1 | - Updated libarchive to 3.8.0 and added new functions. 2 | - Added support for 16 KB page sizes. 3 | -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/changelogs/11.txt: -------------------------------------------------------------------------------- 1 | - Updated libarchive to 3.8.1. 2 | -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/changelogs/2.txt: -------------------------------------------------------------------------------- 1 | - Updated libarchive to 3.7.2. 2 | -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/changelogs/3.txt: -------------------------------------------------------------------------------- 1 | - Fixed issue when writing 7z and some other formats on older Android platforms. 2 | -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/changelogs/4.txt: -------------------------------------------------------------------------------- 1 | - Fixed issue when closing and freeing archives. 2 | -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/changelogs/5.txt: -------------------------------------------------------------------------------- 1 | - Added read/writeOpenMemoryUnsafe() for working with large memory buffers. 2 | - Fixed a parameter type in readSetSeekCallback(). 3 | - Updated dependencies. 4 | -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/changelogs/6.txt: -------------------------------------------------------------------------------- 1 | - Updated dependencies. 2 | -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/changelogs/7.txt: -------------------------------------------------------------------------------- 1 | - Updated dependencies. 2 | -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/changelogs/8.txt: -------------------------------------------------------------------------------- 1 | - Updated dependencies. 2 | -------------------------------------------------------------------------------- /fastlane/metadata/android/en-US/changelogs/9.txt: -------------------------------------------------------------------------------- 1 | - Added bindings for new archive_entry_*_is_set functions. 2 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | 19 | # AndroidX package structure to make it clearer which packages are bundled with the 20 | # Android operating system, and which are packaged with your app's APK 21 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 22 | android.useAndroidX=true 23 | 24 | # Kotlin code style for this project: "official" or "obsolete": 25 | kotlin.code.style=official 26 | 27 | SONATYPE_HOST=CENTRAL_PORTAL 28 | RELEASE_SIGNING_ENABLED=true 29 | 30 | GROUP=me.zhanghai.android.libarchive 31 | VERSION_NAME=1.1.6 32 | VERSION_CODE=11 33 | 34 | POM_DESCRIPTION=libarchive for Android 35 | POM_URL=https://github.com/zhanghai/libarchive-android 36 | POM_INCEPTION_YEAR=2023 37 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 38 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 39 | POM_LICENCE_DIST=repo 40 | POM_DEVELOPER_ID=zhanghai 41 | POM_DEVELOPER_NAME=Hai Zhang 42 | POM_DEVELOPER_URL=https://github.com/zhanghai 43 | POM_SCM_CONNECTION=scm:git@github.com:zhanghai/libarchive-android 44 | POM_SCM_DEV_CONNECTION=scm:git@github.com:zhanghai/libarchive-android 45 | POM_SCM_URL=https://github.com/zhanghai/libarchive-android 46 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhanghai/libarchive-android/d3ee9c472173fcaf28e737f59dd34ef6cf3d1c88/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Dec 12 18:11:07 CST 2023 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /.cxx/ 2 | /build/ 3 | /out/ 4 | -------------------------------------------------------------------------------- /library/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2023 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 3.22.1) 16 | 17 | project(libarchive-android 18 | LANGUAGES C ASM) 19 | # CMAKE_INTERPROCEDURAL_OPTIMIZATION sets -fuse-ld=gold and -flto=thin. 20 | #set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) 21 | add_compile_options( 22 | -fdata-sections 23 | -ffunction-sections 24 | -flto) 25 | add_link_options( 26 | LINKER:--gc-sections) 27 | 28 | # https://developer.android.com/ndk/guides/stable_apis#zlib_compression 29 | # Platform libz has custom SIMD optimizations (*_simd.c) so we should use that instead of building 30 | # from official zlib repository. 31 | find_library(Z_LIBRARY libz.a) 32 | 33 | # https://android.googlesource.com/platform/external/bzip2/+/main/Android.bp 34 | add_library(bz STATIC 35 | src/main/jni/external/bzip2/blocksort.c 36 | src/main/jni/external/bzip2/bzlib.c 37 | src/main/jni/external/bzip2/compress.c 38 | src/main/jni/external/bzip2/crctable.c 39 | src/main/jni/external/bzip2/decompress.c 40 | src/main/jni/external/bzip2/huffman.c 41 | src/main/jni/external/bzip2/randtable.c) 42 | target_compile_definitions(bz 43 | PRIVATE 44 | USE_MMAP) 45 | target_compile_options(bz 46 | PRIVATE 47 | -Werror 48 | -Wno-unused-parameter) 49 | if(CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a") 50 | target_compile_options(bz 51 | PRIVATE 52 | -marm) 53 | endif() 54 | target_include_directories(bz 55 | PUBLIC 56 | src/main/jni/external/bzip2) 57 | 58 | # https://github.com/tukaani-project/xz/blob/master/configure.ac 59 | function(configure_liblzma) 60 | set(HAVE_BSWAP_16 1) 61 | set(HAVE_BSWAP_32 1) 62 | set(HAVE_BSWAP_64 1) 63 | set(HAVE_BYTESWAP_H 1) 64 | set(HAVE_CHECK_CRC32 1) 65 | set(HAVE_CHECK_CRC64 1) 66 | set(HAVE_CHECK_SHA256 1) 67 | set(HAVE_CLOCK_GETTIME 1) 68 | set(HAVE_CLOCK_MONOTONIC 1) 69 | if(CMAKE_ANDROID_ARCH_ABI MATCHES "x86|x86_64") 70 | set(HAVE_CPUID_H 1) 71 | endif() 72 | set(HAVE_DECODERS 1) 73 | set(HAVE_DECODER_ARM 1) 74 | set(HAVE_DECODER_ARM64 1) 75 | set(HAVE_DECODER_ARMTHUMB 1) 76 | set(HAVE_DECODER_DELTA 1) 77 | set(HAVE_DECODER_IA64 1) 78 | set(HAVE_DECODER_LZMA1 1) 79 | set(HAVE_DECODER_LZMA2 1) 80 | set(HAVE_DECODER_POWERPC 1) 81 | set(HAVE_DECODER_SPARC 1) 82 | set(HAVE_DECODER_X86 1) 83 | set(HAVE_ENCODERS 1) 84 | set(HAVE_ENCODER_ARM 1) 85 | set(HAVE_ENCODER_ARM64 1) 86 | set(HAVE_ENCODER_ARMTHUMB 1) 87 | set(HAVE_ENCODER_DELTA 1) 88 | set(HAVE_ENCODER_IA64 1) 89 | set(HAVE_ENCODER_LZMA1 1) 90 | set(HAVE_ENCODER_LZMA2 1) 91 | set(HAVE_ENCODER_POWERPC 1) 92 | set(HAVE_ENCODER_SPARC 1) 93 | set(HAVE_ENCODER_X86 1) 94 | set(HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR 1) 95 | if(CMAKE_ANDROID_ARCH_ABI MATCHES "x86|x86_64") 96 | set(HAVE_IMMINTRIN_H 1) 97 | endif() 98 | set(HAVE_INTTYPES_H 1) 99 | set(HAVE_LZIP_DECODER 1) 100 | set(HAVE_MBRTOWC 1) 101 | set(HAVE_MF_BT2 1) 102 | set(HAVE_MF_BT3 1) 103 | set(HAVE_MF_BT4 1) 104 | set(HAVE_MF_HC3 1) 105 | set(HAVE_MF_HC4 1) 106 | set(HAVE_PTHREAD_CONDATTR_SETCLOCK 1) 107 | set(HAVE_STDBOOL_H 1) 108 | set(HAVE_STDINT_H 1) 109 | set(HAVE_SYS_BYTEORDER_H 1) 110 | set(HAVE_SYS_ENDIAN_H 1) 111 | set(HAVE_SYS_PARAM_H 1) 112 | if(CMAKE_ANDROID_ARCH_ABI MATCHES "x86|x86_64") 113 | set(HAVE_USABLE_CLMUL 1) 114 | endif() 115 | set(HAVE_VISIBILITY 1) 116 | set(HAVE_WCWIDTH 1) 117 | set(HAVE__BOOL 1) 118 | set(HAVE__MM_MOVEMASK_EPI8 1) 119 | set(HAVE___BUILTIN_ASSUME_ALIGNED 1) 120 | set(HAVE___BUILTIN_BSWAPXX 1) 121 | set(MYTHREAD_POSIX 1) 122 | set(NDEBUG 1) 123 | # https://developer.android.com/ndk/guides/cpu-features#cpu_core_counts_using_libcs_sysconf3 124 | set(TUKLIB_CPUCORES_SYSCONF 1) 125 | # https://github.com/tukaani-project/xz/blob/master/m4/tuklib_integer.m4 126 | set(TUKLIB_FAST_UNALIGNED_ACCESS 1) 127 | # https://developer.android.com/reference/android/system/OsConstants#_SC_PAGESIZE 128 | # https://developer.android.com/reference/android/system/OsConstants#_SC_PHYS_PAGES 129 | set(TUKLIB_PHYSMEM_SYSCONF 1) 130 | set(_FILE_OFFSET_BITS 64) 131 | configure_file(src/main/jni/liblzma-config.h.in liblzma/config.h @ONLY) 132 | endfunction() 133 | configure_liblzma() 134 | 135 | # https://github.com/tukaani-project/xz/blob/master/src/liblzma/Makefile.am 136 | add_library(lzma STATIC 137 | # Makefile.am 138 | src/main/jni/external/xz/src/common/tuklib_physmem.c 139 | src/main/jni/external/xz/src/common/tuklib_cpucores.c 140 | # common/Makefile.inc 141 | src/main/jni/external/xz/src/liblzma/common/common.c 142 | src/main/jni/external/xz/src/liblzma/common/block_util.c 143 | src/main/jni/external/xz/src/liblzma/common/easy_preset.c 144 | src/main/jni/external/xz/src/liblzma/common/filter_common.c 145 | src/main/jni/external/xz/src/liblzma/common/hardware_physmem.c 146 | src/main/jni/external/xz/src/liblzma/common/index.c 147 | src/main/jni/external/xz/src/liblzma/common/stream_flags_common.c 148 | src/main/jni/external/xz/src/liblzma/common/string_conversion.c 149 | src/main/jni/external/xz/src/liblzma/common/vli_size.c 150 | src/main/jni/external/xz/src/liblzma/common/hardware_cputhreads.c 151 | src/main/jni/external/xz/src/liblzma/common/outqueue.c 152 | src/main/jni/external/xz/src/liblzma/common/alone_encoder.c 153 | src/main/jni/external/xz/src/liblzma/common/block_buffer_encoder.c 154 | src/main/jni/external/xz/src/liblzma/common/block_encoder.c 155 | src/main/jni/external/xz/src/liblzma/common/block_header_encoder.c 156 | src/main/jni/external/xz/src/liblzma/common/easy_buffer_encoder.c 157 | src/main/jni/external/xz/src/liblzma/common/easy_encoder.c 158 | src/main/jni/external/xz/src/liblzma/common/easy_encoder_memusage.c 159 | src/main/jni/external/xz/src/liblzma/common/filter_buffer_encoder.c 160 | src/main/jni/external/xz/src/liblzma/common/filter_encoder.c 161 | src/main/jni/external/xz/src/liblzma/common/filter_flags_encoder.c 162 | src/main/jni/external/xz/src/liblzma/common/index_encoder.c 163 | src/main/jni/external/xz/src/liblzma/common/stream_buffer_encoder.c 164 | src/main/jni/external/xz/src/liblzma/common/stream_encoder.c 165 | src/main/jni/external/xz/src/liblzma/common/stream_flags_encoder.c 166 | src/main/jni/external/xz/src/liblzma/common/vli_encoder.c 167 | src/main/jni/external/xz/src/liblzma/common/stream_encoder_mt.c 168 | src/main/jni/external/xz/src/liblzma/common/alone_decoder.c 169 | src/main/jni/external/xz/src/liblzma/common/auto_decoder.c 170 | src/main/jni/external/xz/src/liblzma/common/block_buffer_decoder.c 171 | src/main/jni/external/xz/src/liblzma/common/block_decoder.c 172 | src/main/jni/external/xz/src/liblzma/common/block_header_decoder.c 173 | src/main/jni/external/xz/src/liblzma/common/easy_decoder_memusage.c 174 | src/main/jni/external/xz/src/liblzma/common/file_info.c 175 | src/main/jni/external/xz/src/liblzma/common/filter_buffer_decoder.c 176 | src/main/jni/external/xz/src/liblzma/common/filter_decoder.c 177 | src/main/jni/external/xz/src/liblzma/common/filter_flags_decoder.c 178 | src/main/jni/external/xz/src/liblzma/common/index_decoder.c 179 | src/main/jni/external/xz/src/liblzma/common/index_hash.c 180 | src/main/jni/external/xz/src/liblzma/common/stream_buffer_decoder.c 181 | src/main/jni/external/xz/src/liblzma/common/stream_decoder.c 182 | src/main/jni/external/xz/src/liblzma/common/stream_flags_decoder.c 183 | src/main/jni/external/xz/src/liblzma/common/vli_decoder.c 184 | src/main/jni/external/xz/src/liblzma/common/stream_decoder_mt.c 185 | src/main/jni/external/xz/src/liblzma/common/lzip_decoder.c 186 | # check/Makefile.inc 187 | src/main/jni/external/xz/src/liblzma/check/check.c 188 | src/main/jni/external/xz/src/liblzma/check/crc32_fast.c 189 | src/main/jni/external/xz/src/liblzma/check/crc64_fast.c 190 | src/main/jni/external/xz/src/liblzma/check/sha256.c 191 | # lz/Makefile.inc 192 | src/main/jni/external/xz/src/liblzma/lz/lz_encoder.c 193 | src/main/jni/external/xz/src/liblzma/lz/lz_encoder_mf.c 194 | src/main/jni/external/xz/src/liblzma/lz/lz_decoder.c 195 | # lzma/Makefile.inc 196 | src/main/jni/external/xz/src/liblzma/lzma/lzma_encoder_presets.c 197 | src/main/jni/external/xz/src/liblzma/lzma/lzma_encoder.c 198 | src/main/jni/external/xz/src/liblzma/lzma/lzma_encoder_optimum_fast.c 199 | src/main/jni/external/xz/src/liblzma/lzma/lzma_encoder_optimum_normal.c 200 | src/main/jni/external/xz/src/liblzma/lzma/fastpos_table.c 201 | src/main/jni/external/xz/src/liblzma/lzma/lzma_decoder.c 202 | src/main/jni/external/xz/src/liblzma/lzma/lzma2_encoder.c 203 | src/main/jni/external/xz/src/liblzma/lzma/lzma2_decoder.c 204 | # rangecoder/Makefile.inc 205 | src/main/jni/external/xz/src/liblzma/rangecoder/price_table.c 206 | # delta/Makefile.inc 207 | src/main/jni/external/xz/src/liblzma/delta/delta_common.c 208 | src/main/jni/external/xz/src/liblzma/delta/delta_encoder.c 209 | src/main/jni/external/xz/src/liblzma/delta/delta_decoder.c 210 | # simple/Makefile.inc 211 | src/main/jni/external/xz/src/liblzma/simple/simple_coder.c 212 | src/main/jni/external/xz/src/liblzma/simple/simple_encoder.c 213 | src/main/jni/external/xz/src/liblzma/simple/simple_decoder.c 214 | src/main/jni/external/xz/src/liblzma/simple/x86.c 215 | src/main/jni/external/xz/src/liblzma/simple/powerpc.c 216 | src/main/jni/external/xz/src/liblzma/simple/ia64.c 217 | src/main/jni/external/xz/src/liblzma/simple/arm.c 218 | src/main/jni/external/xz/src/liblzma/simple/armthumb.c 219 | src/main/jni/external/xz/src/liblzma/simple/arm64.c 220 | src/main/jni/external/xz/src/liblzma/simple/sparc.c) 221 | # https://github.com/tukaani-project/xz/blob/master/src/liblzma/check/Makefile.inc 222 | if(CMAKE_ANDROID_ARCH_ABI STREQUAL "x86") 223 | target_sources(lzma 224 | PRIVATE 225 | src/main/jni/external/xz/src/liblzma/check/crc32_x86.S 226 | src/main/jni/external/xz/src/liblzma/check/crc64_x86.S) 227 | endif() 228 | target_compile_definitions(lzma 229 | PRIVATE 230 | HAVE_CONFIG_H 231 | TUKLIB_SYMBOL_PREFIX=lzma_) 232 | target_compile_options(lzma 233 | PRIVATE 234 | -Wall 235 | -Wextra 236 | -Wvla 237 | -Wformat=2 238 | -Winit-self 239 | -Wmissing-include-dirs 240 | -Wstrict-overflow=3 241 | -Wfloat-equal 242 | -Wundef 243 | -Wshadow 244 | -Wpointer-arith 245 | -Wbad-function-cast 246 | -Wwrite-strings 247 | -Wdate-time 248 | -Wsign-conversion 249 | -Wfloat-conversion 250 | -Waggregate-return 251 | -Wstrict-prototypes 252 | -Wold-style-definition 253 | -Wmissing-prototypes 254 | -Wmissing-declarations 255 | -Wredundant-decls 256 | -Wc99-compat 257 | -Wc11-extensions 258 | -Wc2x-extensions 259 | -Wpre-c2x-compat 260 | -Warray-bounds-pointer-arithmetic 261 | -Wassign-enum 262 | -Wconditional-uninitialized 263 | -Wdocumentation 264 | -Wduplicate-enum 265 | -Wempty-translation-unit 266 | -Wflexible-array-extensions 267 | -Wmissing-variable-declarations 268 | -Wnewline-eof 269 | -Wshift-sign-overflow 270 | -Wstring-conversion 271 | -Werror) 272 | target_include_directories(lzma 273 | PUBLIC 274 | src/main/jni/external/xz/src/liblzma/api 275 | PRIVATE 276 | src/main/jni/external/xz/src/liblzma/common 277 | src/main/jni/external/xz/src/liblzma/check 278 | src/main/jni/external/xz/src/liblzma/lz 279 | src/main/jni/external/xz/src/liblzma/rangecoder 280 | src/main/jni/external/xz/src/liblzma/lzma 281 | src/main/jni/external/xz/src/liblzma/delta 282 | src/main/jni/external/xz/src/liblzma/simple 283 | src/main/jni/external/xz/src/common 284 | "${CMAKE_CURRENT_BINARY_DIR}/liblzma") 285 | target_link_options(lzma 286 | PRIVATE 287 | -no-undefined 288 | -version-info 10:99:5) 289 | 290 | # https://android.googlesource.com/platform/external/lz4/+/main/lib/Android.bp 291 | add_library(lz4 STATIC 292 | src/main/jni/external/lz4/lib/lz4.c 293 | src/main/jni/external/lz4/lib/lz4hc.c 294 | src/main/jni/external/lz4/lib/lz4frame.c 295 | src/main/jni/external/lz4/lib/xxhash.c) 296 | target_compile_options(lz4 297 | PRIVATE 298 | -Wall 299 | -Werror) 300 | target_include_directories(lz4 301 | PUBLIC 302 | src/main/jni/external/lz4/lib) 303 | 304 | # https://android.googlesource.com/platform/external/zstd/+/main/Android.bp 305 | file(GLOB_RECURSE ZSTD_C_SOURCES 306 | # Don't include unnecessary deprecated/, dictBuilder/ and legacy/. 307 | #src/main/jni/external/zstd/lib/*.c 308 | src/main/jni/external/zstd/lib/common/*.c 309 | src/main/jni/external/zstd/lib/compress/*.c 310 | src/main/jni/external/zstd/lib/decompress/*.c) 311 | add_library(zstd STATIC 312 | ${ZSTD_C_SOURCES}) 313 | if(CMAKE_ANDROID_ARCH_ABI STREQUAL "x86_64") 314 | target_sources(zstd 315 | PRIVATE 316 | src/main/jni/external/zstd/lib/decompress/huf_decompress_amd64.S) 317 | endif() 318 | target_compile_options(zstd 319 | PRIVATE 320 | -Wall 321 | -Werror) 322 | target_include_directories(zstd 323 | PUBLIC 324 | src/main/jni/external/zstd/lib 325 | PRIVATE 326 | src/main/jni/external/zstd/lib/common) 327 | 328 | # https://github.com/Mbed-TLS/mbedtls/blob/v2.28.4/CMakeLists.txt 329 | # https://github.com/Mbed-TLS/mbedtls/blob/v2.28.4/library/CMakeLists.txt 330 | add_library(mbedcrypto STATIC 331 | # src_crypto 332 | src/main/jni/external/mbedtls/library/aes.c 333 | src/main/jni/external/mbedtls/library/aesni.c 334 | src/main/jni/external/mbedtls/library/arc4.c 335 | src/main/jni/external/mbedtls/library/aria.c 336 | src/main/jni/external/mbedtls/library/asn1parse.c 337 | src/main/jni/external/mbedtls/library/asn1write.c 338 | src/main/jni/external/mbedtls/library/base64.c 339 | src/main/jni/external/mbedtls/library/bignum.c 340 | src/main/jni/external/mbedtls/library/blowfish.c 341 | src/main/jni/external/mbedtls/library/camellia.c 342 | src/main/jni/external/mbedtls/library/ccm.c 343 | src/main/jni/external/mbedtls/library/chacha20.c 344 | src/main/jni/external/mbedtls/library/chachapoly.c 345 | src/main/jni/external/mbedtls/library/cipher.c 346 | src/main/jni/external/mbedtls/library/cipher_wrap.c 347 | src/main/jni/external/mbedtls/library/constant_time.c 348 | src/main/jni/external/mbedtls/library/cmac.c 349 | src/main/jni/external/mbedtls/library/ctr_drbg.c 350 | src/main/jni/external/mbedtls/library/des.c 351 | src/main/jni/external/mbedtls/library/dhm.c 352 | src/main/jni/external/mbedtls/library/ecdh.c 353 | src/main/jni/external/mbedtls/library/ecdsa.c 354 | src/main/jni/external/mbedtls/library/ecjpake.c 355 | src/main/jni/external/mbedtls/library/ecp.c 356 | src/main/jni/external/mbedtls/library/ecp_curves.c 357 | src/main/jni/external/mbedtls/library/entropy.c 358 | src/main/jni/external/mbedtls/library/entropy_poll.c 359 | src/main/jni/external/mbedtls/library/error.c 360 | src/main/jni/external/mbedtls/library/gcm.c 361 | src/main/jni/external/mbedtls/library/havege.c 362 | src/main/jni/external/mbedtls/library/hkdf.c 363 | src/main/jni/external/mbedtls/library/hmac_drbg.c 364 | src/main/jni/external/mbedtls/library/md.c 365 | src/main/jni/external/mbedtls/library/md2.c 366 | src/main/jni/external/mbedtls/library/md4.c 367 | src/main/jni/external/mbedtls/library/md5.c 368 | src/main/jni/external/mbedtls/library/memory_buffer_alloc.c 369 | src/main/jni/external/mbedtls/library/mps_reader.c 370 | src/main/jni/external/mbedtls/library/mps_trace.c 371 | src/main/jni/external/mbedtls/library/nist_kw.c 372 | src/main/jni/external/mbedtls/library/oid.c 373 | src/main/jni/external/mbedtls/library/padlock.c 374 | src/main/jni/external/mbedtls/library/pem.c 375 | src/main/jni/external/mbedtls/library/pk.c 376 | src/main/jni/external/mbedtls/library/pk_wrap.c 377 | src/main/jni/external/mbedtls/library/pkcs12.c 378 | src/main/jni/external/mbedtls/library/pkcs5.c 379 | src/main/jni/external/mbedtls/library/pkparse.c 380 | src/main/jni/external/mbedtls/library/pkwrite.c 381 | src/main/jni/external/mbedtls/library/platform.c 382 | src/main/jni/external/mbedtls/library/platform_util.c 383 | src/main/jni/external/mbedtls/library/poly1305.c 384 | src/main/jni/external/mbedtls/library/psa_crypto.c 385 | src/main/jni/external/mbedtls/library/psa_crypto_aead.c 386 | src/main/jni/external/mbedtls/library/psa_crypto_cipher.c 387 | src/main/jni/external/mbedtls/library/psa_crypto_client.c 388 | src/main/jni/external/mbedtls/library/psa_crypto_driver_wrappers.c 389 | src/main/jni/external/mbedtls/library/psa_crypto_ecp.c 390 | src/main/jni/external/mbedtls/library/psa_crypto_hash.c 391 | src/main/jni/external/mbedtls/library/psa_crypto_mac.c 392 | src/main/jni/external/mbedtls/library/psa_crypto_rsa.c 393 | src/main/jni/external/mbedtls/library/psa_crypto_se.c 394 | src/main/jni/external/mbedtls/library/psa_crypto_slot_management.c 395 | src/main/jni/external/mbedtls/library/psa_crypto_storage.c 396 | src/main/jni/external/mbedtls/library/psa_its_file.c 397 | src/main/jni/external/mbedtls/library/ripemd160.c 398 | src/main/jni/external/mbedtls/library/rsa.c 399 | src/main/jni/external/mbedtls/library/rsa_internal.c 400 | src/main/jni/external/mbedtls/library/sha1.c 401 | src/main/jni/external/mbedtls/library/sha256.c 402 | src/main/jni/external/mbedtls/library/sha512.c 403 | src/main/jni/external/mbedtls/library/threading.c 404 | src/main/jni/external/mbedtls/library/timing.c 405 | src/main/jni/external/mbedtls/library/version.c 406 | src/main/jni/external/mbedtls/library/version_features.c 407 | src/main/jni/external/mbedtls/library/xtea.c) 408 | target_compile_options(mbedcrypto 409 | PRIVATE 410 | -Wall 411 | -Wextra 412 | -Wwrite-strings 413 | -Wpointer-arith 414 | -Wimplicit-fallthrough 415 | -Wshadow 416 | -Wvla 417 | -Wformat=2 418 | -Wno-format-nonliteral 419 | -Werror 420 | -Wmissing-declarations 421 | -Wmissing-prototypes 422 | -Wdocumentation 423 | -Wno-documentation-deprecated-sync 424 | -Wunreachable-code) 425 | target_include_directories(mbedcrypto 426 | PUBLIC 427 | src/main/jni/external/mbedtls/include 428 | PRIVATE 429 | src/main/jni/external/mbedtls/library) 430 | 431 | # https://github.com/libarchive/libarchive/blob/master/CMakeLists.txt 432 | set(LIBARCHIVE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/libarchive-config") 433 | function(configure_libarchive) 434 | set(HAVE_LIBZ 1) 435 | set(HAVE_ZLIB_H 1) 436 | set(HAVE_LIBBZ2 1) 437 | set(HAVE_BZLIB_H 1) 438 | set(HAVE_LIBLZMA 1) 439 | set(HAVE_LZMA_H 1) 440 | set(HAVE_LZMA_STREAM_ENCODER_MT 1) 441 | set(HAVE_LIBLZ4 1) 442 | set(HAVE_LZ4_H 1) 443 | set(HAVE_LZ4HC_H 1) 444 | set(HAVE_ZSTD_H 1) 445 | set(HAVE_LIBZSTD 1) 446 | set(HAVE_ZSTD_compressStream 1) 447 | set(HAVE_ZSTD_minCLevel 1) 448 | set(HAVE_LIBMBEDCRYPTO 1) 449 | set(HAVE_MBEDTLS_AES_H 1) 450 | set(HAVE_MBEDTLS_MD_H 1) 451 | set(HAVE_MBEDTLS_PKCS5_H 1) 452 | set(HAVE_MBEDTLS_VERSION_H 1) 453 | set(ARCHIVE_CRYPTO_MD5_MBEDTLS 1) 454 | set(ARCHIVE_CRYPTO_RMD160_MBEDTLS 1) 455 | set(ARCHIVE_CRYPTO_SHA1_MBEDTLS 1) 456 | set(ARCHIVE_CRYPTO_SHA256_MBEDTLS 1) 457 | set(ARCHIVE_CRYPTO_SHA384_MBEDTLS 1) 458 | set(ARCHIVE_CRYPTO_SHA512_MBEDTLS 1) 459 | include(src/main/jni/LibarchiveChecks.cmake) 460 | configure_file(src/main/jni/external/libarchive/build/cmake/config.h.in 461 | "${LIBARCHIVE_CONFIG_DIR}/config.h" @ONLY) 462 | endfunction() 463 | configure_libarchive() 464 | 465 | # https://github.com/libarchive/libarchive/blob/master/libarchive/CMakeLists.txt 466 | find_package(Patch REQUIRED) 467 | set(LIBARCHIVE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/main/jni/external/libarchive/libarchive") 468 | set(LIBARCHIVE_PATCH_DIR "${CMAKE_CURRENT_BINARY_DIR}/libarchive-patch") 469 | set(LIBARCHIVE_SOURCES 470 | # libarchive_SOURCES 471 | "${LIBARCHIVE_SOURCE_DIR}/archive_acl.c" 472 | "${LIBARCHIVE_SOURCE_DIR}/archive_acl_private.h" 473 | "${LIBARCHIVE_SOURCE_DIR}/archive_check_magic.c" 474 | "${LIBARCHIVE_SOURCE_DIR}/archive_cmdline.c" 475 | "${LIBARCHIVE_SOURCE_DIR}/archive_cmdline_private.h" 476 | "${LIBARCHIVE_SOURCE_DIR}/archive_crc32.h" 477 | "${LIBARCHIVE_SOURCE_DIR}/archive_cryptor.c" 478 | "${LIBARCHIVE_SOURCE_DIR}/archive_cryptor_private.h" 479 | "${LIBARCHIVE_SOURCE_DIR}/archive_digest.c" 480 | "${LIBARCHIVE_SOURCE_DIR}/archive_digest_private.h" 481 | "${LIBARCHIVE_SOURCE_DIR}/archive_endian.h" 482 | "${LIBARCHIVE_SOURCE_DIR}/archive_entry.c" 483 | "${LIBARCHIVE_SOURCE_DIR}/archive_entry.h" 484 | "${LIBARCHIVE_SOURCE_DIR}/archive_entry_copy_stat.c" 485 | "${LIBARCHIVE_SOURCE_DIR}/archive_entry_link_resolver.c" 486 | "${LIBARCHIVE_SOURCE_DIR}/archive_entry_locale.h" 487 | "${LIBARCHIVE_SOURCE_DIR}/archive_entry_private.h" 488 | "${LIBARCHIVE_SOURCE_DIR}/archive_entry_sparse.c" 489 | "${LIBARCHIVE_SOURCE_DIR}/archive_entry_stat.c" 490 | "${LIBARCHIVE_SOURCE_DIR}/archive_entry_strmode.c" 491 | "${LIBARCHIVE_SOURCE_DIR}/archive_entry_xattr.c" 492 | "${LIBARCHIVE_SOURCE_DIR}/archive_hmac.c" 493 | "${LIBARCHIVE_SOURCE_DIR}/archive_hmac_private.h" 494 | "${LIBARCHIVE_SOURCE_DIR}/archive_match.c" 495 | "${LIBARCHIVE_SOURCE_DIR}/archive_openssl_evp_private.h" 496 | "${LIBARCHIVE_SOURCE_DIR}/archive_openssl_hmac_private.h" 497 | "${LIBARCHIVE_SOURCE_DIR}/archive_options.c" 498 | "${LIBARCHIVE_SOURCE_DIR}/archive_options_private.h" 499 | "${LIBARCHIVE_SOURCE_DIR}/archive_pack_dev.h" 500 | "${LIBARCHIVE_SOURCE_DIR}/archive_pack_dev.c" 501 | "${LIBARCHIVE_SOURCE_DIR}/archive_parse_date.c" 502 | "${LIBARCHIVE_SOURCE_DIR}/archive_pathmatch.c" 503 | "${LIBARCHIVE_SOURCE_DIR}/archive_pathmatch.h" 504 | "${LIBARCHIVE_SOURCE_DIR}/archive_platform.h" 505 | "${LIBARCHIVE_SOURCE_DIR}/archive_platform_acl.h" 506 | "${LIBARCHIVE_SOURCE_DIR}/archive_platform_xattr.h" 507 | "${LIBARCHIVE_SOURCE_DIR}/archive_ppmd_private.h" 508 | "${LIBARCHIVE_SOURCE_DIR}/archive_ppmd8.c" 509 | "${LIBARCHIVE_SOURCE_DIR}/archive_ppmd8_private.h" 510 | "${LIBARCHIVE_SOURCE_DIR}/archive_ppmd7.c" 511 | "${LIBARCHIVE_SOURCE_DIR}/archive_ppmd7_private.h" 512 | "${LIBARCHIVE_SOURCE_DIR}/archive_private.h" 513 | "${LIBARCHIVE_SOURCE_DIR}/archive_random.c" 514 | "${LIBARCHIVE_SOURCE_DIR}/archive_random_private.h" 515 | "${LIBARCHIVE_SOURCE_DIR}/archive_rb.c" 516 | "${LIBARCHIVE_SOURCE_DIR}/archive_rb.h" 517 | "${LIBARCHIVE_SOURCE_DIR}/archive_read.c" 518 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_add_passphrase.c" 519 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_append_filter.c" 520 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_data_into_fd.c" 521 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_disk_entry_from_file.c" 522 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_disk_posix.c" 523 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_disk_private.h" 524 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_disk_set_standard_lookup.c" 525 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_extract.c" 526 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_extract2.c" 527 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_open_fd.c" 528 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_open_file.c" 529 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_open_filename.c" 530 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_open_memory.c" 531 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_private.h" 532 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_set_format.c" 533 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_set_options.c" 534 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_filter_all.c" 535 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_filter_by_code.c" 536 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_filter_bzip2.c" 537 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_filter_compress.c" 538 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_filter_gzip.c" 539 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_filter_grzip.c" 540 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_filter_lrzip.c" 541 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_filter_lz4.c" 542 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_filter_lzop.c" 543 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_filter_none.c" 544 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_filter_program.c" 545 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_filter_rpm.c" 546 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_filter_uu.c" 547 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_filter_xz.c" 548 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_filter_zstd.c" 549 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_7zip.c" 550 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_all.c" 551 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_ar.c" 552 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_by_code.c" 553 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_cab.c" 554 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_cpio.c" 555 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_empty.c" 556 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_iso9660.c" 557 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_lha.c" 558 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_mtree.c" 559 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_rar.c" 560 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_rar5.c" 561 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_raw.c" 562 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_tar.c" 563 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_warc.c" 564 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_xar.c" 565 | "${LIBARCHIVE_SOURCE_DIR}/archive_read_support_format_zip.c" 566 | "${LIBARCHIVE_SOURCE_DIR}/archive_string.c" 567 | "${LIBARCHIVE_SOURCE_DIR}/archive_string.h" 568 | "${LIBARCHIVE_SOURCE_DIR}/archive_string_composition.h" 569 | "${LIBARCHIVE_SOURCE_DIR}/archive_string_sprintf.c" 570 | "${LIBARCHIVE_SOURCE_DIR}/archive_time.c" 571 | "${LIBARCHIVE_SOURCE_DIR}/archive_time_private.h" 572 | "${LIBARCHIVE_SOURCE_DIR}/archive_util.c" 573 | "${LIBARCHIVE_SOURCE_DIR}/archive_version_details.c" 574 | "${LIBARCHIVE_SOURCE_DIR}/archive_virtual.c" 575 | "${LIBARCHIVE_SOURCE_DIR}/archive_write.c" 576 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_disk_posix.c" 577 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_disk_private.h" 578 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_disk_set_standard_lookup.c" 579 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_private.h" 580 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_open_fd.c" 581 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_open_file.c" 582 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_open_filename.c" 583 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_open_memory.c" 584 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_add_filter.c" 585 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_add_filter_b64encode.c" 586 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_add_filter_by_name.c" 587 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_add_filter_bzip2.c" 588 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_add_filter_compress.c" 589 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_add_filter_grzip.c" 590 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_add_filter_gzip.c" 591 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_add_filter_lrzip.c" 592 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_add_filter_lz4.c" 593 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_add_filter_lzop.c" 594 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_add_filter_none.c" 595 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_add_filter_program.c" 596 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_add_filter_uuencode.c" 597 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_add_filter_xz.c" 598 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_add_filter_zstd.c" 599 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format.c" 600 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_7zip.c" 601 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_ar.c" 602 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_by_name.c" 603 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_cpio.c" 604 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_cpio_binary.c" 605 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_cpio_newc.c" 606 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_cpio_odc.c" 607 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_filter_by_ext.c" 608 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_gnutar.c" 609 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_iso9660.c" 610 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_mtree.c" 611 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_pax.c" 612 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_private.h" 613 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_raw.c" 614 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_shar.c" 615 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_ustar.c" 616 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_v7tar.c" 617 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_warc.c" 618 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_xar.c" 619 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_format_zip.c" 620 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_options.c" 621 | "${LIBARCHIVE_SOURCE_DIR}/archive_write_set_passphrase.c" 622 | "${LIBARCHIVE_SOURCE_DIR}/archive_xxhash.h" 623 | "${LIBARCHIVE_SOURCE_DIR}/config_freebsd.h" 624 | "${LIBARCHIVE_SOURCE_DIR}/filter_fork_posix.c" 625 | "${LIBARCHIVE_SOURCE_DIR}/filter_fork.h" 626 | "${LIBARCHIVE_SOURCE_DIR}/xxhash.c" 627 | # ARCHIVE_BLAKE2 628 | "${LIBARCHIVE_SOURCE_DIR}/archive_blake2sp_ref.c" 629 | "${LIBARCHIVE_SOURCE_DIR}/archive_blake2s_ref.c") 630 | list(TRANSFORM LIBARCHIVE_SOURCES REPLACE "${LIBARCHIVE_SOURCE_DIR}" "${LIBARCHIVE_PATCH_DIR}" 631 | OUTPUT_VARIABLE LIBARCHIVE_PATCH_SOURCES) 632 | add_custom_command(OUTPUT 633 | ${LIBARCHIVE_PATCH_SOURCES} 634 | COMMAND "${CMAKE_COMMAND}" -E copy_directory "${LIBARCHIVE_SOURCE_DIR}" 635 | "${LIBARCHIVE_PATCH_DIR}" 636 | COMMAND "${Patch_EXECUTABLE}" -i "${CMAKE_CURRENT_SOURCE_DIR}/src/main/jni/libarchive.patch" 637 | DEPENDS 638 | "${CMAKE_CURRENT_SOURCE_DIR}/src/main/jni/libarchive.patch" 639 | ${LIBARCHIVE_SOURCES} 640 | WORKING_DIRECTORY "${LIBARCHIVE_PATCH_DIR}" 641 | COMMENT "Patching libarchive" 642 | VERBATIM) 643 | add_library(archive STATIC 644 | ${LIBARCHIVE_PATCH_SOURCES}) 645 | target_compile_definitions(archive 646 | PRIVATE 647 | HAVE_CONFIG_H 648 | LIBARCHIVE_STATIC) 649 | target_compile_options(archive 650 | PRIVATE 651 | -Wall 652 | -Wformat 653 | -Wformat-security 654 | -Werror 655 | -ffunction-sections 656 | -fdata-sections) 657 | target_include_directories(archive 658 | PUBLIC 659 | "${LIBARCHIVE_PATCH_DIR}" 660 | PRIVATE 661 | src/main/jni/external/libarchive/contrib/android/include 662 | "${LIBARCHIVE_CONFIG_DIR}") 663 | target_link_libraries(archive 664 | PRIVATE 665 | "${Z_LIBRARY}" 666 | bz 667 | lzma 668 | lz4 669 | zstd 670 | mbedcrypto) 671 | target_link_options(archive 672 | PRIVATE 673 | LINKER:--gc-sections) 674 | 675 | find_library(LOG_LIBRARY log) 676 | add_library(archive-jni SHARED src/main/jni/archive-jni.c) 677 | target_compile_options(archive-jni 678 | PRIVATE 679 | -Wall 680 | -Werror) 681 | target_link_libraries(archive-jni archive "${LOG_LIBRARY}") 682 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'com.android.library' 18 | 19 | android { 20 | namespace 'me.zhanghai.android.libarchive' 21 | buildToolsVersion = '36.0.0' 22 | compileSdk 36 23 | ndkVersion '28.1.13356709' 24 | defaultConfig { 25 | minSdk 21 26 | targetSdk 36 27 | consumerProguardFiles 'proguard-rules.pro' 28 | externalNativeBuild { 29 | cmake { 30 | arguments '-DANDROID_STL=none' 31 | } 32 | } 33 | } 34 | compileOptions { 35 | sourceCompatibility JavaVersion.VERSION_1_8 36 | targetCompatibility JavaVersion.VERSION_1_8 37 | } 38 | buildTypes { 39 | release { 40 | minifyEnabled false 41 | } 42 | } 43 | externalNativeBuild { 44 | cmake { 45 | path 'CMakeLists.txt' 46 | } 47 | } 48 | } 49 | 50 | dependencies { 51 | implementation 'androidx.annotation:annotation:1.9.1' 52 | } 53 | 54 | apply plugin: 'com.vanniktech.maven.publish' 55 | -------------------------------------------------------------------------------- /library/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=libarchive-android Library 2 | -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | 23 | -keep class me.zhanghai.android.libarchive.** { *; } 24 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/libarchive/Archive.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zhanghai.android.libarchive; 18 | 19 | import android.system.ErrnoException; 20 | import android.system.Os; 21 | 22 | import java.nio.ByteBuffer; 23 | 24 | import androidx.annotation.NonNull; 25 | import androidx.annotation.Nullable; 26 | 27 | public class Archive { 28 | 29 | public static final int ERRNO_EOF = 1; 30 | public static final int ERRNO_OK = 0; 31 | public static final int ERRNO_RETRY = -10; 32 | public static final int ERRNO_WARN =-20; 33 | public static final int ERRNO_FAILED = -25; 34 | public static final int ERRNO_FATAL = -30; 35 | 36 | public static final int FILTER_NONE = 0; 37 | public static final int FILTER_GZIP = 1; 38 | public static final int FILTER_BZIP2 = 2; 39 | public static final int FILTER_COMPRESS = 3; 40 | public static final int FILTER_PROGRAM = 4; 41 | public static final int FILTER_LZMA = 5; 42 | public static final int FILTER_XZ = 6; 43 | public static final int FILTER_UU = 7; 44 | public static final int FILTER_RPM = 8; 45 | public static final int FILTER_LZIP = 9; 46 | public static final int FILTER_LRZIP = 10; 47 | public static final int FILTER_LZOP = 11; 48 | public static final int FILTER_GRZIP = 12; 49 | public static final int FILTER_LZ4 = 13; 50 | public static final int FILTER_ZSTD = 14; 51 | 52 | public static final int FORMAT_BASE_MASK = 0xff0000; 53 | public static final int FORMAT_CPIO = 0x10000; 54 | public static final int FORMAT_CPIO_POSIX = FORMAT_CPIO | 1; 55 | public static final int FORMAT_CPIO_BIN_LE = FORMAT_CPIO | 2; 56 | public static final int FORMAT_CPIO_BIN_BE = FORMAT_CPIO | 3; 57 | public static final int FORMAT_CPIO_SVR4_NOCRC = FORMAT_CPIO | 4; 58 | public static final int FORMAT_CPIO_SVR4_CRC = FORMAT_CPIO | 5; 59 | public static final int FORMAT_CPIO_AFIO_LARGE = FORMAT_CPIO | 6; 60 | public static final int FORMAT_CPIO_PWB = FORMAT_CPIO | 7; 61 | public static final int FORMAT_SHAR = 0x20000; 62 | public static final int FORMAT_SHAR_BASE = FORMAT_SHAR | 1; 63 | public static final int FORMAT_SHAR_DUMP = FORMAT_SHAR | 2; 64 | public static final int FORMAT_TAR = 0x30000; 65 | public static final int FORMAT_TAR_USTAR = FORMAT_TAR | 1; 66 | public static final int FORMAT_TAR_PAX_INTERCHANGE = FORMAT_TAR | 2; 67 | public static final int FORMAT_TAR_PAX_RESTRICTED = FORMAT_TAR | 3; 68 | public static final int FORMAT_TAR_GNUTAR = FORMAT_TAR | 4; 69 | public static final int FORMAT_ISO9660 = 0x40000; 70 | public static final int FORMAT_ISO9660_ROCKRIDGE = FORMAT_ISO9660 | 1; 71 | public static final int FORMAT_ZIP = 0x50000; 72 | public static final int FORMAT_EMPTY = 0x60000; 73 | public static final int FORMAT_AR = 0x70000; 74 | public static final int FORMAT_AR_GNU = FORMAT_AR | 1; 75 | public static final int FORMAT_AR_BSD = FORMAT_AR | 2; 76 | public static final int FORMAT_MTREE = 0x80000; 77 | public static final int FORMAT_RAW = 0x90000; 78 | public static final int FORMAT_XAR = 0xA0000; 79 | public static final int FORMAT_LHA = 0xB0000; 80 | public static final int FORMAT_CAB = 0xC0000; 81 | public static final int FORMAT_RAR = 0xD0000; 82 | public static final int FORMAT_7ZIP = 0xE0000; 83 | public static final int FORMAT_WARC = 0xF0000; 84 | public static final int FORMAT_RAR_V5 = 0x100000; 85 | 86 | public static final int READ_FORMAT_CAPS_NONE = 0; 87 | /** @noinspection PointlessBitwiseExpression*/ 88 | public static final int READ_FORMAT_CAPS_ENCRYPT_DATA = 1 << 0; 89 | public static final int READ_FORMAT_CAPS_ENCRYPT_METADATA = 1 << 1; 90 | 91 | public static final int READ_FORMAT_ENCRYPTION_UNSUPPORTED = -2; 92 | public static final int READ_FORMAT_ENCRYPTION_DONT_KNOW = -1; 93 | 94 | private static final String ENV_TMPDIR = "TMPDIR"; 95 | private static final String PROPERTY_TMPDIR = "java.io.tmpdir"; 96 | 97 | static { 98 | ensureTmpdirEnv(); 99 | System.loadLibrary("archive-jni"); 100 | } 101 | 102 | private static void ensureTmpdirEnv() { 103 | // The TMPDIR environment variable is required for writing formats like 7z which calls 104 | // mkstemp(). 105 | // /tmp isn't available on Android, and /data/local/tmp is only accessible to Shell, so we 106 | // need to set it to the app data cache directory, which we have to do manually on older 107 | // platforms. 108 | // See also 109 | // https://android.googlesource.com/platform/frameworks/base/+/d5ccb038f69193fb63b5169d7adc5da19859c9d8 110 | if (Os.getenv(ENV_TMPDIR) == null) { 111 | String tmpdir = System.getProperty(PROPERTY_TMPDIR); 112 | if (tmpdir != null) { 113 | try { 114 | Os.setenv(ENV_TMPDIR, tmpdir, true); 115 | } catch (ErrnoException e) { 116 | e.printStackTrace(); 117 | } 118 | } 119 | } 120 | } 121 | 122 | static void staticInit() {} 123 | 124 | private Archive() {} 125 | 126 | public static native int versionNumber(); 127 | @NonNull 128 | public static native byte[] versionString(); 129 | @NonNull 130 | public static native byte[] versionDetails(); 131 | 132 | @NonNull 133 | public static native byte[] zlibVersion(); 134 | @NonNull 135 | public static native byte[] liblzmaVersion(); 136 | @NonNull 137 | public static native byte[] bzlibVersion(); 138 | @NonNull 139 | public static native byte[] liblz4Version(); 140 | @NonNull 141 | public static native byte[] libzstdVersion(); 142 | @NonNull 143 | public static native byte[] mbedtlsVersion(); 144 | 145 | public static native long readNew() throws ArchiveException; 146 | 147 | public static native void readSupportFilterAll(long archive) throws ArchiveException; 148 | public static native void readSupportFilterByCode(long archive, int code) 149 | throws ArchiveException; 150 | public static void readSupportFilterBzip2(long archive) throws ArchiveException { 151 | readSupportFilterByCode(archive, FILTER_BZIP2); 152 | } 153 | public static void readSupportFilterCompress(long archive) throws ArchiveException { 154 | readSupportFilterByCode(archive, FILTER_COMPRESS); 155 | } 156 | public static void readSupportFilterGzip(long archive) throws ArchiveException { 157 | readSupportFilterByCode(archive, FILTER_GZIP); 158 | } 159 | public static void readSupportFilterGrzip(long archive) throws ArchiveException { 160 | readSupportFilterByCode(archive, FILTER_GRZIP); 161 | } 162 | public static void readSupportFilterLrzip(long archive) throws ArchiveException { 163 | readSupportFilterByCode(archive, FILTER_LRZIP); 164 | } 165 | public static void readSupportFilterLz4(long archive) throws ArchiveException { 166 | readSupportFilterByCode(archive, FILTER_LZ4); 167 | } 168 | public static void readSupportFilterLzip(long archive) throws ArchiveException { 169 | readSupportFilterByCode(archive, FILTER_LZIP); 170 | } 171 | public static void readSupportFilterLzma(long archive) throws ArchiveException { 172 | readSupportFilterByCode(archive, FILTER_LZMA); 173 | } 174 | public static void readSupportFilterLzop(long archive) throws ArchiveException { 175 | readSupportFilterByCode(archive, FILTER_LZOP); 176 | } 177 | public static void readSupportFilterNone(long archive) throws ArchiveException { 178 | readSupportFilterByCode(archive, FILTER_NONE); 179 | } 180 | public static void readSupportFilterProgram(long archive, @NonNull byte[] command) 181 | throws ArchiveException { 182 | readSupportFilterProgramSignature(archive, command, null); 183 | } 184 | public static native void readSupportFilterProgramSignature(long archive, 185 | @NonNull byte[] command, @Nullable byte[] signature) throws ArchiveException; 186 | public static void readSupportFilterRpm(long archive) throws ArchiveException { 187 | readSupportFilterByCode(archive, FILTER_RPM); 188 | } 189 | public static void readSupportFilterUu(long archive) throws ArchiveException { 190 | readSupportFilterByCode(archive, FILTER_UU); 191 | } 192 | public static void readSupportFilterXz(long archive) throws ArchiveException { 193 | readSupportFilterByCode(archive, FILTER_XZ); 194 | } 195 | public static void readSupportFilterZstd(long archive) throws ArchiveException { 196 | readSupportFilterByCode(archive, FILTER_ZSTD); 197 | } 198 | 199 | public static void readSupportFormat7zip(long archive) throws ArchiveException { 200 | readSupportFormatByCode(archive, FORMAT_7ZIP); 201 | } 202 | public static native void readSupportFormatAll(long archive) throws ArchiveException; 203 | public static void readSupportFormatAr(long archive) throws ArchiveException { 204 | readSupportFormatByCode(archive, FORMAT_AR); 205 | } 206 | public static native void readSupportFormatByCode(long archive, int code) 207 | throws ArchiveException; 208 | public static void readSupportFormatCab(long archive) throws ArchiveException { 209 | readSupportFormatByCode(archive, FORMAT_CAB); 210 | } 211 | public static void readSupportFormatCpio(long archive) throws ArchiveException { 212 | readSupportFormatByCode(archive, FORMAT_CPIO); 213 | } 214 | public static void readSupportFormatEmpty(long archive) throws ArchiveException { 215 | readSupportFormatByCode(archive, FORMAT_EMPTY); 216 | } 217 | public static void readSupportFormatGnutar(long archive) throws ArchiveException { 218 | readSupportFormatTar(archive); 219 | } 220 | public static void readSupportFormatIso9660(long archive) throws ArchiveException { 221 | readSupportFormatByCode(archive, FORMAT_ISO9660); 222 | } 223 | public static void readSupportFormatLha(long archive) throws ArchiveException { 224 | readSupportFormatByCode(archive, FORMAT_LHA); 225 | } 226 | public static void readSupportFormatMtree(long archive) throws ArchiveException { 227 | readSupportFormatByCode(archive, FORMAT_MTREE); 228 | } 229 | public static void readSupportFormatRar(long archive) throws ArchiveException { 230 | readSupportFormatByCode(archive, FORMAT_RAR); 231 | } 232 | public static void readSupportFormatRar5(long archive) throws ArchiveException { 233 | readSupportFormatByCode(archive, FORMAT_RAR_V5); 234 | } 235 | public static void readSupportFormatRaw(long archive) throws ArchiveException { 236 | readSupportFormatByCode(archive, FORMAT_RAW); 237 | } 238 | public static void readSupportFormatTar(long archive) throws ArchiveException { 239 | readSupportFormatByCode(archive, FORMAT_TAR); 240 | } 241 | public static void readSupportFormatWarc(long archive) throws ArchiveException { 242 | readSupportFormatByCode(archive, FORMAT_WARC); 243 | } 244 | public static void readSupportFormatXar(long archive) throws ArchiveException { 245 | readSupportFormatByCode(archive, FORMAT_XAR); 246 | } 247 | public static void readSupportFormatZip(long archive) throws ArchiveException { 248 | readSupportFormatByCode(archive, FORMAT_ZIP); 249 | } 250 | public static native void readSupportFormatZipStreamable(long archive) throws ArchiveException; 251 | public static native void readSupportFormatZipSeekable(long archive) throws ArchiveException; 252 | 253 | public static native void readSetFormat(long archive, int code) throws ArchiveException; 254 | public static native void readAppendFilter(long archive, int code) 255 | throws ArchiveException; 256 | public static void readAppendFilterProgram(long archive, @NonNull byte[] command) 257 | throws ArchiveException { 258 | readAppendFilterProgramSignature(archive, command, null); 259 | } 260 | public static native void readAppendFilterProgramSignature(long archive, 261 | @NonNull byte[] command, @Nullable byte[] signature) throws ArchiveException; 262 | 263 | public static native void readSetOpenCallback(long archive, 264 | @Nullable OpenCallback callback) throws ArchiveException; 265 | public static native void readSetReadCallback(long archive, 266 | @Nullable ReadCallback callback) throws ArchiveException; 267 | public static native void readSetSeekCallback(long archive, 268 | @Nullable SeekCallback callback) throws ArchiveException; 269 | public static native void readSetSkipCallback(long archive, 270 | @Nullable SkipCallback callback) throws ArchiveException; 271 | public static native void readSetCloseCallback(long archive, 272 | @Nullable CloseCallback callback) throws ArchiveException; 273 | public static native void readSetSwitchCallback(long archive, 274 | @Nullable SwitchCallback callback) throws ArchiveException; 275 | 276 | public static void readSetCallbackData(long archive, T clientData) throws ArchiveException { 277 | readSetCallbackData2(archive, clientData, 0); 278 | } 279 | public static native void readSetCallbackData2(long archive, T clientData, int index) 280 | throws ArchiveException; 281 | public static native void readAddCallbackData(long archive, T clientData, int index) 282 | throws ArchiveException; 283 | public static native void readAppendCallbackData(long archive, T clientData) 284 | throws ArchiveException; 285 | public static void readPrependCallbackData(long archive, T clientData) 286 | throws ArchiveException { 287 | readAddCallbackData(archive, clientData, 0); 288 | } 289 | 290 | public static native void readOpen1(long archive) throws ArchiveException; 291 | public static void readOpen(long archive, T clientData, 292 | @Nullable OpenCallback openCallback, @NonNull ReadCallback readCallback, 293 | @Nullable CloseCallback closeCallback) throws ArchiveException { 294 | readSetCallbackData(archive, clientData); 295 | readSetOpenCallback(archive, openCallback); 296 | readSetReadCallback(archive, readCallback); 297 | readSetCloseCallback(archive, closeCallback); 298 | readOpen1(archive); 299 | } 300 | public static void readOpen2(long archive, T clientData, 301 | @Nullable OpenCallback openCallback, @NonNull ReadCallback readCallback, 302 | @Nullable SkipCallback skipCallback, @Nullable CloseCallback closeCallback) 303 | throws ArchiveException { 304 | readSetCallbackData(archive, clientData); 305 | readSetOpenCallback(archive, openCallback); 306 | readSetReadCallback(archive, readCallback); 307 | readSetSkipCallback(archive, skipCallback); 308 | readSetCloseCallback(archive, closeCallback); 309 | readOpen1(archive); 310 | } 311 | public static native void readOpenFileName(long archive, @Nullable byte[] fileName, 312 | long blockSize) throws ArchiveException; 313 | public static native void readOpenFileNames(long archive, @NonNull byte[][] fileNames, 314 | long blockSize) throws ArchiveException; 315 | public static native void readOpenMemory(long archive, @NonNull ByteBuffer buffer) 316 | throws ArchiveException; 317 | public static native void readOpenMemoryUnsafe(long archive, long buffer, long bufferSize) 318 | throws ArchiveException; 319 | public static native void readOpenFd(long archive, int fd, long blockSize) 320 | throws ArchiveException; 321 | 322 | public static native long readNextHeader(long archive) throws ArchiveException; 323 | public static native long readNextHeader2(long archive, long entry) throws ArchiveException; 324 | public static native long readHeaderPosition(long archive) throws ArchiveException; 325 | 326 | public static native int readHasEncryptedEntries(long archive); 327 | public static native int readFormatCapabilities(long archive); 328 | 329 | public static native void readData(long archive, @NonNull ByteBuffer buffer) 330 | throws ArchiveException; 331 | public static native long seekData(long archive, long offset, int whence) 332 | throws ArchiveException; 333 | public static native void readDataSkip(long archive) throws ArchiveException; 334 | public static native void readDataIntoFd(long archive, int fd) throws ArchiveException; 335 | 336 | public static native void readSetFormatOption(long archive, @Nullable byte[] module, 337 | @NonNull byte[] option, @Nullable byte[] value) throws ArchiveException; 338 | public static native void readSetFilterOption(long archive, @Nullable byte[] module, 339 | @NonNull byte[] option, @Nullable byte[] value) throws ArchiveException; 340 | public static native void readSetOption(long archive, @Nullable byte[] module, 341 | @NonNull byte[] option, @Nullable byte[] value) throws ArchiveException; 342 | public static native void readSetOptions(long archive, @NonNull byte[] options) 343 | throws ArchiveException; 344 | 345 | public static native void readAddPassphrase(long archive, @NonNull byte[] passphrase) 346 | throws ArchiveException; 347 | public static native void readSetPassphraseCallback(long archive, T clientData, 348 | @Nullable PassphraseCallback callback) throws ArchiveException; 349 | 350 | public static native void readClose(long archive) throws ArchiveException; 351 | public static void readFree(long archive) throws ArchiveException { 352 | free(archive); 353 | } 354 | 355 | public static native long writeNew() throws ArchiveException; 356 | public static native void writeSetBytesPerBlock(long archive, int bytesPerBlock) 357 | throws ArchiveException; 358 | public static native int writeGetBytesPerBlock(long archive) throws ArchiveException; 359 | public static native void writeSetBytesInLastBlock(long archive, int bytesInLastBlock) 360 | throws ArchiveException; 361 | public static native int writeGetBytesInLastBlock(long archive) throws ArchiveException; 362 | 363 | public static native void writeAddFilter(long archive, int code) throws ArchiveException; 364 | public static native void writeAddFilterByName(long archive, @NonNull byte[] name) 365 | throws ArchiveException; 366 | public static native void writeAddFilterB64encode(long archive) throws ArchiveException; 367 | public static native void writeAddFilterBzip2(long archive) throws ArchiveException; 368 | public static native void writeAddFilterCompress(long archive) throws ArchiveException; 369 | public static native void writeAddFilterGrzip(long archive) throws ArchiveException; 370 | public static native void writeAddFilterGzip(long archive) throws ArchiveException; 371 | public static native void writeAddFilterLrzip(long archive) throws ArchiveException; 372 | public static native void writeAddFilterLz4(long archive) throws ArchiveException; 373 | public static native void writeAddFilterLzip(long archive) throws ArchiveException; 374 | public static native void writeAddFilterLzma(long archive) throws ArchiveException; 375 | public static native void writeAddFilterLzop(long archive) throws ArchiveException; 376 | public static native void writeAddFilterNone(long archive) throws ArchiveException; 377 | public static native void writeAddFilterProgram(long archive, @NonNull byte[] command) 378 | throws ArchiveException; 379 | public static native void writeAddFilterUuencode(long archive) throws ArchiveException; 380 | public static native void writeAddFilterXz(long archive) throws ArchiveException; 381 | public static native void writeAddFilterZstd(long archive) throws ArchiveException; 382 | 383 | public static native void writeSetFormat(long archive, int code) throws ArchiveException; 384 | public static native void writeSetFormatByName(long archive, @NonNull byte[] name) 385 | throws ArchiveException; 386 | public static native void writeSetFormat7zip(long archive) throws ArchiveException; 387 | public static native void writeSetFormatArBsd(long archive) throws ArchiveException; 388 | public static native void writeSetFormatArSvr4(long archive) throws ArchiveException; 389 | public static native void writeSetFormatCpio(long archive) throws ArchiveException; 390 | public static native void writeSetFormatCpioBin(long archive) throws ArchiveException; 391 | public static native void writeSetFormatCpioNewc(long archive) throws ArchiveException; 392 | public static native void writeSetFormatCpioOdc(long archive) throws ArchiveException; 393 | public static native void writeSetFormatCpioPwb(long archive) throws ArchiveException; 394 | public static native void writeSetFormatGnutar(long archive) throws ArchiveException; 395 | public static native void writeSetFormatIso9660(long archive) throws ArchiveException; 396 | public static native void writeSetFormatMtree(long archive) throws ArchiveException; 397 | public static native void writeSetFormatMtreeClassic(long archive) throws ArchiveException; 398 | public static native void writeSetFormatPax(long archive) throws ArchiveException; 399 | public static native void writeSetFormatPaxRestricted(long archive) throws ArchiveException; 400 | public static native void writeSetFormatRaw(long archive) throws ArchiveException; 401 | public static native void writeSetFormatShar(long archive) throws ArchiveException; 402 | public static native void writeSetFormatSharDump(long archive) throws ArchiveException; 403 | public static native void writeSetFormatUstar(long archive) throws ArchiveException; 404 | public static native void writeSetFormatV7tar(long archive) throws ArchiveException; 405 | public static native void writeSetFormatWarc(long archive) throws ArchiveException; 406 | public static native void writeSetFormatXar(long archive) throws ArchiveException; 407 | public static native void writeSetFormatZip(long archive) throws ArchiveException; 408 | 409 | public static native void writeSetFormatFilterByExt(long archive, @NonNull byte[] fileName) 410 | throws ArchiveException; 411 | public static native void writeSetFormatFilterByExtDef(long archive, @NonNull byte[] fileName, 412 | @NonNull byte[] defaultExtension) throws ArchiveException; 413 | 414 | public static native void writeZipSetCompressionDeflate(long archive) throws ArchiveException; 415 | public static native void writeZipSetCompressionStore(long archive) throws ArchiveException; 416 | public static native void writeZipSetCompressionLzma(long archive) throws ArchiveException; 417 | public static native void writeZipSetCompressionXz(long archive) throws ArchiveException; 418 | public static native void writeZipSetCompressionBzip2(long archive) throws ArchiveException; 419 | public static native void writeZipSetCompressionZstd(long archive) throws ArchiveException; 420 | 421 | public static void writeOpen(long archive, T clientData, 422 | @Nullable OpenCallback openCallback, @NonNull WriteCallback writeCallback, 423 | @Nullable CloseCallback closeCallback) throws ArchiveException { 424 | writeOpen2(archive, clientData, openCallback, writeCallback, closeCallback, null); 425 | } 426 | public static native void writeOpen2(long archive, T clientData, 427 | @Nullable OpenCallback openCallback, @NonNull WriteCallback writeCallback, 428 | @Nullable CloseCallback closeCallback, @Nullable FreeCallback freeCallback) 429 | throws ArchiveException; 430 | public static native void writeOpenFd(long archive, int fd) throws ArchiveException; 431 | public static native void writeOpenFileName(long archive, @NonNull byte[] fileName) 432 | throws ArchiveException; 433 | public static native void writeOpenMemory(long archive, @NonNull ByteBuffer buffer) 434 | throws ArchiveException; 435 | public static native void writeOpenMemoryUnsafe(long archive, long buffer, long bufferSize) 436 | throws ArchiveException; 437 | public static native long writeOpenMemoryGetUsed(long archive) throws ArchiveException; 438 | 439 | public static native void writeHeader(long archive, long entry) throws ArchiveException; 440 | public static native void writeData(long archive, @NonNull ByteBuffer buffer) 441 | throws ArchiveException; 442 | 443 | public static native void writeFinishEntry(long archive) throws ArchiveException; 444 | public static native void writeClose(long archive) throws ArchiveException; 445 | public static native void writeFail(long archive) throws ArchiveException; 446 | public static void writeFree(long archive) throws ArchiveException { 447 | free(archive); 448 | } 449 | 450 | public static native void writeSetFormatOption(long archive, @Nullable byte[] module, 451 | @NonNull byte[] option, @Nullable byte[] value) throws ArchiveException; 452 | public static native void writeSetFilterOption(long archive, @Nullable byte[] module, 453 | @NonNull byte[] option, @Nullable byte[] value) throws ArchiveException; 454 | public static native void writeSetOption(long archive, @Nullable byte[] module, 455 | @NonNull byte[] option, @Nullable byte[] value) throws ArchiveException; 456 | public static native void writeSetOptions(long archive, @NonNull byte[] options) 457 | throws ArchiveException; 458 | 459 | public static native void writeSetPassphrase(long archive, @NonNull byte[] passphrase) 460 | throws ArchiveException; 461 | public static native void writeSetPassphraseCallback(long archive, T clientData, 462 | @Nullable PassphraseCallback callback) throws ArchiveException; 463 | 464 | public static native void free(long archive) throws ArchiveException; 465 | 466 | public static native int filterCount(long archive); 467 | public static native long filterBytes(long archive, int index); 468 | public static native int filterCode(long archive, int index); 469 | @Nullable 470 | public static native byte[] filterName(long archive, int index); 471 | 472 | public static native long parseDate(long now, @NonNull byte[] dateString); 473 | 474 | public static native int errno(long archive); 475 | @Nullable 476 | public static native byte[] errorString(long archive); 477 | @Nullable 478 | public static native byte[] formatName(long archive); 479 | public static native int format(long archive); 480 | public static native void clearError(long archive); 481 | public static native void setError(long archive, int number, @Nullable byte[] string); 482 | public static native void copyError(long destination, long source); 483 | public static native int fileCount(long archive); 484 | @Nullable 485 | public static native byte[] charset(long archive); 486 | public static native void setCharset(long archive, @Nullable byte[] charset) 487 | throws ArchiveException; 488 | 489 | public interface ReadCallback { 490 | @Nullable 491 | ByteBuffer onRead(long archive, T clientData) throws ArchiveException; 492 | } 493 | 494 | public interface SkipCallback { 495 | long onSkip(long archive, T clientData, long request) throws ArchiveException; 496 | } 497 | 498 | public interface SeekCallback { 499 | long onSeek(long archive, T clientData, long offset, int whence) throws ArchiveException; 500 | } 501 | 502 | public interface WriteCallback { 503 | void onWrite(long archive, T clientData, @NonNull ByteBuffer buffer) 504 | throws ArchiveException; 505 | } 506 | 507 | public interface OpenCallback { 508 | void onOpen(long archive, T clientData) throws ArchiveException; 509 | } 510 | 511 | public interface CloseCallback { 512 | void onClose(long archive, T clientData) throws ArchiveException; 513 | } 514 | 515 | public interface FreeCallback { 516 | void onFree(long archive, T clientData) throws ArchiveException; 517 | } 518 | 519 | public interface SwitchCallback { 520 | void onSwitch(long archive, T clientData1, T clientData2) throws ArchiveException; 521 | } 522 | 523 | public interface PassphraseCallback { 524 | @Nullable 525 | byte[] onPassphrase(long archive, T clientData) throws ArchiveException; 526 | } 527 | } 528 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/libarchive/ArchiveEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zhanghai.android.libarchive; 18 | 19 | import java.nio.ByteBuffer; 20 | 21 | import androidx.annotation.NonNull; 22 | import androidx.annotation.Nullable; 23 | 24 | /** @noinspection OctalInteger*/ 25 | public class ArchiveEntry { 26 | 27 | static { 28 | Archive.staticInit(); 29 | } 30 | 31 | private ArchiveEntry() {} 32 | 33 | public static final int AE_IFMT = 0170000; 34 | public static final int AE_IFREG = 0100000; 35 | public static final int AE_IFLNK = 0120000; 36 | public static final int AE_IFSOCK = 0140000; 37 | public static final int AE_IFCHR = 0020000; 38 | public static final int AE_IFBLK = 0060000; 39 | public static final int AE_IFDIR = 0040000; 40 | public static final int AE_IFIFO = 0010000; 41 | 42 | public static final int AE_SYMLINK_TYPE_UNDEFINED = 0; 43 | public static final int AE_SYMLINK_TYPE_FILE = 1; 44 | public static final int AE_SYMLINK_TYPE_DIRECTORY = 2; 45 | 46 | public static final int DIGEST_MD5 = 0x00000001; 47 | public static final int DIGEST_RMD160 = 0x00000002; 48 | public static final int DIGEST_SHA1 = 0x00000003; 49 | public static final int DIGEST_SHA256 = 0x00000004; 50 | public static final int DIGEST_SHA384 = 0x00000005; 51 | public static final int DIGEST_SHA512 = 0x00000006; 52 | 53 | public static native void clear(long entry); 54 | public static native long clone(long entry); 55 | public static native void free(long entry); 56 | public static native long new1(); 57 | public static native long new2(long archive); 58 | 59 | public static native long atime(long entry); 60 | public static native long atimeNsec(long entry); 61 | public static native boolean atimeIsSet(long entry); 62 | public static native long birthtime(long entry); 63 | public static native long birthtimeNsec(long entry); 64 | public static native boolean birthtimeIsSet(long entry); 65 | public static native long ctime(long entry); 66 | public static native long ctimeNsec(long entry); 67 | public static native boolean ctimeIsSet(long entry); 68 | public static native long dev(long entry); 69 | public static native boolean devIsSet(long entry); 70 | public static native long devmajor(long entry); 71 | public static native long devminor(long entry); 72 | public static native int filetype(long entry); 73 | public static native boolean filetypeIsSet(long entry); 74 | public static native long fflagsSet(long entry); 75 | public static native long fflagsClear(long entry); 76 | @Nullable 77 | public static native byte[] fflagsText(long entry); 78 | public static native long gid(long entry); 79 | public static native boolean gidIsSet(long entry); 80 | @Nullable 81 | public static native byte[] gname(long entry); 82 | @Nullable 83 | public static native String gnameUtf8(long entry); 84 | @Nullable 85 | public static native byte[] hardlink(long entry); 86 | @Nullable 87 | public static native String hardlinkUtf8(long entry); 88 | public static native boolean hardlinkIsSet(long entry); 89 | public static native long ino(long entry); 90 | public static native boolean inoIsSet(long entry); 91 | public static native int mode(long entry); 92 | public static native long mtime(long entry); 93 | public static native long mtimeNsec(long entry); 94 | public static native boolean mtimeIsSet(long entry); 95 | public static native long nlink(long entry); 96 | @Nullable 97 | public static native byte[] pathname(long entry); 98 | @Nullable 99 | public static native String pathnameUtf8(long entry); 100 | public static native int perm(long entry); 101 | public static native boolean permIsSet(long entry); 102 | public static native boolean rdevIsSet(long entry); 103 | public static native long rdev(long entry); 104 | public static native long rdevmajor(long entry); 105 | public static native long rdevminor(long entry); 106 | @Nullable 107 | public static native byte[] sourcepath(long entry); 108 | public static native long size(long entry); 109 | public static native boolean sizeIsSet(long entry); 110 | @Nullable 111 | public static native byte[] strmode(long entry); 112 | @Nullable 113 | public static native byte[] symlink(long entry); 114 | @Nullable 115 | public static native String symlinkUtf8(long entry); 116 | public static native int symlinkType(long entry); 117 | public static native long uid(long entry); 118 | public static native boolean uidIsSet(long entry); 119 | @Nullable 120 | public static native byte[] uname(long entry); 121 | @Nullable 122 | public static native String unameUtf8(long entry); 123 | public static native boolean isDataEncrypted(long entry); 124 | public static native boolean isMetadataEncrypted(long entry); 125 | public static native boolean isEncrypted(long entry); 126 | 127 | public static native void setAtime(long entry, long atime, long atimeNsec); 128 | public static native void unsetAtime(long entry); 129 | public static native void setBirthtime(long entry, long birthtime, long birthtimeNsec); 130 | public static native void unsetBirthtime(long entry); 131 | public static native void setCtime(long entry, long ctime, long ctimeNsec); 132 | public static native void unsetCtime(long entry); 133 | public static native void setDev(long entry, long dev); 134 | public static native void setDevmajor(long entry, long devmajor); 135 | public static native void setDevminor(long entry, long devminor); 136 | public static native void setFiletype(long entry, int filetype); 137 | public static native void setFflags(long entry, long set, long clear); 138 | public static native int setFflagsText(long entry, @Nullable byte[] fflags); 139 | public static native void setGid(long entry, long gid); 140 | public static native void setGname(long entry, @Nullable byte[] gname); 141 | public static native void setGnameUtf8(long entry, @Nullable String gname); 142 | public static native boolean updateGnameUtf8(long entry, @Nullable String gname); 143 | public static native void setHardlink(long entry, @Nullable byte[] hardlink); 144 | public static native void setHardlinkUtf8(long entry, @Nullable String hardlink); 145 | public static native boolean updateHardlinkUtf8(long entry, @Nullable String hardlink); 146 | public static native void setIno(long entry, long ino); 147 | public static native void setLink(long entry, @Nullable byte[] link); 148 | public static native void setLinkUtf8(long entry, @Nullable String link); 149 | public static native boolean updateLinkUtf8(long entry, @Nullable String link); 150 | public static native void setMode(long entry, int mode); 151 | public static native void setMtime(long entry, long mtime, long mtimeNsec); 152 | public static native void unsetMtime(long entry); 153 | public static native void setNlink(long entry, int nlink); 154 | public static native void setPathname(long entry, @Nullable byte[] pathname); 155 | public static native void setPathnameUtf8(long entry, @Nullable String pathname); 156 | public static native boolean updatePathnameUtf8(long entry, @Nullable String pathname); 157 | public static native void setPerm(long entry, int perm); 158 | public static native void setRdev(long entry, long rdev); 159 | public static native void setRdevmajor(long entry, long rdevmajor); 160 | public static native void setRdevminor(long entry, long rdevminor); 161 | public static native void setSize(long entry, long size); 162 | public static native void unsetSize(long entry); 163 | public static native void setSourcepath(long entry, @Nullable byte[] sourcepath); 164 | public static native void setSymlink(long entry, @Nullable byte[] symlink); 165 | public static native void setSymlinkType(long entry, int type); 166 | public static native void setSymlinkUtf8(long entry, @Nullable String symlink); 167 | public static native boolean updateSymlinkUtf8(long entry, @Nullable String symlink); 168 | public static native void setUid(long entry, long uid); 169 | public static native void setUname(long entry, @Nullable byte[] uname); 170 | public static native void setUnameUtf8(long entry, @Nullable String uname); 171 | public static native boolean updateUnameUtf8(long entry, @Nullable String uname); 172 | public static native void setDataEncrypted(long entry, boolean encrypted); 173 | public static native void setMetadataEncrypted(long entry, boolean encrypted); 174 | 175 | @NonNull 176 | public static native StructStat stat(long entry); 177 | public static native void setStat(long entry, @NonNull StructStat stat); 178 | 179 | @Nullable 180 | public static native ByteBuffer digest(long entry, int type); 181 | 182 | public static class StructTimespec { 183 | public long tvSec; 184 | public long tvNsec; 185 | } 186 | 187 | public static class StructStat { 188 | public long stDev; 189 | public int stMode; 190 | public int stNlink; 191 | public int stUid; 192 | public int stGid; 193 | public long stRdev; 194 | public long stSize; 195 | public long stBlksize; 196 | public long stBlocks; 197 | public StructTimespec stAtim; 198 | public StructTimespec stMtim; 199 | public StructTimespec stCtim; 200 | public long stIno; 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/libarchive/ArchiveException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zhanghai.android.libarchive; 18 | 19 | import java.io.IOException; 20 | 21 | import androidx.annotation.Nullable; 22 | 23 | public class ArchiveException extends IOException { 24 | private final int mCode; 25 | 26 | public ArchiveException(int code, @Nullable String message) { 27 | this(code, message, null); 28 | } 29 | 30 | public ArchiveException(int code, @Nullable String message, 31 | @Nullable Throwable cause) { 32 | super(message, cause); 33 | 34 | mCode = code; 35 | } 36 | 37 | public int getCode() { 38 | return mCode; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /library/src/main/jni/LibarchiveChecks.cmake: -------------------------------------------------------------------------------- 1 | ../../../../third_party/libarchive/LibarchiveChecks.cmake -------------------------------------------------------------------------------- /library/src/main/jni/libarchive.patch: -------------------------------------------------------------------------------- 1 | --- archive_entry.c 2 | +++ archive_entry.c 3 | @@ -1597,6 +1597,27 @@ 4 | } 5 | } 6 | 7 | +la_ssize_t 8 | +archive_entry_digest_size(int type) 9 | +{ 10 | + switch (type) { 11 | + case ARCHIVE_ENTRY_DIGEST_MD5: 12 | + return sizeof(((struct ae_digest *) NULL)->md5); 13 | + case ARCHIVE_ENTRY_DIGEST_RMD160: 14 | + return sizeof(((struct ae_digest *) NULL)->rmd160); 15 | + case ARCHIVE_ENTRY_DIGEST_SHA1: 16 | + return sizeof(((struct ae_digest *) NULL)->sha1); 17 | + case ARCHIVE_ENTRY_DIGEST_SHA256: 18 | + return sizeof(((struct ae_digest *) NULL)->sha256); 19 | + case ARCHIVE_ENTRY_DIGEST_SHA384: 20 | + return sizeof(((struct ae_digest *) NULL)->sha384); 21 | + case ARCHIVE_ENTRY_DIGEST_SHA512: 22 | + return sizeof(((struct ae_digest *) NULL)->sha512); 23 | + default: 24 | + return -1; 25 | + } 26 | +} 27 | + 28 | int 29 | archive_entry_set_digest(struct archive_entry *entry, int type, 30 | const unsigned char *digest) 31 | --- archive_entry.h 32 | +++ archive_entry.h 33 | @@ -449,6 +449,7 @@ 34 | #define ARCHIVE_ENTRY_DIGEST_SHA512 0x00000006 35 | 36 | __LA_DECL const unsigned char * archive_entry_digest(struct archive_entry *, int /* type */); 37 | +__LA_DECL la_ssize_t archive_entry_digest_size(int /* type */); 38 | __LA_DECL int archive_entry_set_digest(struct archive_entry *, int, const unsigned char *); 39 | 40 | /* 41 | --- archive.h 42 | +++ archive.h 43 | @@ -548,6 +548,8 @@ 44 | __LA_DECL int archive_read_append_callback_data(struct archive *, void *); 45 | /* This prepends a data object to the beginning of list */ 46 | __LA_DECL int archive_read_prepend_callback_data(struct archive *, void *); 47 | +__LA_DECL unsigned int archive_read_get_callback_data_size(struct archive *); 48 | +__LA_DECL void *archive_read_get_callback_data(struct archive *, unsigned int); 49 | 50 | /* Opening freezes the callbacks. */ 51 | __LA_DECL int archive_read_open1(struct archive *); 52 | @@ -1132,6 +1134,9 @@ 53 | * NOTE: This is not intended for general date parsing, and the resulting timestamp should only be used for libarchive. */ 54 | __LA_DECL time_t archive_parse_date(time_t now, const char *datestr); 55 | 56 | +__LA_DECL void *archive_get_user_data(struct archive *); 57 | +__LA_DECL void archive_set_user_data(struct archive *, void *); 58 | + 59 | __LA_DECL int archive_errno(struct archive *); 60 | __LA_DECL const char *archive_error_string(struct archive *); 61 | __LA_DECL const char *archive_format_name(struct archive *); 62 | @@ -1142,6 +1147,8 @@ 63 | __LA_DECL void archive_copy_error(struct archive *dest, 64 | struct archive *src); 65 | __LA_DECL int archive_file_count(struct archive *); 66 | +__LA_DECL const char *archive_charset(struct archive *); 67 | +__LA_DECL int archive_set_charset(struct archive *, const char *); 68 | 69 | /* 70 | * ARCHIVE_MATCH API 71 | --- archive_private.h 72 | +++ archive_private.h 73 | @@ -117,6 +117,8 @@ 74 | /* Number of file entries processed. */ 75 | int file_count; 76 | 77 | + void *user_data; 78 | + 79 | int archive_error_number; 80 | const char *error; 81 | struct archive_string error_string; 82 | --- archive_read.c 83 | +++ archive_read.c 84 | @@ -444,6 +444,23 @@ 85 | return archive_read_add_callback_data(_a, client_data, 0); 86 | } 87 | 88 | +unsigned int archive_read_get_callback_data_size(struct archive *_a) 89 | +{ 90 | + struct archive_read *a = (struct archive_read *)_a; 91 | + return a->client.nodes; 92 | +} 93 | + 94 | +void *archive_read_get_callback_data(struct archive *_a, unsigned int iindex) 95 | +{ 96 | + struct archive_read *a = (struct archive_read *)_a; 97 | + if (iindex > a->client.nodes) { 98 | + archive_set_error(&a->archive, EINVAL, 99 | + "Invalid index specified."); 100 | + return NULL; 101 | + } 102 | + return a->client.dataset[iindex].data; 103 | +} 104 | + 105 | static const struct archive_read_filter_vtable 106 | none_reader_vtable = { 107 | .read = client_read_proxy, 108 | --- archive_util.c 109 | +++ archive_util.c 110 | @@ -99,6 +99,18 @@ 111 | return (ARCHIVE_VERSION_STRING); 112 | } 113 | 114 | +void * 115 | +archive_get_user_data(struct archive *a) 116 | +{ 117 | + return a->user_data; 118 | +} 119 | + 120 | +void 121 | +archive_set_user_data(struct archive *a, void *user_data) 122 | +{ 123 | + a->user_data = user_data; 124 | +} 125 | + 126 | int 127 | archive_errno(struct archive *a) 128 | { 129 | @@ -165,6 +177,35 @@ 130 | return archive_filter_bytes(a, 0); 131 | } 132 | 133 | +const char * 134 | +archive_charset(struct archive *a) 135 | +{ 136 | + if (a->current_code != NULL && a->current_code[0] != '\0') { 137 | + return a->current_code; 138 | + } else { 139 | + return NULL; 140 | + } 141 | +} 142 | + 143 | +int 144 | +archive_set_charset(struct archive *a, const char *charset) 145 | +{ 146 | + if (a->current_code != NULL) { 147 | + free(a->current_code); 148 | + } 149 | + if (charset != NULL && charset[0] != '\0') { 150 | + a->current_code = strdup(charset); 151 | + if (a->current_code == NULL) { 152 | + archive_set_error(a, ENOMEM, 153 | + "Can't allocate data for charset"); 154 | + return ARCHIVE_FATAL; 155 | + } 156 | + } else { 157 | + a->current_code = NULL; 158 | + } 159 | + return ARCHIVE_OK; 160 | +} 161 | + 162 | void 163 | archive_clear_error(struct archive *a) 164 | { 165 | --- archive_write_set_format_zip.c 166 | +++ archive_write_set_format_zip.c 167 | @@ -927,6 +927,9 @@ 168 | if (strcmp(archive_string_conversion_charset_name( 169 | zip->opt_sconv), "UTF-8") == 0) 170 | zip->entry_flags |= ZIP_ENTRY_FLAG_UTF8_NAME; 171 | + } else if (a->archive.current_code != NULL 172 | + && strcmp(a->archive.current_code, "UTF-8") == 0) { 173 | + zip->entry_flags |= ZIP_ENTRY_FLAG_UTF8_NAME; 174 | #if HAVE_NL_LANGINFO 175 | } else if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0) { 176 | zip->entry_flags |= ZIP_ENTRY_FLAG_UTF8_NAME; 177 | -------------------------------------------------------------------------------- /library/src/main/jni/liblzma-config.h.in: -------------------------------------------------------------------------------- 1 | #cmakedefine ENABLE_NLS 1 2 | #cmakedefine HAVE_BSWAP_16 1 3 | #cmakedefine HAVE_BSWAP_32 1 4 | #cmakedefine HAVE_BSWAP_64 1 5 | #cmakedefine HAVE_BYTESWAP_H 1 6 | #cmakedefine HAVE_CC_SHA256_CTX 1 7 | #cmakedefine HAVE_CC_SHA256_INIT 1 8 | #cmakedefine HAVE_CHECK_CRC32 1 9 | #cmakedefine HAVE_CHECK_CRC64 1 10 | #cmakedefine HAVE_CHECK_SHA256 1 11 | #cmakedefine HAVE_CLOCK_GETTIME 1 12 | #cmakedefine HAVE_CLOCK_MONOTONIC 1 13 | #cmakedefine HAVE_COMMONCRYPTO_COMMONDIGEST_H 1 14 | #cmakedefine HAVE_CPUID_H 1 15 | #cmakedefine HAVE_DECODERS 1 16 | #cmakedefine HAVE_DECODER_ARM 1 17 | #cmakedefine HAVE_DECODER_ARM64 1 18 | #cmakedefine HAVE_DECODER_ARMTHUMB 1 19 | #cmakedefine HAVE_DECODER_DELTA 1 20 | #cmakedefine HAVE_DECODER_IA64 1 21 | #cmakedefine HAVE_DECODER_LZMA1 1 22 | #cmakedefine HAVE_DECODER_LZMA2 1 23 | #cmakedefine HAVE_DECODER_POWERPC 1 24 | #cmakedefine HAVE_DECODER_SPARC 1 25 | #cmakedefine HAVE_DECODER_X86 1 26 | #cmakedefine HAVE_ENCODERS 1 27 | #cmakedefine HAVE_ENCODER_ARM 1 28 | #cmakedefine HAVE_ENCODER_ARM64 1 29 | #cmakedefine HAVE_ENCODER_ARMTHUMB 1 30 | #cmakedefine HAVE_ENCODER_DELTA 1 31 | #cmakedefine HAVE_ENCODER_IA64 1 32 | #cmakedefine HAVE_ENCODER_LZMA1 1 33 | #cmakedefine HAVE_ENCODER_LZMA2 1 34 | #cmakedefine HAVE_ENCODER_POWERPC 1 35 | #cmakedefine HAVE_ENCODER_SPARC 1 36 | #cmakedefine HAVE_ENCODER_X86 1 37 | #cmakedefine HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR 1 38 | #cmakedefine HAVE_IMMINTRIN_H 1 39 | #cmakedefine HAVE_INTTYPES_H 1 40 | #cmakedefine HAVE_LZIP_DECODER 1 41 | #cmakedefine HAVE_MBRTOWC 1 42 | #cmakedefine HAVE_MF_BT2 1 43 | #cmakedefine HAVE_MF_BT3 1 44 | #cmakedefine HAVE_MF_BT4 1 45 | #cmakedefine HAVE_MF_HC3 1 46 | #cmakedefine HAVE_MF_HC4 1 47 | #cmakedefine HAVE_PROGRAM_INVOCATION_NAME 1 48 | #cmakedefine HAVE_PTHREAD_CONDATTR_SETCLOCK 1 49 | #cmakedefine HAVE_SHA256INIT 1 50 | #cmakedefine HAVE_SHA256_CTX 1 51 | #cmakedefine HAVE_SHA256_H 1 52 | #cmakedefine HAVE_SHA256_INIT 1 53 | #cmakedefine HAVE_SHA2_CTX 1 54 | #cmakedefine HAVE_SHA2_H 1 55 | #cmakedefine HAVE_SMALL 1 56 | #cmakedefine HAVE_STDBOOL_H 1 57 | #cmakedefine HAVE_STDINT_H 1 58 | #cmakedefine HAVE_SYMBOL_VERSIONS_LINUX 1 59 | #cmakedefine HAVE_SYS_BYTEORDER_H 1 60 | #cmakedefine HAVE_SYS_ENDIAN_H 1 61 | #cmakedefine HAVE_SYS_PARAM_H 1 62 | #cmakedefine HAVE_USABLE_CLMUL 1 63 | #cmakedefine HAVE_VISIBILITY 1 64 | #cmakedefine HAVE_WCWIDTH 1 65 | #cmakedefine HAVE__BOOL 1 66 | #cmakedefine HAVE__MM_MOVEMASK_EPI8 1 67 | #cmakedefine HAVE___BUILTIN_ASSUME_ALIGNED 1 68 | #cmakedefine HAVE___BUILTIN_BSWAPXX 1 69 | #cmakedefine MYTHREAD_POSIX 1 70 | #cmakedefine MYTHREAD_VISTA 1 71 | #cmakedefine MYTHREAD_WIN95 1 72 | #cmakedefine NDEBUG 1 73 | #cmakedefine SIZEOF_SIZE_T @SIZEOF_SIZE_T@ 74 | #cmakedefine TUKLIB_CPUCORES_CPUSET 1 75 | #cmakedefine TUKLIB_CPUCORES_PSTAT_GETDYNAMIC 1 76 | #cmakedefine TUKLIB_CPUCORES_SCHED_GETAFFINITY 1 77 | #cmakedefine TUKLIB_CPUCORES_SYSCONF 1 78 | #cmakedefine TUKLIB_CPUCORES_SYSCTL 1 79 | #cmakedefine TUKLIB_FAST_UNALIGNED_ACCESS 1 80 | #cmakedefine TUKLIB_PHYSMEM_AIX 1 81 | #cmakedefine TUKLIB_PHYSMEM_GETINVENT_R 1 82 | #cmakedefine TUKLIB_PHYSMEM_GETSYSINFO 1 83 | #cmakedefine TUKLIB_PHYSMEM_PSTAT_GETSTATIC 1 84 | #cmakedefine TUKLIB_PHYSMEM_SYSCONF 1 85 | #cmakedefine TUKLIB_PHYSMEM_SYSCTL 1 86 | #cmakedefine TUKLIB_PHYSMEM_SYSINFO 1 87 | #cmakedefine TUKLIB_USE_UNSAFE_TYPE_PUNNING 1 88 | #cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@ 89 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /.cxx/ 2 | /build/ 3 | /out/ 4 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'com.android.application' 18 | 19 | android { 20 | namespace 'me.zhanghai.android.libarchive.sample' 21 | buildToolsVersion = '36.0.0' 22 | compileSdk 36 23 | defaultConfig { 24 | applicationId 'me.zhanghai.android.libarchive.sample' 25 | minSdk 21 26 | targetSdk 36 27 | versionCode Integer.parseInt(VERSION_CODE) 28 | versionName VERSION_NAME 29 | } 30 | compileOptions { 31 | sourceCompatibility JavaVersion.VERSION_1_8 32 | targetCompatibility JavaVersion.VERSION_1_8 33 | } 34 | buildTypes { 35 | release { 36 | minifyEnabled true 37 | shrinkResources true 38 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 39 | } 40 | } 41 | } 42 | 43 | dependencies { 44 | implementation project(':library') 45 | implementation 'androidx.annotation:annotation:1.9.1' 46 | } 47 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | 21 | 26 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /sample/src/main/java/me/zhanghai/android/libarchive/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zhanghai.android.libarchive.sample; 18 | 19 | import android.app.Activity; 20 | import android.content.Intent; 21 | import android.database.Cursor; 22 | import android.net.Uri; 23 | import android.os.Bundle; 24 | import android.os.ParcelFileDescriptor; 25 | import android.provider.OpenableColumns; 26 | import android.system.ErrnoException; 27 | import android.system.Os; 28 | import android.system.OsConstants; 29 | import android.text.format.DateUtils; 30 | import android.text.format.Formatter; 31 | import android.view.Menu; 32 | import android.view.MenuItem; 33 | import android.view.ViewGroup; 34 | import android.widget.HorizontalScrollView; 35 | import android.widget.ScrollView; 36 | import android.widget.TextView; 37 | 38 | import java.io.FileDescriptor; 39 | import java.io.IOException; 40 | import java.io.InterruptedIOException; 41 | import java.nio.ByteBuffer; 42 | import java.nio.charset.StandardCharsets; 43 | import java.util.concurrent.TimeUnit; 44 | 45 | import androidx.annotation.NonNull; 46 | import androidx.annotation.Nullable; 47 | import me.zhanghai.android.libarchive.Archive; 48 | import me.zhanghai.android.libarchive.ArchiveEntry; 49 | import me.zhanghai.android.libarchive.ArchiveException; 50 | 51 | public class MainActivity extends Activity { 52 | 53 | private static final int MENU_ID_OPEN = 1; 54 | 55 | private static final int REQUEST_CODE_OPEN_DOCUMENT = 1; 56 | 57 | private static final boolean READ_WITH_CALLBACKS = true; 58 | 59 | private ScrollView mScrollView; 60 | private HorizontalScrollView mHorizontalScrollView; 61 | private TextView mTextView; 62 | 63 | @Override 64 | protected void onCreate(Bundle savedInstanceState) { 65 | super.onCreate(savedInstanceState); 66 | 67 | String versionDetails = newStringFromBytes(Archive.versionDetails()); 68 | 69 | mTextView = new TextView(this); 70 | mTextView.setFitsSystemWindows(true); 71 | mTextView.setText(versionDetails); 72 | mHorizontalScrollView = new HorizontalScrollView(this); 73 | mHorizontalScrollView.setFillViewport(true); 74 | mHorizontalScrollView.setHorizontalScrollBarEnabled(true); 75 | mHorizontalScrollView.addView(mTextView, new ViewGroup.LayoutParams( 76 | ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 77 | mScrollView = new ScrollView(this); 78 | mScrollView.setFillViewport(true); 79 | mHorizontalScrollView.setVerticalScrollBarEnabled(true); 80 | mScrollView.addView(mHorizontalScrollView, new ViewGroup.LayoutParams( 81 | ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 82 | setContentView(mScrollView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 83 | ViewGroup.LayoutParams.MATCH_PARENT)); 84 | } 85 | 86 | @Override 87 | public boolean onCreateOptionsMenu(@NonNull Menu menu) { 88 | super.onCreateOptionsMenu(menu); 89 | 90 | menu.add(Menu.NONE, MENU_ID_OPEN, 0, "Open") 91 | .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); 92 | return true; 93 | } 94 | 95 | @Override 96 | public boolean onOptionsItemSelected(@NonNull MenuItem item) { 97 | //noinspection SwitchStatementWithTooFewBranches 98 | switch (item.getItemId()) { 99 | case MENU_ID_OPEN: 100 | onOpenDocument(); 101 | return true; 102 | default: 103 | return super.onOptionsItemSelected(item); 104 | } 105 | } 106 | 107 | private void onOpenDocument() { 108 | Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT) 109 | .addCategory(Intent.CATEGORY_OPENABLE) 110 | .setType("*/*"); 111 | startActivityForResult(intent, REQUEST_CODE_OPEN_DOCUMENT); 112 | } 113 | 114 | @Override 115 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { 116 | //noinspection SwitchStatementWithTooFewBranches 117 | switch (requestCode) { 118 | case REQUEST_CODE_OPEN_DOCUMENT: 119 | onOpenDocumentResult(resultCode, data); 120 | break; 121 | default: 122 | super.onActivityResult(requestCode, resultCode, data); 123 | } 124 | } 125 | 126 | private void onOpenDocumentResult(int resultCode, @Nullable Intent data) { 127 | if (resultCode != RESULT_OK || data == null) { 128 | return; 129 | } 130 | Uri uri = data.getData(); 131 | if (uri == null) { 132 | return; 133 | } 134 | // HACK: I/O on main thread. 135 | String output = readArchive(uri); 136 | mScrollView.scrollTo(0, 0); 137 | mHorizontalScrollView.scrollTo(0, 0); 138 | mTextView.setText(output); 139 | } 140 | 141 | @NonNull 142 | private String readArchive(@NonNull Uri uri) { 143 | try { 144 | StringBuilder builder = new StringBuilder(); 145 | String displayName = getUriDisplayName(uri); 146 | builder.append(displayName).append('\n'); 147 | 148 | try (ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(uri, "r")) { 149 | if (pfd == null) { 150 | throw new IOException("ContentResolver.openFileDescriptor() returned null"); 151 | } 152 | long archive = Archive.readNew(); 153 | try { 154 | Archive.setCharset(archive, 155 | StandardCharsets.UTF_8.name().getBytes(StandardCharsets.UTF_8)); 156 | Archive.readSupportFilterAll(archive); 157 | Archive.readSupportFormatAll(archive); 158 | 159 | if (READ_WITH_CALLBACKS) { 160 | Archive.readSetCallbackData(archive, pfd.getFileDescriptor()); 161 | ByteBuffer buffer = ByteBuffer.allocateDirect(8192); 162 | Archive.readSetReadCallback(archive, (_1, fd) -> { 163 | buffer.clear(); 164 | try { 165 | Os.read((FileDescriptor) fd, buffer); 166 | } catch (ErrnoException | InterruptedIOException e) { 167 | throw new ArchiveException(Archive.ERRNO_FATAL, "Os.read", e); 168 | } 169 | buffer.flip(); 170 | return buffer; 171 | }); 172 | Archive.readSetSkipCallback(archive, (_1, fd, request) -> { 173 | try { 174 | Os.lseek((FileDescriptor) fd, request, OsConstants.SEEK_CUR); 175 | } catch (ErrnoException e) { 176 | throw new ArchiveException(Archive.ERRNO_FATAL, "Os.lseek", e); 177 | } 178 | return request; 179 | }); 180 | Archive.readSetSeekCallback(archive, (_1, fd, offset, whence) -> { 181 | try { 182 | return Os.lseek((FileDescriptor) fd, offset, whence); 183 | } catch (ErrnoException e) { 184 | throw new ArchiveException(Archive.ERRNO_FATAL, "Os.lseek", e); 185 | } 186 | }); 187 | Archive.readOpen1(archive); 188 | } else { 189 | Archive.readOpenFd(archive, pfd.getFd(), 8192); 190 | } 191 | 192 | long entry = Archive.readNextHeader(archive); 193 | String formatName = newStringFromBytes(Archive.formatName(archive)); 194 | int filterCount = Archive.filterCount(archive); 195 | String filterName = filterCount > 1 ? newStringFromBytes(Archive.filterName( 196 | archive, 0)) : null; 197 | builder.append(formatName).append('\t').append(filterName).append('\n'); 198 | 199 | while (entry != 0) { 200 | String entryName = getEntryString(ArchiveEntry.pathnameUtf8(entry), 201 | ArchiveEntry.pathname(entry)); 202 | ArchiveEntry.StructStat entryStat = ArchiveEntry.stat(entry); 203 | String entrySizeString = Formatter.formatShortFileSize(this, 204 | entryStat.stSize); 205 | long entryModifiedTime = getMillisFromTimes(entryStat.stMtim.tvSec, 206 | entryStat.stMtim.tvNsec); 207 | String entryModifiedTimeString = formatDateTime(entryModifiedTime); 208 | builder.append(entrySizeString).append('\t').append(entryModifiedTimeString) 209 | .append('\t').append(entryName).append('\n'); 210 | 211 | entry = Archive.readNextHeader(archive); 212 | } 213 | } finally { 214 | Archive.free(archive); 215 | } 216 | } 217 | 218 | return builder.toString(); 219 | } catch (IOException e) { 220 | e.printStackTrace(); 221 | return e.toString(); 222 | } 223 | } 224 | 225 | @NonNull 226 | private String getUriDisplayName(@NonNull Uri uri) { 227 | try (Cursor cursor = getContentResolver().query(uri, 228 | new String[] { OpenableColumns.DISPLAY_NAME }, null, null, null)) { 229 | if (cursor != null && cursor.moveToFirst()) { 230 | int displayNameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME); 231 | if (displayNameIndex != -1) { 232 | String displayName = cursor.getString(displayNameIndex); 233 | if (displayName != null && !displayName.isEmpty()) { 234 | return displayName; 235 | } 236 | } 237 | } 238 | } 239 | String lastPathSegment = uri.getLastPathSegment(); 240 | if (lastPathSegment != null) { 241 | return lastPathSegment; 242 | } 243 | return uri.toString(); 244 | } 245 | 246 | @Nullable 247 | private String getEntryString(@Nullable String utf8, @Nullable byte[] bytes) { 248 | return utf8 != null ? utf8 : newStringFromBytes(bytes); 249 | } 250 | 251 | @Nullable 252 | private String newStringFromBytes(@Nullable byte[] bytes) { 253 | return bytes != null ? new String(bytes, StandardCharsets.UTF_8) : null; 254 | } 255 | 256 | private long getMillisFromTimes(long seconds, long nanoseconds) { 257 | return TimeUnit.SECONDS.toMillis(seconds) + TimeUnit.NANOSECONDS.toMillis(nanoseconds); 258 | } 259 | 260 | @NonNull 261 | private String formatDateTime(long millis) { 262 | return DateUtils.formatDateTime(this, millis, DateUtils.FORMAT_SHOW_TIME 263 | | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_NOON 264 | | DateUtils.FORMAT_NO_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL); 265 | } 266 | } 267 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | include ':library', ':sample' 18 | -------------------------------------------------------------------------------- /third_party/libarchive/LICENSE: -------------------------------------------------------------------------------- 1 | The libarchive distribution as a whole is Copyright by Tim Kientzle 2 | and is subject to the copyright notice reproduced at the bottom of 3 | this file. 4 | 5 | Each individual file in this distribution should have a clear 6 | copyright/licensing statement at the beginning of the file. If any do 7 | not, please let me know and I will rectify it. The following is 8 | intended to summarize the copyright status of the individual files; 9 | the actual statements in the files are controlling. 10 | 11 | * Except as listed below, all C sources (including .c and .h files) 12 | and documentation files are subject to the copyright notice reproduced 13 | at the bottom of this file. 14 | 15 | * The following source files are also subject in whole or in part to 16 | a 3-clause UC Regents copyright; please read the individual source 17 | files for details: 18 | libarchive/archive_read_support_filter_compress.c 19 | libarchive/archive_write_add_filter_compress.c 20 | libarchive/mtree.5 21 | 22 | * The following source files are in the public domain: 23 | libarchive/archive_getdate.c 24 | 25 | * The following source files are triple-licensed with the ability to choose 26 | from CC0 1.0 Universal, OpenSSL or Apache 2.0 licenses: 27 | libarchive/archive_blake2.h 28 | libarchive/archive_blake2_impl.h 29 | libarchive/archive_blake2s_ref.c 30 | libarchive/archive_blake2sp_ref.c 31 | 32 | * The build files---including Makefiles, configure scripts, 33 | and auxiliary scripts used as part of the compile process---have 34 | widely varying licensing terms. Please check individual files before 35 | distributing them to see if those restrictions apply to you. 36 | 37 | I intend for all new source code to use the license below and hope over 38 | time to replace code with other licenses with new implementations that 39 | do use the license below. The varying licensing of the build scripts 40 | seems to be an unavoidable mess. 41 | 42 | 43 | Copyright (c) 2003-2018 44 | All rights reserved. 45 | 46 | Redistribution and use in source and binary forms, with or without 47 | modification, are permitted provided that the following conditions 48 | are met: 49 | 1. Redistributions of source code must retain the above copyright 50 | notice, this list of conditions and the following disclaimer 51 | in this position and unchanged. 52 | 2. Redistributions in binary form must reproduce the above copyright 53 | notice, this list of conditions and the following disclaimer in the 54 | documentation and/or other materials provided with the distribution. 55 | 56 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 57 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 58 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 59 | IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 60 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 61 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 62 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 63 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 64 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 65 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 66 | -------------------------------------------------------------------------------- /third_party/libarchive/LibarchiveChecks.cmake: -------------------------------------------------------------------------------- 1 | # https://github.com/libarchive/libarchive/blob/master/CMakeLists.txt 2 | 3 | include(CMakePushCheckState) 4 | include(CheckIncludeFiles) 5 | include(CheckStructHasMember) 6 | include(CheckSymbolExists) 7 | include(CheckTypeSize) 8 | 9 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/external/libarchive/build/cmake) 10 | include(CheckFileOffsetBits) 11 | include(CheckFuncs) 12 | include(CheckHeaderDirent) 13 | list(POP_BACK CMAKE_MODULE_PATH) 14 | 15 | # 16 | # Check headers 17 | # 18 | CHECK_HEADER_DIRENT() 19 | 20 | SET(INCLUDES "") 21 | MACRO (LA_CHECK_INCLUDE_FILE header var) 22 | CHECK_INCLUDE_FILES("${INCLUDES};${header}" ${var}) 23 | IF (${var}) 24 | SET(INCLUDES ${INCLUDES} ${header}) 25 | ENDIF (${var}) 26 | ENDMACRO (LA_CHECK_INCLUDE_FILE) 27 | 28 | # Some FreeBSD headers assume sys/types.h was already included. 29 | LA_CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H) 30 | 31 | # Alphabetize the rest unless there's a compelling reason 32 | LA_CHECK_INCLUDE_FILE("acl/libacl.h" HAVE_ACL_LIBACL_H) 33 | LA_CHECK_INCLUDE_FILE("attr/xattr.h" HAVE_ATTR_XATTR_H) 34 | LA_CHECK_INCLUDE_FILE("ctype.h" HAVE_CTYPE_H) 35 | LA_CHECK_INCLUDE_FILE("copyfile.h" HAVE_COPYFILE_H) 36 | LA_CHECK_INCLUDE_FILE("direct.h" HAVE_DIRECT_H) 37 | LA_CHECK_INCLUDE_FILE("dlfcn.h" HAVE_DLFCN_H) 38 | LA_CHECK_INCLUDE_FILE("errno.h" HAVE_ERRNO_H) 39 | LA_CHECK_INCLUDE_FILE("ext2fs/ext2_fs.h" HAVE_EXT2FS_EXT2_FS_H) 40 | 41 | CHECK_C_SOURCE_COMPILES("#include 42 | #include 43 | int main(void) { return EXT2_IOC_GETFLAGS; }" HAVE_WORKING_EXT2_IOC_GETFLAGS) 44 | 45 | LA_CHECK_INCLUDE_FILE("fcntl.h" HAVE_FCNTL_H) 46 | LA_CHECK_INCLUDE_FILE("fnmatch.h" HAVE_FNMATCH_H) 47 | LA_CHECK_INCLUDE_FILE("grp.h" HAVE_GRP_H) 48 | LA_CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H) 49 | LA_CHECK_INCLUDE_FILE("io.h" HAVE_IO_H) 50 | LA_CHECK_INCLUDE_FILE("langinfo.h" HAVE_LANGINFO_H) 51 | LA_CHECK_INCLUDE_FILE("limits.h" HAVE_LIMITS_H) 52 | LA_CHECK_INCLUDE_FILE("linux/types.h" HAVE_LINUX_TYPES_H) 53 | LA_CHECK_INCLUDE_FILE("linux/fiemap.h" HAVE_LINUX_FIEMAP_H) 54 | LA_CHECK_INCLUDE_FILE("linux/fs.h" HAVE_LINUX_FS_H) 55 | 56 | CHECK_C_SOURCE_COMPILES("#include 57 | #include 58 | int main(void) { return FS_IOC_GETFLAGS; }" HAVE_WORKING_FS_IOC_GETFLAGS) 59 | 60 | LA_CHECK_INCLUDE_FILE("linux/magic.h" HAVE_LINUX_MAGIC_H) 61 | LA_CHECK_INCLUDE_FILE("locale.h" HAVE_LOCALE_H) 62 | LA_CHECK_INCLUDE_FILE("membership.h" HAVE_MEMBERSHIP_H) 63 | LA_CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H) 64 | LA_CHECK_INCLUDE_FILE("paths.h" HAVE_PATHS_H) 65 | LA_CHECK_INCLUDE_FILE("poll.h" HAVE_POLL_H) 66 | LA_CHECK_INCLUDE_FILE("process.h" HAVE_PROCESS_H) 67 | LA_CHECK_INCLUDE_FILE("pthread.h" HAVE_PTHREAD_H) 68 | LA_CHECK_INCLUDE_FILE("pwd.h" HAVE_PWD_H) 69 | LA_CHECK_INCLUDE_FILE("readpassphrase.h" HAVE_READPASSPHRASE_H) 70 | LA_CHECK_INCLUDE_FILE("regex.h" HAVE_REGEX_H) 71 | LA_CHECK_INCLUDE_FILE("signal.h" HAVE_SIGNAL_H) 72 | LA_CHECK_INCLUDE_FILE("spawn.h" HAVE_SPAWN_H) 73 | LA_CHECK_INCLUDE_FILE("stdarg.h" HAVE_STDARG_H) 74 | LA_CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H) 75 | LA_CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H) 76 | LA_CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H) 77 | LA_CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H) 78 | LA_CHECK_INCLUDE_FILE("sys/acl.h" HAVE_SYS_ACL_H) 79 | LA_CHECK_INCLUDE_FILE("sys/cdefs.h" HAVE_SYS_CDEFS_H) 80 | LA_CHECK_INCLUDE_FILE("sys/extattr.h" HAVE_SYS_EXTATTR_H) 81 | LA_CHECK_INCLUDE_FILE("sys/ioctl.h" HAVE_SYS_IOCTL_H) 82 | LA_CHECK_INCLUDE_FILE("sys/mkdev.h" HAVE_SYS_MKDEV_H) 83 | LA_CHECK_INCLUDE_FILE("sys/mount.h" HAVE_SYS_MOUNT_H) 84 | LA_CHECK_INCLUDE_FILE("sys/param.h" HAVE_SYS_PARAM_H) 85 | LA_CHECK_INCLUDE_FILE("sys/poll.h" HAVE_SYS_POLL_H) 86 | LA_CHECK_INCLUDE_FILE("sys/richacl.h" HAVE_SYS_RICHACL_H) 87 | LA_CHECK_INCLUDE_FILE("sys/select.h" HAVE_SYS_SELECT_H) 88 | LA_CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H) 89 | LA_CHECK_INCLUDE_FILE("sys/statfs.h" HAVE_SYS_STATFS_H) 90 | LA_CHECK_INCLUDE_FILE("sys/statvfs.h" HAVE_SYS_STATVFS_H) 91 | LA_CHECK_INCLUDE_FILE("sys/sysmacros.h" HAVE_SYS_SYSMACROS_H) 92 | LA_CHECK_INCLUDE_FILE("sys/time.h" HAVE_SYS_TIME_H) 93 | LA_CHECK_INCLUDE_FILE("sys/utime.h" HAVE_SYS_UTIME_H) 94 | LA_CHECK_INCLUDE_FILE("sys/utsname.h" HAVE_SYS_UTSNAME_H) 95 | LA_CHECK_INCLUDE_FILE("sys/vfs.h" HAVE_SYS_VFS_H) 96 | LA_CHECK_INCLUDE_FILE("sys/wait.h" HAVE_SYS_WAIT_H) 97 | LA_CHECK_INCLUDE_FILE("sys/xattr.h" HAVE_SYS_XATTR_H) 98 | LA_CHECK_INCLUDE_FILE("time.h" HAVE_TIME_H) 99 | LA_CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H) 100 | LA_CHECK_INCLUDE_FILE("utime.h" HAVE_UTIME_H) 101 | LA_CHECK_INCLUDE_FILE("wchar.h" HAVE_WCHAR_H) 102 | LA_CHECK_INCLUDE_FILE("wctype.h" HAVE_WCTYPE_H) 103 | LA_CHECK_INCLUDE_FILE("windows.h" HAVE_WINDOWS_H) 104 | IF(ENABLE_CNG) 105 | LA_CHECK_INCLUDE_FILE("bcrypt.h" HAVE_BCRYPT_H) 106 | IF(HAVE_BCRYPT_H) 107 | LIST(APPEND ADDITIONAL_LIBS "bcrypt") 108 | ENDIF(HAVE_BCRYPT_H) 109 | ELSE(ENABLE_CNG) 110 | UNSET(HAVE_BCRYPT_H CACHE) 111 | ENDIF(ENABLE_CNG) 112 | # Following files need windows.h, so we should test it after windows.h test. 113 | LA_CHECK_INCLUDE_FILE("wincrypt.h" HAVE_WINCRYPT_H) 114 | LA_CHECK_INCLUDE_FILE("winioctl.h" HAVE_WINIOCTL_H) 115 | 116 | # 117 | # Check whether use of __EXTENSIONS__ is safe. 118 | # We need some macro such as _GNU_SOURCE to use extension functions. 119 | # 120 | SET(_INCLUDE_FILES) 121 | FOREACH (it ${_HEADER}) 122 | SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n") 123 | ENDFOREACH (it) 124 | 125 | CHECK_C_SOURCE_COMPILES( 126 | "#define __EXTENSIONS__ 1 127 | ${_INCLUDE_FILES} 128 | int main() { return 0;}" 129 | SAFE_TO_DEFINE_EXTENSIONS) 130 | 131 | # 132 | # Check functions 133 | # 134 | CMAKE_PUSH_CHECK_STATE() # Save the state of the variables 135 | IF (CMAKE_C_COMPILER_ID MATCHES "^GNU$" OR 136 | CMAKE_C_COMPILER_ID MATCHES "^Clang$") 137 | # 138 | # During checking functions, we should use -fno-builtin to avoid the 139 | # failure of function detection which failure is an error "conflicting 140 | # types for built-in function" caused by using -Werror option. 141 | # 142 | SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-builtin") 143 | ENDIF (CMAKE_C_COMPILER_ID MATCHES "^GNU$" OR 144 | CMAKE_C_COMPILER_ID MATCHES "^Clang$") 145 | CHECK_SYMBOL_EXISTS(_CrtSetReportMode "crtdbg.h" HAVE__CrtSetReportMode) 146 | CHECK_FUNCTION_EXISTS_GLIBC(arc4random_buf HAVE_ARC4RANDOM_BUF) 147 | CHECK_FUNCTION_EXISTS_GLIBC(chflags HAVE_CHFLAGS) 148 | CHECK_FUNCTION_EXISTS_GLIBC(chown HAVE_CHOWN) 149 | CHECK_FUNCTION_EXISTS_GLIBC(chroot HAVE_CHROOT) 150 | CHECK_FUNCTION_EXISTS_GLIBC(ctime_r HAVE_CTIME_R) 151 | CHECK_FUNCTION_EXISTS_GLIBC(fchdir HAVE_FCHDIR) 152 | CHECK_FUNCTION_EXISTS_GLIBC(fchflags HAVE_FCHFLAGS) 153 | CHECK_FUNCTION_EXISTS_GLIBC(fchmod HAVE_FCHMOD) 154 | CHECK_FUNCTION_EXISTS_GLIBC(fchown HAVE_FCHOWN) 155 | CHECK_FUNCTION_EXISTS_GLIBC(fcntl HAVE_FCNTL) 156 | CHECK_FUNCTION_EXISTS_GLIBC(fdopendir HAVE_FDOPENDIR) 157 | CHECK_FUNCTION_EXISTS_GLIBC(fnmatch HAVE_FNMATCH) 158 | CHECK_FUNCTION_EXISTS_GLIBC(fork HAVE_FORK) 159 | CHECK_FUNCTION_EXISTS_GLIBC(fstat HAVE_FSTAT) 160 | CHECK_FUNCTION_EXISTS_GLIBC(fstatat HAVE_FSTATAT) 161 | CHECK_FUNCTION_EXISTS_GLIBC(fstatfs HAVE_FSTATFS) 162 | CHECK_FUNCTION_EXISTS_GLIBC(fstatvfs HAVE_FSTATVFS) 163 | CHECK_FUNCTION_EXISTS_GLIBC(ftruncate HAVE_FTRUNCATE) 164 | CHECK_FUNCTION_EXISTS_GLIBC(futimens HAVE_FUTIMENS) 165 | CHECK_FUNCTION_EXISTS_GLIBC(futimes HAVE_FUTIMES) 166 | CHECK_FUNCTION_EXISTS_GLIBC(futimesat HAVE_FUTIMESAT) 167 | CHECK_FUNCTION_EXISTS_GLIBC(geteuid HAVE_GETEUID) 168 | CHECK_FUNCTION_EXISTS_GLIBC(getgrgid_r HAVE_GETGRGID_R) 169 | CHECK_FUNCTION_EXISTS_GLIBC(getgrnam_r HAVE_GETGRNAM_R) 170 | CHECK_FUNCTION_EXISTS_GLIBC(getline HAVE_GETLINE) 171 | CHECK_FUNCTION_EXISTS_GLIBC(getpwnam_r HAVE_GETPWNAM_R) 172 | CHECK_FUNCTION_EXISTS_GLIBC(getpwuid_r HAVE_GETPWUID_R) 173 | CHECK_FUNCTION_EXISTS_GLIBC(getpid HAVE_GETPID) 174 | CHECK_FUNCTION_EXISTS_GLIBC(getvfsbyname HAVE_GETVFSBYNAME) 175 | CHECK_FUNCTION_EXISTS_GLIBC(gmtime_r HAVE_GMTIME_R) 176 | CHECK_FUNCTION_EXISTS_GLIBC(lchflags HAVE_LCHFLAGS) 177 | CHECK_FUNCTION_EXISTS_GLIBC(lchmod HAVE_LCHMOD) 178 | CHECK_FUNCTION_EXISTS_GLIBC(lchown HAVE_LCHOWN) 179 | CHECK_FUNCTION_EXISTS_GLIBC(link HAVE_LINK) 180 | CHECK_FUNCTION_EXISTS_GLIBC(linkat HAVE_LINKAT) 181 | CHECK_FUNCTION_EXISTS_GLIBC(localtime_r HAVE_LOCALTIME_R) 182 | CHECK_FUNCTION_EXISTS_GLIBC(lstat HAVE_LSTAT) 183 | CHECK_FUNCTION_EXISTS_GLIBC(lutimes HAVE_LUTIMES) 184 | CHECK_FUNCTION_EXISTS_GLIBC(mbrtowc HAVE_MBRTOWC) 185 | CHECK_FUNCTION_EXISTS_GLIBC(memmove HAVE_MEMMOVE) 186 | CHECK_FUNCTION_EXISTS_GLIBC(mkdir HAVE_MKDIR) 187 | CHECK_FUNCTION_EXISTS_GLIBC(mkfifo HAVE_MKFIFO) 188 | CHECK_FUNCTION_EXISTS_GLIBC(mknod HAVE_MKNOD) 189 | CHECK_FUNCTION_EXISTS_GLIBC(mkstemp HAVE_MKSTEMP) 190 | CHECK_FUNCTION_EXISTS_GLIBC(nl_langinfo HAVE_NL_LANGINFO) 191 | CHECK_FUNCTION_EXISTS_GLIBC(openat HAVE_OPENAT) 192 | CHECK_FUNCTION_EXISTS_GLIBC(pipe HAVE_PIPE) 193 | CHECK_FUNCTION_EXISTS_GLIBC(poll HAVE_POLL) 194 | CHECK_FUNCTION_EXISTS_GLIBC(posix_spawnp HAVE_POSIX_SPAWNP) 195 | CHECK_FUNCTION_EXISTS_GLIBC(readlink HAVE_READLINK) 196 | CHECK_FUNCTION_EXISTS_GLIBC(readpassphrase HAVE_READPASSPHRASE) 197 | CHECK_FUNCTION_EXISTS_GLIBC(select HAVE_SELECT) 198 | CHECK_FUNCTION_EXISTS_GLIBC(setenv HAVE_SETENV) 199 | CHECK_FUNCTION_EXISTS_GLIBC(setlocale HAVE_SETLOCALE) 200 | CHECK_FUNCTION_EXISTS_GLIBC(sigaction HAVE_SIGACTION) 201 | CHECK_FUNCTION_EXISTS_GLIBC(statfs HAVE_STATFS) 202 | CHECK_FUNCTION_EXISTS_GLIBC(statvfs HAVE_STATVFS) 203 | CHECK_FUNCTION_EXISTS_GLIBC(strchr HAVE_STRCHR) 204 | CHECK_FUNCTION_EXISTS_GLIBC(strdup HAVE_STRDUP) 205 | CHECK_FUNCTION_EXISTS_GLIBC(strerror HAVE_STRERROR) 206 | CHECK_FUNCTION_EXISTS_GLIBC(strncpy_s HAVE_STRNCPY_S) 207 | CHECK_FUNCTION_EXISTS_GLIBC(strnlen HAVE_STRNLEN) 208 | CHECK_FUNCTION_EXISTS_GLIBC(strrchr HAVE_STRRCHR) 209 | CHECK_FUNCTION_EXISTS_GLIBC(symlink HAVE_SYMLINK) 210 | CHECK_FUNCTION_EXISTS_GLIBC(sysconf HAVE_SYSCONF) 211 | CHECK_FUNCTION_EXISTS_GLIBC(tcgetattr HAVE_TCGETATTR) 212 | CHECK_FUNCTION_EXISTS_GLIBC(tcsetattr HAVE_TCSETATTR) 213 | CHECK_FUNCTION_EXISTS_GLIBC(timegm HAVE_TIMEGM) 214 | CHECK_FUNCTION_EXISTS_GLIBC(tzset HAVE_TZSET) 215 | CHECK_FUNCTION_EXISTS_GLIBC(unlinkat HAVE_UNLINKAT) 216 | CHECK_FUNCTION_EXISTS_GLIBC(unsetenv HAVE_UNSETENV) 217 | CHECK_FUNCTION_EXISTS_GLIBC(utime HAVE_UTIME) 218 | CHECK_FUNCTION_EXISTS_GLIBC(utimes HAVE_UTIMES) 219 | CHECK_FUNCTION_EXISTS_GLIBC(utimensat HAVE_UTIMENSAT) 220 | CHECK_FUNCTION_EXISTS_GLIBC(vfork HAVE_VFORK) 221 | CHECK_FUNCTION_EXISTS_GLIBC(wcrtomb HAVE_WCRTOMB) 222 | check_symbol_exists(wcscmp wchar.h HAVE_WCSCMP) 223 | check_symbol_exists(wcscpy wchar.h HAVE_WCSCPY) 224 | check_symbol_exists(wcslen wchar.h HAVE_WCSLEN) 225 | CHECK_FUNCTION_EXISTS_GLIBC(wctomb HAVE_WCTOMB) 226 | CHECK_FUNCTION_EXISTS_GLIBC(_fseeki64 HAVE__FSEEKI64) 227 | CHECK_FUNCTION_EXISTS_GLIBC(_get_timezone HAVE__GET_TIMEZONE) 228 | CHECK_SYMBOL_EXISTS(ctime_s "time.h" HAVE_CTIME_S) 229 | CHECK_SYMBOL_EXISTS(gmtime_s "time.h" HAVE_GMTIME_S) 230 | CHECK_SYMBOL_EXISTS(localtime_s "time.h" HAVE_LOCALTIME_S) 231 | CHECK_SYMBOL_EXISTS(_mkgmtime "time.h" HAVE__MKGMTIME) 232 | 233 | SET(CMAKE_REQUIRED_LIBRARIES "") 234 | CHECK_FUNCTION_EXISTS(cygwin_conv_path HAVE_CYGWIN_CONV_PATH) 235 | CHECK_FUNCTION_EXISTS(fseeko HAVE_FSEEKO) 236 | CHECK_FUNCTION_EXISTS(strerror_r HAVE_STRERROR_R) 237 | CHECK_FUNCTION_EXISTS(strftime HAVE_STRFTIME) 238 | CHECK_FUNCTION_EXISTS(vprintf HAVE_VPRINTF) 239 | CHECK_FUNCTION_EXISTS(wmemcmp HAVE_WMEMCMP) 240 | CHECK_FUNCTION_EXISTS(wmemcpy HAVE_WMEMCPY) 241 | CHECK_FUNCTION_EXISTS(wmemmove HAVE_WMEMMOVE) 242 | 243 | CMAKE_POP_CHECK_STATE() # Restore the state of the variables 244 | 245 | CHECK_C_SOURCE_COMPILES( 246 | "#include \n#include \nint main(void) { struct vfsconf v; return sizeof(v);}" 247 | HAVE_STRUCT_VFSCONF) 248 | 249 | CHECK_C_SOURCE_COMPILES( 250 | "#include \n#include \nint main(void) { struct xvfsconf v; return sizeof(v);}" 251 | HAVE_STRUCT_XVFSCONF) 252 | 253 | CHECK_C_SOURCE_COMPILES( 254 | "#include \n#include \nint main(void) { struct statfs s; return sizeof(s);}" 255 | HAVE_STRUCT_STATFS) 256 | 257 | # Make sure we have the POSIX version of readdir_r, not the 258 | # older 2-argument version. 259 | CHECK_C_SOURCE_COMPILES( 260 | "#include \nint main() {DIR *d = opendir(\".\"); struct dirent e,*r; return readdir_r(d,&e,&r);}" 261 | HAVE_READDIR_R) 262 | 263 | # dirfd can be either a function or a macro. 264 | CHECK_C_SOURCE_COMPILES( 265 | "#include \nint main() {DIR *d = opendir(\".\"); return dirfd(d);}" 266 | HAVE_DIRFD) 267 | 268 | # Only detect readlinkat() if we also have AT_FDCWD in unistd.h. 269 | # NOTE: linux requires fcntl.h for AT_FDCWD. 270 | CHECK_C_SOURCE_COMPILES( 271 | "#include \n#include \nint main() {char buf[10]; return readlinkat(AT_FDCWD, \"\", buf, 0);}" 272 | HAVE_READLINKAT) 273 | 274 | # To verify major(), we need to both include the header 275 | # of interest and verify that the result can be linked. 276 | # CHECK_FUNCTION_EXISTS doesn't accept a header argument, 277 | # CHECK_SYMBOL_EXISTS doesn't test linkage. 278 | CHECK_C_SOURCE_COMPILES( 279 | "#include \nint main() { return major(256); }" 280 | MAJOR_IN_MKDEV) 281 | CHECK_C_SOURCE_COMPILES( 282 | "#include \nint main() { return major(256); }" 283 | MAJOR_IN_SYSMACROS) 284 | 285 | IF(HAVE_STRERROR_R) 286 | SET(HAVE_DECL_STRERROR_R 1) 287 | ENDIF(HAVE_STRERROR_R) 288 | 289 | # 290 | # Check defines 291 | # 292 | SET(headers "limits.h") 293 | IF(HAVE_STDINT_H) 294 | LIST(APPEND headers "stdint.h") 295 | ENDIF(HAVE_STDINT_H) 296 | IF(HAVE_INTTYPES_H) 297 | LIST(APPEND headers "inttypes.h") 298 | ENDIF(HAVE_INTTYPES_H) 299 | CHECK_SYMBOL_EXISTS(EFTYPE "errno.h" HAVE_EFTYPE) 300 | CHECK_SYMBOL_EXISTS(EILSEQ "errno.h" HAVE_EILSEQ) 301 | CHECK_SYMBOL_EXISTS(D_MD_ORDER "langinfo.h" HAVE_D_MD_ORDER) 302 | CHECK_SYMBOL_EXISTS(INT32_MAX "${headers}" HAVE_DECL_INT32_MAX) 303 | CHECK_SYMBOL_EXISTS(INT32_MIN "${headers}" HAVE_DECL_INT32_MIN) 304 | CHECK_SYMBOL_EXISTS(INT64_MAX "${headers}" HAVE_DECL_INT64_MAX) 305 | CHECK_SYMBOL_EXISTS(INT64_MIN "${headers}" HAVE_DECL_INT64_MIN) 306 | CHECK_SYMBOL_EXISTS(INTMAX_MAX "${headers}" HAVE_DECL_INTMAX_MAX) 307 | CHECK_SYMBOL_EXISTS(INTMAX_MIN "${headers}" HAVE_DECL_INTMAX_MIN) 308 | CHECK_SYMBOL_EXISTS(UINT32_MAX "${headers}" HAVE_DECL_UINT32_MAX) 309 | CHECK_SYMBOL_EXISTS(UINT64_MAX "${headers}" HAVE_DECL_UINT64_MAX) 310 | CHECK_SYMBOL_EXISTS(UINTMAX_MAX "${headers}" HAVE_DECL_UINTMAX_MAX) 311 | CHECK_SYMBOL_EXISTS(SIZE_MAX "${headers}" HAVE_DECL_SIZE_MAX) 312 | CHECK_SYMBOL_EXISTS(SSIZE_MAX "limits.h" HAVE_DECL_SSIZE_MAX) 313 | 314 | # 315 | # Check struct members 316 | # 317 | # Check for tm_gmtoff in struct tm 318 | CHECK_STRUCT_HAS_MEMBER("struct tm" tm_gmtoff 319 | "time.h" HAVE_STRUCT_TM_TM_GMTOFF) 320 | CHECK_STRUCT_HAS_MEMBER("struct tm" __tm_gmtoff 321 | "time.h" HAVE_STRUCT_TM___TM_GMTOFF) 322 | 323 | IF(HAVE_STRUCT_STATFS) 324 | # Check for f_namemax in struct statfs 325 | CHECK_STRUCT_HAS_MEMBER("struct statfs" f_namemax 326 | "sys/param.h;sys/mount.h" HAVE_STRUCT_STATFS_F_NAMEMAX) 327 | # Check for f_iosize in struct statfs 328 | CHECK_STRUCT_HAS_MEMBER("struct statfs" f_iosize 329 | "sys/param.h;sys/mount.h" HAVE_STRUCT_STATFS_F_IOSIZE) 330 | ENDIF(HAVE_STRUCT_STATFS) 331 | 332 | # Check for birthtime in struct stat 333 | CHECK_STRUCT_HAS_MEMBER("struct stat" st_birthtime 334 | "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_BIRTHTIME) 335 | 336 | # Check for high-resolution timestamps in struct stat 337 | CHECK_STRUCT_HAS_MEMBER("struct stat" st_birthtimespec.tv_nsec 338 | "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC) 339 | CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec 340 | "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) 341 | CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec 342 | "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) 343 | CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtime_n 344 | "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIME_N) 345 | CHECK_STRUCT_HAS_MEMBER("struct stat" st_umtime 346 | "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_UMTIME) 347 | CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtime_usec 348 | "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIME_USEC) 349 | # Check for block size support in struct stat 350 | CHECK_STRUCT_HAS_MEMBER("struct stat" st_blksize 351 | "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_BLKSIZE) 352 | # Check for st_flags in struct stat (BSD fflags) 353 | CHECK_STRUCT_HAS_MEMBER("struct stat" st_flags 354 | "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_FLAGS) 355 | 356 | IF(HAVE_SYS_STATVFS_H) 357 | CHECK_STRUCT_HAS_MEMBER("struct statvfs" f_iosize 358 | "sys/types.h;sys/statvfs.h" HAVE_STRUCT_STATVFS_F_IOSIZE) 359 | ENDIF() 360 | 361 | # 362 | # 363 | CHECK_STRUCT_HAS_MEMBER("struct tm" tm_sec 364 | "sys/types.h;sys/time.h;time.h" HAVE_SYS_TIME_H) 365 | 366 | # 367 | # Check for integer types 368 | # 369 | # 370 | CHECK_TYPE_SIZE("short" SIZEOF_SHORT) 371 | CHECK_TYPE_SIZE("int" SIZEOF_INT) 372 | CHECK_TYPE_SIZE("long" SIZEOF_LONG) 373 | CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG) 374 | 375 | CHECK_TYPE_SIZE("unsigned short" SIZEOF_UNSIGNED_SHORT) 376 | CHECK_TYPE_SIZE("unsigned" SIZEOF_UNSIGNED) 377 | CHECK_TYPE_SIZE("unsigned long" SIZEOF_UNSIGNED_LONG) 378 | CHECK_TYPE_SIZE("unsigned long long" SIZEOF_UNSIGNED_LONG_LONG) 379 | 380 | CHECK_TYPE_SIZE("__int64" __INT64) 381 | CHECK_TYPE_SIZE("unsigned __int64" UNSIGNED___INT64) 382 | 383 | CHECK_TYPE_SIZE(int16_t INT16_T) 384 | CHECK_TYPE_SIZE(int32_t INT32_T) 385 | CHECK_TYPE_SIZE(int64_t INT64_T) 386 | CHECK_TYPE_SIZE(intmax_t INTMAX_T) 387 | CHECK_TYPE_SIZE(uint8_t UINT8_T) 388 | CHECK_TYPE_SIZE(uint16_t UINT16_T) 389 | CHECK_TYPE_SIZE(uint32_t UINT32_T) 390 | CHECK_TYPE_SIZE(uint64_t UINT64_T) 391 | CHECK_TYPE_SIZE(uintmax_t UINTMAX_T) 392 | 393 | CHECK_TYPE_SIZE(dev_t DEV_T) 394 | IF(NOT HAVE_DEV_T) 395 | IF(MSVC) 396 | SET(dev_t "unsigned int") 397 | ENDIF(MSVC) 398 | ENDIF(NOT HAVE_DEV_T) 399 | # 400 | CHECK_TYPE_SIZE(gid_t GID_T) 401 | IF(NOT HAVE_GID_T) 402 | IF(WIN32) 403 | SET(gid_t "short") 404 | ELSE(WIN32) 405 | SET(gid_t "unsigned int") 406 | ENDIF(WIN32) 407 | ENDIF(NOT HAVE_GID_T) 408 | # 409 | CHECK_TYPE_SIZE(id_t ID_T) 410 | IF(NOT HAVE_ID_T) 411 | IF(WIN32) 412 | SET(id_t "short") 413 | ELSE(WIN32) 414 | SET(id_t "unsigned int") 415 | ENDIF(WIN32) 416 | ENDIF(NOT HAVE_ID_T) 417 | # 418 | CHECK_TYPE_SIZE(mode_t MODE_T) 419 | IF(NOT HAVE_MODE_T) 420 | IF(WIN32) 421 | SET(mode_t "unsigned short") 422 | ELSE(WIN32) 423 | SET(mode_t "int") 424 | ENDIF(WIN32) 425 | ENDIF(NOT HAVE_MODE_T) 426 | # 427 | CHECK_TYPE_SIZE(off_t OFF_T) 428 | IF(NOT HAVE_OFF_T) 429 | SET(off_t "__int64") 430 | ENDIF(NOT HAVE_OFF_T) 431 | # 432 | CHECK_TYPE_SIZE(size_t SIZE_T) 433 | IF(NOT HAVE_SIZE_T) 434 | IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) 435 | SET(size_t "uint64_t") 436 | ELSE("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) 437 | SET(size_t "uint32_t") 438 | ENDIF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) 439 | ENDIF(NOT HAVE_SIZE_T) 440 | # 441 | CHECK_TYPE_SIZE(ssize_t SSIZE_T) 442 | IF(NOT HAVE_SSIZE_T) 443 | IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) 444 | SET(ssize_t "int64_t") 445 | ELSE("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) 446 | SET(ssize_t "long") 447 | ENDIF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) 448 | ENDIF(NOT HAVE_SSIZE_T) 449 | # 450 | CHECK_TYPE_SIZE(uid_t UID_T) 451 | IF(NOT HAVE_UID_T) 452 | IF(WIN32) 453 | SET(uid_t "short") 454 | ELSE(WIN32) 455 | SET(uid_t "unsigned int") 456 | ENDIF(WIN32) 457 | ENDIF(NOT HAVE_UID_T) 458 | # 459 | CHECK_TYPE_SIZE(pid_t PID_T) 460 | IF(NOT HAVE_PID_T) 461 | IF(WIN32) 462 | SET(pid_t "int") 463 | ELSE(WIN32) 464 | MESSAGE(FATAL_ERROR "pid_t doesn't exist on this platform?") 465 | ENDIF(WIN32) 466 | ENDIF(NOT HAVE_PID_T) 467 | # 468 | CHECK_TYPE_SIZE(intptr_t INTPTR_T) 469 | IF(NOT HAVE_INTPTR_T) 470 | IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) 471 | SET(intptr_t "int64_t") 472 | ELSE() 473 | SET(intptr_t "int32_t") 474 | ENDIF() 475 | ENDIF(NOT HAVE_INTPTR_T) 476 | # 477 | CHECK_TYPE_SIZE(uintptr_t UINTPTR_T) 478 | IF(NOT HAVE_UINTPTR_T) 479 | IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) 480 | SET(uintptr_t "uint64_t") 481 | ELSE() 482 | SET(uintptr_t "uint32_t") 483 | ENDIF() 484 | ENDIF(NOT HAVE_UINTPTR_T) 485 | # 486 | CHECK_TYPE_SIZE(wchar_t SIZEOF_WCHAR_T) 487 | IF(HAVE_SIZEOF_WCHAR_T) 488 | SET(HAVE_WCHAR_T 1) 489 | ENDIF(HAVE_SIZEOF_WCHAR_T) 490 | # 491 | # Check if _FILE_OFFSET_BITS macro needed for large files 492 | # 493 | CHECK_FILE_OFFSET_BITS() 494 | 495 | # 496 | # Check for Extended Attribute libraries, headers, and functions 497 | # 498 | IF(ENABLE_XATTR) 499 | CHECK_LIBRARY_EXISTS(attr "setxattr" "" HAVE_LIBATTR) 500 | IF(HAVE_LIBATTR) 501 | SET(CMAKE_REQUIRED_LIBRARIES "attr") 502 | pkg_check_modules(LIBATTR libattr) 503 | IF(LIBATTR_VERSION) 504 | SET(LIBATTR_PKGCONFIG_VERSION ${LIBATTR_VERSION}) 505 | ENDIF(LIBATTR_VERSION) 506 | ELSE(HAVE_LIBATTR) 507 | CHECK_LIBRARY_EXISTS(gnu "setxattr" "" HAVE_LIBATTR_GNU) 508 | IF(HAVE_LIBATTR_GNU) 509 | SET(CMAKE_REQUIRED_LIBRARIES "gnu") 510 | ENDIF() 511 | UNSET(LIBATTR_PKGCONFIG_VERSION CACHE) 512 | ENDIF(HAVE_LIBATTR) 513 | CHECK_SYMBOL_EXISTS(EXTATTR_NAMESPACE_USER "sys/types.h;sys/extattr.h" HAVE_DECL_EXTATTR_NAMESPACE_USER) 514 | CHECK_SYMBOL_EXISTS(XATTR_NOFOLLOW "sys/xattr.h" HAVE_DECL_XATTR_NOFOLLOW) 515 | IF(HAVE_SYS_XATTR_H AND HAVE_DECL_XATTR_NOFOLLOW) 516 | CHECK_FUNCTION_EXISTS(fgetxattr HAVE_FGETXATTR) 517 | CHECK_FUNCTION_EXISTS(flistxattr HAVE_FLISTXATTR) 518 | CHECK_FUNCTION_EXISTS(fsetxattr HAVE_FSETXATTR) 519 | CHECK_FUNCTION_EXISTS(getxattr HAVE_GETXATTR) 520 | CHECK_FUNCTION_EXISTS(listxattr HAVE_LISTXATTR) 521 | CHECK_FUNCTION_EXISTS(setxattr HAVE_SETXATTR) 522 | IF(HAVE_FGETXATTR AND 523 | HAVE_FLISTXATTR AND 524 | HAVE_FSETXATTR AND 525 | HAVE_GETXATTR AND 526 | HAVE_LISTXATTR AND 527 | HAVE_SETXATTR) 528 | SET(ARCHIVE_XATTR_DARWIN TRUE) 529 | ENDIF() 530 | ELSEIF(HAVE_SYS_EXTATTR_H AND HAVE_DECL_EXTATTR_NAMESPACE_USER) 531 | # FreeBSD xattr support 532 | CHECK_FUNCTION_EXISTS(extattr_get_fd HAVE_EXTATTR_GET_FD) 533 | CHECK_FUNCTION_EXISTS(extattr_get_file HAVE_EXTATTR_GET_FILE) 534 | CHECK_FUNCTION_EXISTS(extattr_get_link HAVE_EXTATTR_GET_LINK) 535 | CHECK_FUNCTION_EXISTS(extattr_list_fd HAVE_EXTATTR_LIST_FD) 536 | CHECK_FUNCTION_EXISTS(extattr_list_file HAVE_EXTATTR_LIST_FILE) 537 | CHECK_FUNCTION_EXISTS(extattr_list_link HAVE_EXTATTR_LIST_LINK) 538 | CHECK_FUNCTION_EXISTS(extattr_set_fd HAVE_EXTATTR_SET_FD) 539 | CHECK_FUNCTION_EXISTS(extattr_set_link HAVE_EXTATTR_SET_LINK) 540 | IF(HAVE_EXTATTR_GET_FD AND 541 | HAVE_EXTATTR_GET_FILE AND 542 | HAVE_EXTATTR_GET_LINK AND 543 | HAVE_EXTATTR_LIST_FD AND 544 | HAVE_EXTATTR_LIST_FILE AND 545 | HAVE_EXTATTR_LIST_LINK AND 546 | HAVE_EXTATTR_SET_FD AND 547 | HAVE_EXTATTR_SET_LINK) 548 | SET(ARCHIVE_XATTR_FREEBSD TRUE) 549 | ENDIF() 550 | ELSEIF(HAVE_SYS_XATTR_H OR HAVE_ATTR_XATTR_H) 551 | # Linux xattr support 552 | CHECK_FUNCTION_EXISTS_GLIBC(fgetxattr HAVE_FGETXATTR) 553 | CHECK_FUNCTION_EXISTS_GLIBC(flistxattr HAVE_FLISTXATTR) 554 | CHECK_FUNCTION_EXISTS_GLIBC(fsetxattr HAVE_FSETXATTR) 555 | CHECK_FUNCTION_EXISTS_GLIBC(getxattr HAVE_GETXATTR) 556 | CHECK_FUNCTION_EXISTS_GLIBC(lgetxattr HAVE_LGETXATTR) 557 | CHECK_FUNCTION_EXISTS_GLIBC(listxattr HAVE_LISTXATTR) 558 | CHECK_FUNCTION_EXISTS_GLIBC(llistxattr HAVE_LLISTXATTR) 559 | CHECK_FUNCTION_EXISTS_GLIBC(lsetxattr HAVE_LSETXATTR) 560 | IF(HAVE_FGETXATTR AND 561 | HAVE_FLISTXATTR AND 562 | HAVE_FSETXATTR AND 563 | HAVE_GETXATTR AND 564 | HAVE_LGETXATTR AND 565 | HAVE_LISTXATTR AND 566 | HAVE_LLISTXATTR AND 567 | HAVE_LSETXATTR) 568 | SET(ARCHIVE_XATTR_LINUX TRUE) 569 | ENDIF() 570 | ELSEIF(HAVE_SYS_EA_H) 571 | # AIX xattr support 572 | CHECK_FUNCTION_EXISTS(fgetea HAVE_FGETEA) 573 | CHECK_FUNCTION_EXISTS(flistea HAVE_FLISTEA) 574 | CHECK_FUNCTION_EXISTS(fsetea HAVE_FSETEA) 575 | CHECK_FUNCTION_EXISTS(getea HAVE_GETEA) 576 | CHECK_FUNCTION_EXISTS(lgetea HAVE_LGETEA) 577 | CHECK_FUNCTION_EXISTS(listea HAVE_LISTEA) 578 | CHECK_FUNCTION_EXISTS(llistea HAVE_LLISTEA) 579 | CHECK_FUNCTION_EXISTS(lsetea HAVE_LSETEA) 580 | IF(HAVE_FGETEA AND 581 | HAVE_FLISTEA AND 582 | HAVE_FSETEA AND 583 | HAVE_GETEA AND 584 | HAVE_LGETEA AND 585 | HAVE_LISTEA AND 586 | HAVE_LLISTEA AND 587 | HAVE_LSETEA) 588 | SET(ARCHIVE_XATTR_AIX TRUE) 589 | ENDIF() 590 | ENDIF() 591 | 592 | IF(ARCHIVE_XATTR_DARWIN) 593 | MESSAGE(STATUS "Extended attributes support: Darwin") 594 | ELSEIF(ARCHIVE_XATTR_FREEBSD) 595 | MESSAGE(STATUS "Extended attributes support: FreeBSD") 596 | ELSEIF(ARCHIVE_XATTR_LINUX) 597 | MESSAGE(STATUS "Extended attributes support: Linux") 598 | ELSEIF(ARCHIVE_XATTR_AIX) 599 | MESSAGE(STATUS "Extended attributes support: AIX") 600 | ELSE() 601 | MESSAGE(STATUS "Extended attributes support: none") 602 | ENDIF() 603 | ELSE(ENABLE_XATTR) 604 | SET(ARCHIVE_XATTR_DARWIN FALSE) 605 | SET(ARCHIVE_XATTR_FREEBSD FALSE) 606 | SET(ARCHIVE_XATTR_LINUX FALSE) 607 | SET(ARCHIVE_XATTR_AIX FALSE) 608 | ENDIF(ENABLE_XATTR) 609 | 610 | # Check visibility annotations 611 | SET(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") 612 | SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fvisibility=hidden -Werror") 613 | CHECK_C_SOURCE_COMPILES("void __attribute__((visibility(\"default\"))) foo(void); 614 | int main() { return 0; }" HAVE_VISIBILITY_ATTR) 615 | IF (HAVE_VISIBILITY_ATTR) 616 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") 617 | ADD_DEFINITIONS(-D__LIBARCHIVE_ENABLE_VISIBILITY) 618 | ENDIF(HAVE_VISIBILITY_ATTR) 619 | SET(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}") 620 | --------------------------------------------------------------------------------