mirror of
https://github.com/ARMSX2/ARMSX2.git
synced 2026-08-24 16:50:16 -07:00
3rdparty: Un-submodule libzip
This commit is contained in:
@@ -27,9 +27,6 @@
|
||||
[submodule "3rdparty/sdl2/SDL"]
|
||||
path = 3rdparty/sdl2/SDL
|
||||
url = https://github.com/libsdl-org/SDL.git
|
||||
[submodule "3rdparty/libzip/libzip"]
|
||||
path = 3rdparty/libzip/libzip
|
||||
url = https://github.com/nih-at/libzip.git
|
||||
[submodule "3rdparty/zstd/zstd"]
|
||||
path = 3rdparty/zstd/zstd
|
||||
url = https://github.com/facebook/zstd.git
|
||||
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
Dieter Baron <dillo@nih.at>
|
||||
Thomas Klausner <tk@giga.or.at>
|
||||
Vendored
+382
-27
@@ -1,31 +1,386 @@
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "")
|
||||
set(LIBZIP_DO_INSTALL OFF CACHE BOOL "")
|
||||
cmake_minimum_required(VERSION 3.5.0)
|
||||
|
||||
set(ENABLE_COMMONCRYPTO OFF CACHE BOOL "")
|
||||
set(ENABLE_GNUTLS OFF CACHE BOOL "")
|
||||
set(ENABLE_MBEDTLS OFF CACHE BOOL "")
|
||||
set(ENABLE_WINDOWS_CRYPTO OFF CACHE BOOL "")
|
||||
set(ENABLE_OPENSSL OFF CACHE BOOL "")
|
||||
set(ENABLE_BZIP2 OFF CACHE BOOL "")
|
||||
set(ENABLE_LZMA OFF CACHE BOOL "")
|
||||
set(ENABLE_ZSTD ON CACHE BOOL "")
|
||||
|
||||
set(BUILD_TOOLS OFF CACHE BOOL "")
|
||||
set(BUILD_REGRESS OFF CACHE BOOL "")
|
||||
set(BUILD_EXAMPLES OFF CACHE BOOL "")
|
||||
set(BUILD_DOC OFF CACHE BOOL "")
|
||||
|
||||
if(WIN32)
|
||||
# Needed otherwise find_package() will look in the system.
|
||||
set(ZLIB_FOUND TRUE)
|
||||
set(ZLIB_LIBRARY "$<TARGET_FILE:pcsx2-zlib>")
|
||||
set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/zlib")
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
if (${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-compat)
|
||||
endif()
|
||||
|
||||
# Fill in the location of zstd, so find_package() doesn't try to use
|
||||
# a potentially-old system version. It also picks up Zstd::Zstd.
|
||||
set(Zstd_FOUND TRUE)
|
||||
set(Zstd_LIBRARY "$<TARGET_FILE:pcsx2-zstd>")
|
||||
set(Zstd_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../zstd/zstd/lib")
|
||||
project(libzip
|
||||
VERSION 1.10.1
|
||||
LANGUAGES C)
|
||||
|
||||
add_subdirectory(libzip EXCLUDE_FROM_ALL)
|
||||
set(ENABLE_FDOPEN ON)
|
||||
set(HAVE_LIBZSTD TRUE)
|
||||
set(ZIP_STATIC TRUE)
|
||||
|
||||
include(CheckFunctionExists)
|
||||
include(CheckIncludeFiles)
|
||||
include(CheckLibraryExists)
|
||||
include(CheckSymbolExists)
|
||||
include(CheckTypeSize)
|
||||
include(CheckCSourceRuns)
|
||||
include(CheckCSourceCompiles)
|
||||
include(CheckStructHasMember)
|
||||
include(TestBigEndian)
|
||||
|
||||
# Checks
|
||||
|
||||
# Request ISO C secure library functions (memcpy_s &c)
|
||||
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D__STDC_WANT_LIB_EXT1__=1)
|
||||
|
||||
check_function_exists(_close HAVE__CLOSE)
|
||||
check_function_exists(_dup HAVE__DUP)
|
||||
check_function_exists(_fdopen HAVE__FDOPEN)
|
||||
check_function_exists(_fileno HAVE__FILENO)
|
||||
check_function_exists(_setmode HAVE__SETMODE)
|
||||
check_symbol_exists(_snprintf stdio.h HAVE__SNPRINTF)
|
||||
check_symbol_exists(_snprintf_s stdio.h HAVE__SNPRINTF_S)
|
||||
check_symbol_exists(_snwprintf_s stdio.h HAVE__SNWPRINTF_S)
|
||||
check_function_exists(_strdup HAVE__STRDUP)
|
||||
check_symbol_exists(_stricmp string.h HAVE__STRICMP)
|
||||
check_function_exists(_strtoi64 HAVE__STRTOI64)
|
||||
check_function_exists(_strtoui64 HAVE__STRTOUI64)
|
||||
check_function_exists(_unlink HAVE__UNLINK)
|
||||
check_function_exists(arc4random HAVE_ARC4RANDOM)
|
||||
check_function_exists(clonefile HAVE_CLONEFILE)
|
||||
check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO)
|
||||
check_function_exists(explicit_memset HAVE_EXPLICIT_MEMSET)
|
||||
check_function_exists(fchmod HAVE_FCHMOD)
|
||||
check_function_exists(fileno HAVE_FILENO)
|
||||
check_function_exists(fseeko HAVE_FSEEKO)
|
||||
check_function_exists(ftello HAVE_FTELLO)
|
||||
check_function_exists(getprogname HAVE_GETPROGNAME)
|
||||
check_symbol_exists(localtime_r time.h HAVE_LOCALTIME_R)
|
||||
check_symbol_exists(localtime_s time.h HAVE_LOCALTIME_S)
|
||||
check_function_exists(memcpy_s HAVE_MEMCPY_S)
|
||||
check_function_exists(random HAVE_RANDOM)
|
||||
check_function_exists(setmode HAVE_SETMODE)
|
||||
check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF)
|
||||
check_symbol_exists(snprintf_s stdio.h HAVE_SNPRINTF_S)
|
||||
check_symbol_exists(strcasecmp strings.h HAVE_STRCASECMP)
|
||||
check_function_exists(strdup HAVE_STRDUP)
|
||||
check_function_exists(strerror_s HAVE_STRERROR_S)
|
||||
check_function_exists(strerrorlen_s HAVE_STRERRORLEN_S)
|
||||
check_function_exists(stricmp HAVE_STRICMP)
|
||||
check_function_exists(strncpy_s HAVE_STRNCPY_S)
|
||||
check_function_exists(strtoll HAVE_STRTOLL)
|
||||
check_function_exists(strtoull HAVE_STRTOULL)
|
||||
|
||||
check_include_files("sys/types.h;sys/stat.h;fts.h" HAVE_FTS_H)
|
||||
# fts functions may be in external library
|
||||
if(HAVE_FTS_H)
|
||||
check_function_exists(fts_open HAVE_FTS_OPEN)
|
||||
if(NOT HAVE_FTS_OPEN)
|
||||
check_library_exists(fts fts_open "" HAVE_LIB_FTS)
|
||||
else(NOT HAVE_FTS_OPEN)
|
||||
set(HAVE_LIB_FTS "" CACHE INTERNAL "")
|
||||
endif(NOT HAVE_FTS_OPEN)
|
||||
else(HAVE_FTS_H)
|
||||
set(HAVE_LIB_FTS "" CACHE INTERNAL "")
|
||||
endif(HAVE_FTS_H)
|
||||
|
||||
if(HAVE_LIB_FTS)
|
||||
set(FTS_LIB fts CACHE INTERNAL "")
|
||||
else()
|
||||
set(FTS_LIB "" CACHE INTERNAL "")
|
||||
endif()
|
||||
|
||||
check_include_files(stdbool.h HAVE_STDBOOL_H)
|
||||
check_include_files(strings.h HAVE_STRINGS_H)
|
||||
check_include_files(unistd.h HAVE_UNISTD_H)
|
||||
|
||||
check_include_files(inttypes.h HAVE_INTTYPES_H_LIBZIP)
|
||||
check_include_files(stdint.h HAVE_STDINT_H_LIBZIP)
|
||||
check_include_files(sys/types.h HAVE_SYS_TYPES_H_LIBZIP)
|
||||
|
||||
# TODO: fix test
|
||||
# this test does not find __progname even when it exists
|
||||
#check_symbol_exists(__progname stdlib.h HAVE___PROGNAME)
|
||||
|
||||
check_type_size(__int8 __INT8_LIBZIP)
|
||||
check_type_size(int8_t INT8_T_LIBZIP)
|
||||
check_type_size(uint8_t UINT8_T_LIBZIP)
|
||||
check_type_size(__int16 __INT16_LIBZIP)
|
||||
check_type_size(int16_t INT16_T_LIBZIP)
|
||||
check_type_size(uint16_t UINT16_T_LIBZIP)
|
||||
check_type_size(__int32 __INT32_LIBZIP)
|
||||
check_type_size(int32_t INT32_T_LIBZIP)
|
||||
check_type_size(uint32_t UINT32_T_LIBZIP)
|
||||
check_type_size(__int64 __INT64_LIBZIP)
|
||||
check_type_size(int64_t INT64_T_LIBZIP)
|
||||
check_type_size(uint64_t UINT64_T_LIBZIP)
|
||||
check_type_size("short" SHORT_LIBZIP)
|
||||
check_type_size("int" INT_LIBZIP)
|
||||
check_type_size("long" LONG_LIBZIP)
|
||||
check_type_size("long long" LONG_LONG_LIBZIP)
|
||||
check_type_size("off_t" SIZEOF_OFF_T)
|
||||
check_type_size("size_t" SIZEOF_SIZE_T)
|
||||
|
||||
check_c_source_compiles("#include <sys/ioctl.h>
|
||||
#include <linux/fs.h>
|
||||
int main(int argc, char *argv[]) { unsigned long x = FICLONERANGE; }" HAVE_FICLONERANGE)
|
||||
|
||||
check_c_source_compiles("
|
||||
int foo(char * _Nullable bar);
|
||||
int main(int argc, char *argv[]) { }" HAVE_NULLABLE)
|
||||
|
||||
test_big_endian(WORDS_BIGENDIAN)
|
||||
|
||||
if(MSVC)
|
||||
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
||||
add_compile_definitions(_CRT_NONSTDC_NO_DEPRECATE)
|
||||
endif(MSVC)
|
||||
|
||||
# fixed size integral types
|
||||
|
||||
if(HAVE_INTTYPES_H_LIBZIP)
|
||||
set(LIBZIP_TYPES_INCLUDE "#if !defined(__STDC_FORMAT_MACROS)
|
||||
#define __STDC_FORMAT_MACROS 1
|
||||
#endif
|
||||
#include <inttypes.h>")
|
||||
elseif(HAVE_STDINT_H_LIBZIP)
|
||||
set(LIBZIP_TYPES_INCLUDE "#include <stdint.h>")
|
||||
elseif(HAVE_SYS_TYPES_H_LIBZIP)
|
||||
set(LIBZIP_TYPES_INCLUDE "#include <sys/types.h>")
|
||||
endif()
|
||||
|
||||
if(HAVE_INT8_T_LIBZIP)
|
||||
set(ZIP_INT8_T int8_t)
|
||||
elseif(HAVE___INT8_LIBZIP)
|
||||
set(ZIP_INT8_T __int8)
|
||||
else()
|
||||
set(ZIP_INT8_T "signed char")
|
||||
endif()
|
||||
|
||||
if(HAVE_UINT8_T_LIBZIP)
|
||||
set(ZIP_UINT8_T uint8_t)
|
||||
elseif(HAVE___INT8_LIBZIP)
|
||||
set(ZIP_UINT8_T "unsigned __int8")
|
||||
else()
|
||||
set(ZIP_UINT8_T "unsigned char")
|
||||
endif()
|
||||
|
||||
if(HAVE_INT16_T_LIBZIP)
|
||||
set(ZIP_INT16_T int16_t)
|
||||
elseif(HAVE___INT16_LIBZIP)
|
||||
set(INT16_T_LIBZIP __int16)
|
||||
elseif(SHORT_LIBZIP EQUAL 2)
|
||||
set(INT16_T_LIBZIP short)
|
||||
endif()
|
||||
|
||||
if(HAVE_UINT16_T_LIBZIP)
|
||||
set(ZIP_UINT16_T uint16_t)
|
||||
elseif(HAVE___INT16_LIBZIP)
|
||||
set(UINT16_T_LIBZIP "unsigned __int16")
|
||||
elseif(SHORT_LIBZIP EQUAL 2)
|
||||
set(UINT16_T_LIBZIP "unsigned short")
|
||||
endif()
|
||||
|
||||
if(HAVE_INT32_T_LIBZIP)
|
||||
set(ZIP_INT32_T int32_t)
|
||||
elseif(HAVE___INT32_LIBZIP)
|
||||
set(ZIP_INT32_T __int32)
|
||||
elseif(INT_LIBZIP EQUAL 4)
|
||||
set(ZIP_INT32_T int)
|
||||
elseif(LONG_LIBZIP EQUAL 4)
|
||||
set(ZIP_INT32_T long)
|
||||
endif()
|
||||
|
||||
if(HAVE_UINT32_T_LIBZIP)
|
||||
set(ZIP_UINT32_T uint32_t)
|
||||
elseif(HAVE___INT32_LIBZIP)
|
||||
set(ZIP_UINT32_T "unsigned __int32")
|
||||
elseif(INT_LIBZIP EQUAL 4)
|
||||
set(ZIP_UINT32_T "unsigned int")
|
||||
elseif(LONG_LIBZIP EQUAL 4)
|
||||
set(ZIP_UINT32_T "unsigned long")
|
||||
endif()
|
||||
|
||||
if(HAVE_INT64_T_LIBZIP)
|
||||
set(ZIP_INT64_T int64_t)
|
||||
elseif(HAVE___INT64_LIBZIP)
|
||||
set(ZIP_INT64_T __int64)
|
||||
elseif(LONG_LIBZIP EQUAL 8)
|
||||
set(ZIP_INT64_T long)
|
||||
elseif(LONG_LONG_LIBZIP EQUAL 8)
|
||||
set(ZIP_INT64_T "long long")
|
||||
endif()
|
||||
|
||||
if(HAVE_UINT64_T_LIBZIP)
|
||||
set(ZIP_UINT64_T uint64_t)
|
||||
elseif(HAVE___INT64_LIBZIP)
|
||||
set(ZIP_UINT64_T "unsigned __int64")
|
||||
elseif(LONG_LIBZIP EQUAL 8)
|
||||
set(ZIP_UINT64_T "unsigned long")
|
||||
elseif(LONG_LONG_LIBZIP EQUAL 8)
|
||||
set(ZIP_UINT64_T "unsigned long long")
|
||||
endif()
|
||||
|
||||
if(HAVE_NULLABLE)
|
||||
set(ZIP_NULLABLE_DEFINES)
|
||||
else()
|
||||
set(ZIP_NULLABLE_DEFINES "#define _Nullable
|
||||
#define _Nonnull")
|
||||
endif()
|
||||
|
||||
# write out config file
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake-config.h.in ${PROJECT_BINARY_DIR}/config.h)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake-zipconf.h.in ${PROJECT_BINARY_DIR}/zipconf.h)
|
||||
|
||||
set(CMAKE_C_VISIBILITY_PRESET hidden)
|
||||
|
||||
add_library(zip STATIC
|
||||
lib/zip_add.c
|
||||
lib/zip_add_dir.c
|
||||
lib/zip_add_entry.c
|
||||
lib/zip_algorithm_deflate.c
|
||||
lib/zip_buffer.c
|
||||
lib/zip_close.c
|
||||
lib/zip_delete.c
|
||||
lib/zip_dir_add.c
|
||||
lib/zip_dirent.c
|
||||
lib/zip_discard.c
|
||||
lib/zip_entry.c
|
||||
lib/zip_error.c
|
||||
lib/zip_error_clear.c
|
||||
lib/zip_error_get.c
|
||||
lib/zip_error_get_sys_type.c
|
||||
lib/zip_error_strerror.c
|
||||
lib/zip_error_to_str.c
|
||||
lib/zip_extra_field.c
|
||||
lib/zip_extra_field_api.c
|
||||
lib/zip_fclose.c
|
||||
lib/zip_fdopen.c
|
||||
lib/zip_file_add.c
|
||||
lib/zip_file_error_clear.c
|
||||
lib/zip_file_error_get.c
|
||||
lib/zip_file_get_comment.c
|
||||
lib/zip_file_get_external_attributes.c
|
||||
lib/zip_file_get_offset.c
|
||||
lib/zip_file_rename.c
|
||||
lib/zip_file_replace.c
|
||||
lib/zip_file_set_comment.c
|
||||
lib/zip_file_set_encryption.c
|
||||
lib/zip_file_set_external_attributes.c
|
||||
lib/zip_file_set_mtime.c
|
||||
lib/zip_file_strerror.c
|
||||
lib/zip_fopen.c
|
||||
lib/zip_fopen_encrypted.c
|
||||
lib/zip_fopen_index.c
|
||||
lib/zip_fopen_index_encrypted.c
|
||||
lib/zip_fread.c
|
||||
lib/zip_fseek.c
|
||||
lib/zip_ftell.c
|
||||
lib/zip_get_archive_comment.c
|
||||
lib/zip_get_archive_flag.c
|
||||
lib/zip_get_encryption_implementation.c
|
||||
lib/zip_get_file_comment.c
|
||||
lib/zip_get_name.c
|
||||
lib/zip_get_num_entries.c
|
||||
lib/zip_get_num_files.c
|
||||
lib/zip_hash.c
|
||||
lib/zip_io_util.c
|
||||
lib/zip_libzip_version.c
|
||||
lib/zip_memdup.c
|
||||
lib/zip_name_locate.c
|
||||
lib/zip_new.c
|
||||
lib/zip_open.c
|
||||
lib/zip_pkware.c
|
||||
lib/zip_progress.c
|
||||
lib/zip_rename.c
|
||||
lib/zip_replace.c
|
||||
lib/zip_set_archive_comment.c
|
||||
lib/zip_set_archive_flag.c
|
||||
lib/zip_set_default_password.c
|
||||
lib/zip_set_file_comment.c
|
||||
lib/zip_set_file_compression.c
|
||||
lib/zip_set_name.c
|
||||
lib/zip_source_accept_empty.c
|
||||
lib/zip_source_begin_write.c
|
||||
lib/zip_source_begin_write_cloning.c
|
||||
lib/zip_source_buffer.c
|
||||
lib/zip_source_call.c
|
||||
lib/zip_source_close.c
|
||||
lib/zip_source_commit_write.c
|
||||
lib/zip_source_compress.c
|
||||
lib/zip_source_crc.c
|
||||
lib/zip_source_error.c
|
||||
lib/zip_source_file_common.c
|
||||
lib/zip_source_file_stdio.c
|
||||
lib/zip_source_free.c
|
||||
lib/zip_source_function.c
|
||||
lib/zip_source_get_file_attributes.c
|
||||
lib/zip_source_is_deleted.c
|
||||
lib/zip_source_layered.c
|
||||
lib/zip_source_open.c
|
||||
lib/zip_source_pass_to_lower_layer.c
|
||||
lib/zip_source_pkware_decode.c
|
||||
lib/zip_source_pkware_encode.c
|
||||
lib/zip_source_read.c
|
||||
lib/zip_source_remove.c
|
||||
lib/zip_source_rollback_write.c
|
||||
lib/zip_source_seek.c
|
||||
lib/zip_source_seek_write.c
|
||||
lib/zip_source_stat.c
|
||||
lib/zip_source_supports.c
|
||||
lib/zip_source_tell.c
|
||||
lib/zip_source_tell_write.c
|
||||
lib/zip_source_window.c
|
||||
lib/zip_source_write.c
|
||||
lib/zip_source_zip.c
|
||||
lib/zip_source_zip_new.c
|
||||
lib/zip_stat.c
|
||||
lib/zip_stat_index.c
|
||||
lib/zip_stat_init.c
|
||||
lib/zip_strerror.c
|
||||
lib/zip_string.c
|
||||
lib/zip_unchange.c
|
||||
lib/zip_unchange_all.c
|
||||
lib/zip_unchange_archive.c
|
||||
lib/zip_unchange_data.c
|
||||
lib/zip_utf-8.c
|
||||
${CMAKE_CURRENT_BINARY_DIR}/zip_err_str.c
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_sources(zip PRIVATE
|
||||
lib/zip_source_file_win32.c
|
||||
lib/zip_source_file_win32_named.c
|
||||
lib/zip_source_file_win32_utf16.c
|
||||
lib/zip_source_file_win32_utf8.c
|
||||
lib/zip_source_file_win32_ansi.c
|
||||
lib/zip_random_win32.c
|
||||
)
|
||||
else(WIN32)
|
||||
target_sources(zip PRIVATE
|
||||
lib/zip_source_file_stdio_named.c
|
||||
lib/zip_random_unix.c
|
||||
)
|
||||
endif(WIN32)
|
||||
|
||||
target_sources(zip PRIVATE lib/zip_algorithm_zstd.c)
|
||||
target_link_libraries(zip PRIVATE Zstd::Zstd)
|
||||
|
||||
target_link_libraries(zip PRIVATE ZLIB::ZLIB)
|
||||
target_include_directories(zip
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/lib>
|
||||
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
|
||||
# create zip_err_str.c from zip.h and zipint.h
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zip_err_str.c
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
"-DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}"
|
||||
"-DCMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}"
|
||||
"-P" "${PROJECT_SOURCE_DIR}/cmake/GenerateZipErrorStrings.cmake"
|
||||
DEPENDS
|
||||
${PROJECT_SOURCE_DIR}/cmake/GenerateZipErrorStrings.cmake
|
||||
${PROJECT_SOURCE_DIR}/lib/zip.h
|
||||
${PROJECT_SOURCE_DIR}/lib/zipint.h
|
||||
COMMENT "Generating zip_err_str.c"
|
||||
)
|
||||
|
||||
add_library(libzip::zip ALIAS zip)
|
||||
|
||||
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
Copyright (C) 1999-2020 Dieter Baron and Thomas Klausner
|
||||
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
3. The names of the authors may not be used to endorse or promote
|
||||
products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
Vendored
+72
@@ -0,0 +1,72 @@
|
||||
#ifndef HAD_CONFIG_H
|
||||
#define HAD_CONFIG_H
|
||||
#ifndef _HAD_ZIPCONF_H
|
||||
#include "zipconf.h"
|
||||
#endif
|
||||
/* BEGIN DEFINES */
|
||||
#cmakedefine ENABLE_FDOPEN
|
||||
#cmakedefine HAVE___PROGNAME
|
||||
#cmakedefine HAVE__CLOSE
|
||||
#cmakedefine HAVE__DUP
|
||||
#cmakedefine HAVE__FDOPEN
|
||||
#cmakedefine HAVE__FILENO
|
||||
#cmakedefine HAVE__SETMODE
|
||||
#cmakedefine HAVE__SNPRINTF
|
||||
#cmakedefine HAVE__SNPRINTF_S
|
||||
#cmakedefine HAVE__SNWPRINTF_S
|
||||
#cmakedefine HAVE__STRDUP
|
||||
#cmakedefine HAVE__STRICMP
|
||||
#cmakedefine HAVE__STRTOI64
|
||||
#cmakedefine HAVE__STRTOUI64
|
||||
#cmakedefine HAVE__UNLINK
|
||||
#cmakedefine HAVE_ARC4RANDOM
|
||||
#cmakedefine HAVE_CLONEFILE
|
||||
#cmakedefine HAVE_COMMONCRYPTO
|
||||
#cmakedefine HAVE_CRYPTO
|
||||
#cmakedefine HAVE_FICLONERANGE
|
||||
#cmakedefine HAVE_FILENO
|
||||
#cmakedefine HAVE_FCHMOD
|
||||
#cmakedefine HAVE_FSEEKO
|
||||
#cmakedefine HAVE_FTELLO
|
||||
#cmakedefine HAVE_GETPROGNAME
|
||||
#cmakedefine HAVE_GNUTLS
|
||||
#cmakedefine HAVE_LIBBZ2
|
||||
#cmakedefine HAVE_LIBLZMA
|
||||
#cmakedefine HAVE_LIBZSTD
|
||||
#cmakedefine HAVE_LOCALTIME_R
|
||||
#cmakedefine HAVE_LOCALTIME_S
|
||||
#cmakedefine HAVE_MEMCPY_S
|
||||
#cmakedefine HAVE_MBEDTLS
|
||||
#cmakedefine HAVE_MKSTEMP
|
||||
#cmakedefine HAVE_NULLABLE
|
||||
#cmakedefine HAVE_OPENSSL
|
||||
#cmakedefine HAVE_SETMODE
|
||||
#cmakedefine HAVE_SNPRINTF
|
||||
#cmakedefine HAVE_SNPRINTF_S
|
||||
#cmakedefine HAVE_STRCASECMP
|
||||
#cmakedefine HAVE_STRDUP
|
||||
#cmakedefine HAVE_STRERROR_S
|
||||
#cmakedefine HAVE_STRERRORLEN_S
|
||||
#cmakedefine HAVE_STRICMP
|
||||
#cmakedefine HAVE_STRNCPY_S
|
||||
#cmakedefine HAVE_STRTOLL
|
||||
#cmakedefine HAVE_STRTOULL
|
||||
#cmakedefine HAVE_STRUCT_TM_TM_ZONE
|
||||
#cmakedefine HAVE_STDBOOL_H
|
||||
#cmakedefine HAVE_STRINGS_H
|
||||
#cmakedefine HAVE_UNISTD_H
|
||||
#cmakedefine HAVE_WINDOWS_CRYPTO
|
||||
#cmakedefine SIZEOF_OFF_T ${SIZEOF_OFF_T}
|
||||
#cmakedefine SIZEOF_SIZE_T ${SIZEOF_SIZE_T}
|
||||
#cmakedefine HAVE_DIRENT_H
|
||||
#cmakedefine HAVE_FTS_H
|
||||
#cmakedefine HAVE_NDIR_H
|
||||
#cmakedefine HAVE_SYS_DIR_H
|
||||
#cmakedefine HAVE_SYS_NDIR_H
|
||||
#cmakedefine WORDS_BIGENDIAN
|
||||
#cmakedefine HAVE_SHARED
|
||||
/* END DEFINES */
|
||||
#define PACKAGE "@CMAKE_PROJECT_NAME@"
|
||||
#define VERSION "@CMAKE_PROJECT_VERSION@"
|
||||
|
||||
#endif /* HAD_CONFIG_H */
|
||||
Vendored
+47
@@ -0,0 +1,47 @@
|
||||
#ifndef _HAD_ZIPCONF_H
|
||||
#define _HAD_ZIPCONF_H
|
||||
|
||||
/*
|
||||
zipconf.h -- platform specific include file
|
||||
|
||||
This file was generated automatically by CMake
|
||||
based on ../cmake-zipconf.h.in.
|
||||
*/
|
||||
|
||||
#define LIBZIP_VERSION "${libzip_VERSION}"
|
||||
#define LIBZIP_VERSION_MAJOR ${libzip_VERSION_MAJOR}
|
||||
#define LIBZIP_VERSION_MINOR ${libzip_VERSION_MINOR}
|
||||
#define LIBZIP_VERSION_MICRO ${libzip_VERSION_PATCH}
|
||||
|
||||
#cmakedefine ZIP_STATIC
|
||||
|
||||
${ZIP_NULLABLE_DEFINES}
|
||||
|
||||
${LIBZIP_TYPES_INCLUDE}
|
||||
|
||||
typedef ${ZIP_INT8_T} zip_int8_t;
|
||||
typedef ${ZIP_UINT8_T} zip_uint8_t;
|
||||
typedef ${ZIP_INT16_T} zip_int16_t;
|
||||
typedef ${ZIP_UINT16_T} zip_uint16_t;
|
||||
typedef ${ZIP_INT32_T} zip_int32_t;
|
||||
typedef ${ZIP_UINT32_T} zip_uint32_t;
|
||||
typedef ${ZIP_INT64_T} zip_int64_t;
|
||||
typedef ${ZIP_UINT64_T} zip_uint64_t;
|
||||
|
||||
#define ZIP_INT8_MIN (-ZIP_INT8_MAX-1)
|
||||
#define ZIP_INT8_MAX 0x7f
|
||||
#define ZIP_UINT8_MAX 0xff
|
||||
|
||||
#define ZIP_INT16_MIN (-ZIP_INT16_MAX-1)
|
||||
#define ZIP_INT16_MAX 0x7fff
|
||||
#define ZIP_UINT16_MAX 0xffff
|
||||
|
||||
#define ZIP_INT32_MIN (-ZIP_INT32_MAX-1L)
|
||||
#define ZIP_INT32_MAX 0x7fffffffL
|
||||
#define ZIP_UINT32_MAX 0xffffffffLU
|
||||
|
||||
#define ZIP_INT64_MIN (-ZIP_INT64_MAX-1LL)
|
||||
#define ZIP_INT64_MAX 0x7fffffffffffffffLL
|
||||
#define ZIP_UINT64_MAX 0xffffffffffffffffULL
|
||||
|
||||
#endif /* zipconf.h */
|
||||
Vendored
+186
@@ -0,0 +1,186 @@
|
||||
# Copyright (C) 2020 Dieter Baron and Thomas Klausner
|
||||
#
|
||||
# The authors can be contacted at <info@libzip.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# 3. The names of the authors may not be used to endorse or promote
|
||||
# products derived from this software without specific prior
|
||||
# written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
||||
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#[=======================================================================[.rst:
|
||||
Findzstd
|
||||
-------
|
||||
|
||||
Finds the Zstandard (zstd) library.
|
||||
|
||||
Imported Targets
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This module provides the following imported targets, if found:
|
||||
|
||||
``zstd::libzstd_shared``
|
||||
The shared Zstandard library
|
||||
``zstd::libzstd_static``
|
||||
The shared Zstandard library
|
||||
|
||||
Result Variables
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This will define the following variables:
|
||||
|
||||
``zstd_FOUND``
|
||||
True if the system has the Zstandard library.
|
||||
``zstd_VERSION``
|
||||
The version of the Zstandard library which was found.
|
||||
|
||||
Cache Variables
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
The following cache variables may also be set:
|
||||
|
||||
``zstd_INCLUDE_DIR``
|
||||
The directory containing ``zstd.h``.
|
||||
``zstd_STATIC_LIBRARY``
|
||||
The path to the Zstandard static library.
|
||||
``zstd_SHARED_LIBRARY``
|
||||
The path to the Zstandard shared library.
|
||||
``zstd_DLL``
|
||||
The path to the Zstandard DLL.
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(PC_zstd QUIET libzstd)
|
||||
|
||||
find_path(zstd_INCLUDE_DIR
|
||||
NAMES zstd.h
|
||||
HINTS ${PC_zstd_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
find_file(zstd_DLL
|
||||
NAMES libzstd.dll zstd.dll
|
||||
PATH_SUFFIXES bin
|
||||
HINTS ${PC_zstd_PREFIX}
|
||||
)
|
||||
|
||||
# On Windows, we manually define the library names to avoid mistaking the
|
||||
# implib for the static library
|
||||
if(zstd_DLL)
|
||||
set(_zstd_win_static_name zstd-static)
|
||||
set(_zstd_win_shared_name zstd)
|
||||
else()
|
||||
# vcpkg removes the -static suffix in static builds
|
||||
set(_zstd_win_static_name zstd zstd_static)
|
||||
set(_zstd_win_shared_name)
|
||||
endif()
|
||||
|
||||
set(_previous_suffixes ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".dylib" ".dll.a" ".lib")
|
||||
find_library(zstd_SHARED_LIBRARY
|
||||
NAMES zstd ${_zstd_win_shared_name}
|
||||
HINTS ${PC_zstd_LIBDIR}
|
||||
)
|
||||
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".lib")
|
||||
find_library(zstd_STATIC_LIBRARY
|
||||
NAMES zstd ${_zstd_win_static_name}
|
||||
HINTS ${PC_zstd_LIBDIR}
|
||||
)
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_previous_suffixes})
|
||||
|
||||
# Set zstd_LIBRARY to the shared library or fall back to the static library
|
||||
if(zstd_SHARED_LIBRARY)
|
||||
set(_zstd_LIBRARY ${zstd_SHARED_LIBRARY})
|
||||
else()
|
||||
set(_zstd_LIBRARY ${zstd_STATIC_LIBRARY})
|
||||
endif()
|
||||
|
||||
# Extract version information from the header file
|
||||
if(zstd_INCLUDE_DIR)
|
||||
file(STRINGS ${zstd_INCLUDE_DIR}/zstd.h _ver_major_line
|
||||
REGEX "^#define ZSTD_VERSION_MAJOR *[0-9]+"
|
||||
LIMIT_COUNT 1)
|
||||
string(REGEX MATCH "[0-9]+"
|
||||
zstd_MAJOR_VERSION "${_ver_major_line}")
|
||||
file(STRINGS ${zstd_INCLUDE_DIR}/zstd.h _ver_minor_line
|
||||
REGEX "^#define ZSTD_VERSION_MINOR *[0-9]+"
|
||||
LIMIT_COUNT 1)
|
||||
string(REGEX MATCH "[0-9]+"
|
||||
zstd_MINOR_VERSION "${_ver_minor_line}")
|
||||
file(STRINGS ${zstd_INCLUDE_DIR}/zstd.h _ver_release_line
|
||||
REGEX "^#define ZSTD_VERSION_RELEASE *[0-9]+"
|
||||
LIMIT_COUNT 1)
|
||||
string(REGEX MATCH "[0-9]+"
|
||||
zstd_RELEASE_VERSION "${_ver_release_line}")
|
||||
set(Zstd_VERSION "${zstd_MAJOR_VERSION}.${zstd_MINOR_VERSION}.${zstd_RELEASE_VERSION}")
|
||||
unset(_ver_major_line)
|
||||
unset(_ver_minor_line)
|
||||
unset(_ver_release_line)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(zstd
|
||||
FOUND_VAR zstd_FOUND
|
||||
REQUIRED_VARS
|
||||
_zstd_LIBRARY
|
||||
zstd_INCLUDE_DIR
|
||||
VERSION_VAR zstd_VERSION
|
||||
)
|
||||
|
||||
if(zstd_FOUND AND zstd_SHARED_LIBRARY AND NOT TARGET zstd::libzstd_shared)
|
||||
add_library(zstd::libzstd_shared SHARED IMPORTED)
|
||||
if(WIN32)
|
||||
set_target_properties(zstd::libzstd_shared PROPERTIES
|
||||
IMPORTED_LOCATION "${zstd_DLL}"
|
||||
IMPORTED_IMPLIB "${zstd_SHARED_LIBRARY}"
|
||||
)
|
||||
else()
|
||||
set_target_properties(zstd::libzstd_shared PROPERTIES
|
||||
IMPORTED_LOCATION "${zstd_SHARED_LIBRARY}"
|
||||
)
|
||||
endif()
|
||||
|
||||
set_target_properties(zstd::libzstd_shared PROPERTIES
|
||||
INTERFACE_COMPILE_OPTIONS "${PC_zstd_CFLAGS_OTHER}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(zstd_FOUND AND zstd_STATIC_LIBRARY AND NOT TARGET zstd::libzstd_static)
|
||||
add_library(zstd::libzstd_static STATIC IMPORTED)
|
||||
set_target_properties(zstd::libzstd_static PROPERTIES
|
||||
IMPORTED_LOCATION "${zstd_STATIC_LIBRARY}"
|
||||
INTERFACE_COMPILE_OPTIONS "${PC_zstd_CFLAGS_OTHER}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
|
||||
)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(
|
||||
zstd_INCLUDE_DIR
|
||||
zstd_DLL
|
||||
zstd_SHARED_LIBRARY
|
||||
zstd_STATIC_LIBRARY
|
||||
)
|
||||
@@ -0,0 +1,47 @@
|
||||
# create zip_err_str.c from zip.h and zipint.h
|
||||
file(READ ${PROJECT_SOURCE_DIR}/lib/zip.h zip_h)
|
||||
string(REGEX MATCHALL "#define ZIP_ER_([A-Z0-9_]+) ([0-9]+)[ \t]+/([-*0-9a-zA-Z, ']*)/" zip_h_err ${zip_h})
|
||||
file(READ ${PROJECT_SOURCE_DIR}/lib/zipint.h zipint_h)
|
||||
string(REGEX MATCHALL "#define ZIP_ER_DETAIL_([A-Z0-9_]+) ([0-9]+)[ \t]+/([-*0-9a-zA-Z, ']*)/" zipint_h_err ${zipint_h})
|
||||
set(zip_err_str [=[
|
||||
/*
|
||||
This file was generated automatically by CMake
|
||||
from zip.h and zipint.h\; make changes there.
|
||||
*/
|
||||
|
||||
#include "zipint.h"
|
||||
|
||||
#define L ZIP_ET_LIBZIP
|
||||
#define N ZIP_ET_NONE
|
||||
#define S ZIP_ET_SYS
|
||||
#define Z ZIP_ET_ZLIB
|
||||
|
||||
#define E ZIP_DETAIL_ET_ENTRY
|
||||
#define G ZIP_DETAIL_ET_GLOBAL
|
||||
|
||||
const struct _zip_err_info _zip_err_str[] = {
|
||||
]=])
|
||||
set(zip_err_type)
|
||||
foreach(errln ${zip_h_err})
|
||||
string(REGEX MATCH "#define ZIP_ER_([A-Z0-9_]+) ([0-9]+)[ \t]+/([-*0-9a-zA-Z, ']*)/" err_t_tt ${errln})
|
||||
string(REGEX MATCH "([L|N|S|Z]+) ([-0-9a-zA-Z,, ']*)" err_t_tt "${CMAKE_MATCH_3}")
|
||||
string(STRIP "${CMAKE_MATCH_2}" err_t_tt)
|
||||
string(APPEND zip_err_str " { ${CMAKE_MATCH_1}, \"${err_t_tt}\" },\n")
|
||||
endforeach()
|
||||
string(APPEND zip_err_str [=[}\;
|
||||
|
||||
const int _zip_err_str_count = sizeof(_zip_err_str)/sizeof(_zip_err_str[0])\;
|
||||
|
||||
const struct _zip_err_info _zip_err_details[] = {
|
||||
]=])
|
||||
foreach(errln ${zipint_h_err})
|
||||
string(REGEX MATCH "#define ZIP_ER_DETAIL_([A-Z0-9_]+) ([0-9]+)[ \t]+/([-*0-9a-zA-Z, ']*)/" err_t_tt ${errln})
|
||||
string(REGEX MATCH "([E|G]+) ([-0-9a-zA-Z, ']*)" err_t_tt "${CMAKE_MATCH_3}")
|
||||
string(STRIP "${CMAKE_MATCH_2}" err_t_tt)
|
||||
string(APPEND zip_err_str " { ${CMAKE_MATCH_1}, \"${err_t_tt}\" },\n")
|
||||
endforeach()
|
||||
string(APPEND zip_err_str [=[}\;
|
||||
|
||||
const int _zip_err_details_count = sizeof(_zip_err_details)/sizeof(_zip_err_details[0])\;
|
||||
]=])
|
||||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/zip_err_str.c ${zip_err_str})
|
||||
Vendored
+208
@@ -0,0 +1,208 @@
|
||||
include(CheckFunctionExists)
|
||||
|
||||
set(CMAKE_C_VISIBILITY_PRESET hidden)
|
||||
|
||||
add_library(zip
|
||||
zip_add.c
|
||||
zip_add_dir.c
|
||||
zip_add_entry.c
|
||||
zip_algorithm_deflate.c
|
||||
zip_buffer.c
|
||||
zip_close.c
|
||||
zip_delete.c
|
||||
zip_dir_add.c
|
||||
zip_dirent.c
|
||||
zip_discard.c
|
||||
zip_entry.c
|
||||
zip_error.c
|
||||
zip_error_clear.c
|
||||
zip_error_get.c
|
||||
zip_error_get_sys_type.c
|
||||
zip_error_strerror.c
|
||||
zip_error_to_str.c
|
||||
zip_extra_field.c
|
||||
zip_extra_field_api.c
|
||||
zip_fclose.c
|
||||
zip_fdopen.c
|
||||
zip_file_add.c
|
||||
zip_file_error_clear.c
|
||||
zip_file_error_get.c
|
||||
zip_file_get_comment.c
|
||||
zip_file_get_external_attributes.c
|
||||
zip_file_get_offset.c
|
||||
zip_file_rename.c
|
||||
zip_file_replace.c
|
||||
zip_file_set_comment.c
|
||||
zip_file_set_encryption.c
|
||||
zip_file_set_external_attributes.c
|
||||
zip_file_set_mtime.c
|
||||
zip_file_strerror.c
|
||||
zip_fopen.c
|
||||
zip_fopen_encrypted.c
|
||||
zip_fopen_index.c
|
||||
zip_fopen_index_encrypted.c
|
||||
zip_fread.c
|
||||
zip_fseek.c
|
||||
zip_ftell.c
|
||||
zip_get_archive_comment.c
|
||||
zip_get_archive_flag.c
|
||||
zip_get_encryption_implementation.c
|
||||
zip_get_file_comment.c
|
||||
zip_get_name.c
|
||||
zip_get_num_entries.c
|
||||
zip_get_num_files.c
|
||||
zip_hash.c
|
||||
zip_io_util.c
|
||||
zip_libzip_version.c
|
||||
zip_memdup.c
|
||||
zip_name_locate.c
|
||||
zip_new.c
|
||||
zip_open.c
|
||||
zip_pkware.c
|
||||
zip_progress.c
|
||||
zip_rename.c
|
||||
zip_replace.c
|
||||
zip_set_archive_comment.c
|
||||
zip_set_archive_flag.c
|
||||
zip_set_default_password.c
|
||||
zip_set_file_comment.c
|
||||
zip_set_file_compression.c
|
||||
zip_set_name.c
|
||||
zip_source_accept_empty.c
|
||||
zip_source_begin_write.c
|
||||
zip_source_begin_write_cloning.c
|
||||
zip_source_buffer.c
|
||||
zip_source_call.c
|
||||
zip_source_close.c
|
||||
zip_source_commit_write.c
|
||||
zip_source_compress.c
|
||||
zip_source_crc.c
|
||||
zip_source_error.c
|
||||
zip_source_file_common.c
|
||||
zip_source_file_stdio.c
|
||||
zip_source_free.c
|
||||
zip_source_function.c
|
||||
zip_source_get_file_attributes.c
|
||||
zip_source_is_deleted.c
|
||||
zip_source_layered.c
|
||||
zip_source_open.c
|
||||
zip_source_pass_to_lower_layer.c
|
||||
zip_source_pkware_decode.c
|
||||
zip_source_pkware_encode.c
|
||||
zip_source_read.c
|
||||
zip_source_remove.c
|
||||
zip_source_rollback_write.c
|
||||
zip_source_seek.c
|
||||
zip_source_seek_write.c
|
||||
zip_source_stat.c
|
||||
zip_source_supports.c
|
||||
zip_source_tell.c
|
||||
zip_source_tell_write.c
|
||||
zip_source_window.c
|
||||
zip_source_write.c
|
||||
zip_source_zip.c
|
||||
zip_source_zip_new.c
|
||||
zip_stat.c
|
||||
zip_stat_index.c
|
||||
zip_stat_init.c
|
||||
zip_strerror.c
|
||||
zip_string.c
|
||||
zip_unchange.c
|
||||
zip_unchange_all.c
|
||||
zip_unchange_archive.c
|
||||
zip_unchange_data.c
|
||||
zip_utf-8.c
|
||||
${CMAKE_CURRENT_BINARY_DIR}/zip_err_str.c
|
||||
)
|
||||
add_library(libzip::zip ALIAS zip)
|
||||
|
||||
if(WIN32)
|
||||
target_sources(zip PRIVATE
|
||||
zip_source_file_win32.c
|
||||
zip_source_file_win32_named.c
|
||||
zip_source_file_win32_utf16.c
|
||||
zip_source_file_win32_utf8.c
|
||||
)
|
||||
if(CMAKE_SYSTEM_NAME MATCHES WindowsPhone OR CMAKE_SYSTEM_NAME MATCHES WindowsStore)
|
||||
target_sources(zip PRIVATE zip_random_uwp.c)
|
||||
else()
|
||||
target_sources(zip PRIVATE zip_source_file_win32_ansi.c zip_random_win32.c)
|
||||
target_link_libraries(zip PRIVATE advapi32)
|
||||
endif()
|
||||
else(WIN32)
|
||||
target_sources(zip PRIVATE
|
||||
zip_source_file_stdio_named.c
|
||||
zip_random_unix.c
|
||||
)
|
||||
endif(WIN32)
|
||||
|
||||
if(HAVE_LIBBZ2)
|
||||
target_sources(zip PRIVATE zip_algorithm_bzip2.c)
|
||||
target_link_libraries(zip PRIVATE BZip2::BZip2)
|
||||
endif()
|
||||
|
||||
if(HAVE_LIBLZMA)
|
||||
target_sources(zip PRIVATE zip_algorithm_xz.c)
|
||||
target_link_libraries(zip PRIVATE LibLZMA::LibLZMA)
|
||||
endif()
|
||||
|
||||
if(HAVE_LIBZSTD)
|
||||
target_sources(zip PRIVATE zip_algorithm_zstd.c)
|
||||
target_link_libraries(zip PRIVATE ${zstd_TARGET})
|
||||
endif()
|
||||
|
||||
if(HAVE_COMMONCRYPTO)
|
||||
target_sources(zip PRIVATE zip_crypto_commoncrypto.c)
|
||||
elseif(HAVE_WINDOWS_CRYPTO)
|
||||
target_sources(zip PRIVATE zip_crypto_win.c)
|
||||
target_link_libraries(zip PRIVATE bcrypt)
|
||||
elseif(HAVE_GNUTLS)
|
||||
target_sources(zip PRIVATE zip_crypto_gnutls.c)
|
||||
target_link_libraries(zip PRIVATE GnuTLS::GnuTLS Nettle::Nettle)
|
||||
elseif(HAVE_OPENSSL)
|
||||
target_sources(zip PRIVATE zip_crypto_openssl.c)
|
||||
target_link_libraries(zip PRIVATE OpenSSL::Crypto)
|
||||
elseif(HAVE_MBEDTLS)
|
||||
target_sources(zip PRIVATE zip_crypto_mbedtls.c)
|
||||
target_link_libraries(zip PRIVATE MbedTLS::MbedTLS)
|
||||
endif()
|
||||
|
||||
if(HAVE_CRYPTO)
|
||||
target_sources(zip PRIVATE zip_winzip_aes.c zip_source_winzip_aes_decode.c zip_source_winzip_aes_encode.c)
|
||||
endif()
|
||||
|
||||
if(SHARED_LIB_VERSIONNING)
|
||||
set_target_properties(zip PROPERTIES VERSION 5.5 SOVERSION 5)
|
||||
endif()
|
||||
|
||||
target_link_libraries(zip PRIVATE ZLIB::ZLIB)
|
||||
target_include_directories(zip
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/lib>
|
||||
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
|
||||
if(LIBZIP_DO_INSTALL)
|
||||
install(TARGETS zip
|
||||
EXPORT ${PROJECT_NAME}-targets
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
install(FILES zip.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
endif()
|
||||
|
||||
# create zip_err_str.c from zip.h and zipint.h
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zip_err_str.c
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
"-DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}"
|
||||
"-DCMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}"
|
||||
"-P" "${PROJECT_SOURCE_DIR}/cmake/GenerateZipErrorStrings.cmake"
|
||||
DEPENDS
|
||||
${PROJECT_SOURCE_DIR}/cmake/GenerateZipErrorStrings.cmake
|
||||
${PROJECT_SOURCE_DIR}/lib/zip.h
|
||||
${PROJECT_SOURCE_DIR}/lib/zipint.h
|
||||
COMMENT "Generating zip_err_str.c"
|
||||
)
|
||||
Vendored
+240
@@ -0,0 +1,240 @@
|
||||
#ifndef _HAD_LIBZIP_COMPAT_H
|
||||
#define _HAD_LIBZIP_COMPAT_H
|
||||
|
||||
/*
|
||||
compat.h -- compatibility defines.
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
3. The names of the authors may not be used to endorse or promote
|
||||
products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "zipconf.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
/* to have *_MAX definitions for all types when compiling with g++ */
|
||||
#define __STDC_LIMIT_MACROS
|
||||
|
||||
/* to have ISO C secure library functions */
|
||||
#define __STDC_WANT_LIB_EXT1__ 1
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef ZIP_EXTERN
|
||||
#ifndef ZIP_STATIC
|
||||
#define ZIP_EXTERN __declspec(dllexport)
|
||||
#endif
|
||||
#endif
|
||||
/* for dup(), close(), etc. */
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDBOOL_H
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
typedef char bool;
|
||||
#define true 1
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/* at least MinGW does not provide EOPNOTSUPP, see
|
||||
* http://sourceforge.net/p/mingw/bugs/263/
|
||||
*/
|
||||
#ifndef EOPNOTSUPP
|
||||
#define EOPNOTSUPP EINVAL
|
||||
#endif
|
||||
|
||||
/* at least MinGW does not provide EOVERFLOW, see
|
||||
* http://sourceforge.net/p/mingw/bugs/242/
|
||||
*/
|
||||
#ifndef EOVERFLOW
|
||||
#define EOVERFLOW EFBIG
|
||||
#endif
|
||||
|
||||
/* not supported on at least Windows */
|
||||
#ifndef O_CLOEXEC
|
||||
#define O_CLOEXEC 0
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#if defined(HAVE__CLOSE)
|
||||
#define close _close
|
||||
#endif
|
||||
#if defined(HAVE__DUP)
|
||||
#define dup _dup
|
||||
#endif
|
||||
/* crashes reported when using fdopen instead of _fdopen on Windows/Visual Studio 10/Win64 */
|
||||
#if defined(HAVE__FDOPEN)
|
||||
#define fdopen _fdopen
|
||||
#endif
|
||||
#if !defined(HAVE_FILENO) && defined(HAVE__FILENO)
|
||||
#define fileno _fileno
|
||||
#endif
|
||||
#if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
#if !defined(HAVE__SNWPRINTF_S)
|
||||
#define _snwprintf_s(buf, bufsz, len, fmt, ...) (_snwprintf((buf), (len), (fmt), __VA_ARGS__))
|
||||
#endif
|
||||
#if defined(HAVE__STRDUP)
|
||||
#if !defined(HAVE_STRDUP) || defined(_WIN32)
|
||||
#undef strdup
|
||||
#define strdup _strdup
|
||||
#endif
|
||||
#endif
|
||||
#if !defined(HAVE__SETMODE) && defined(HAVE_SETMODE)
|
||||
#define _setmode setmode
|
||||
#endif
|
||||
#if !defined(HAVE_STRTOLL) && defined(HAVE__STRTOI64)
|
||||
#define strtoll _strtoi64
|
||||
#endif
|
||||
#if !defined(HAVE_STRTOULL) && defined(HAVE__STRTOUI64)
|
||||
#define strtoull _strtoui64
|
||||
#endif
|
||||
#if defined(HAVE__UNLINK)
|
||||
#define unlink _unlink
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FSEEKO
|
||||
#define fseeko(s, o, w) (fseek((s), (long int)(o), (w)))
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FTELLO
|
||||
#define ftello(s) ((long)ftell((s)))
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LOCALTIME_S
|
||||
#ifdef _WIN32
|
||||
/* Windows is incompatible to the C11 standard, hurray! */
|
||||
#define zip_localtime(t, tm) (localtime_s((tm), (t)) == 0 ? tm : NULL)
|
||||
#else
|
||||
#define zip_localtime localtime_s
|
||||
#endif
|
||||
#else
|
||||
#ifdef HAVE_LOCALTIME_R
|
||||
#define zip_localtime localtime_r
|
||||
#else
|
||||
#define zip_localtime(t, tm) (localtime(t))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MEMCPY_S
|
||||
#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SNPRINTF_S
|
||||
#ifdef HAVE__SNPRINTF_S
|
||||
#define snprintf_s(buf, bufsz, fmt, ...) (_snprintf_s((buf), (bufsz), (bufsz), (fmt), __VA_ARGS__))
|
||||
#else
|
||||
#define snprintf_s snprintf
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_STRCASECMP)
|
||||
#if defined(HAVE__STRICMP)
|
||||
#define strcasecmp _stricmp
|
||||
#elif defined(HAVE_STRICMP)
|
||||
#define strcasecmp stricmp
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRNCPY_S
|
||||
#define strncpy_s(dest, destsz, src, count) (strncpy((dest), (src), (count)), 0)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRERROR_S
|
||||
#define strerrorlen_s(errnum) (strlen(strerror(errnum)))
|
||||
#define strerror_s(buf, bufsz, errnum) ((void)strncpy_s((buf), (bufsz), strerror(errnum), (bufsz)), (buf)[(bufsz)-1] = '\0', strerrorlen_s(errnum) >= (bufsz))
|
||||
#else
|
||||
#ifndef HAVE_STRERRORLEN_S
|
||||
#define strerrorlen_s(errnum) 8192
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if SIZEOF_OFF_T == 8
|
||||
#define ZIP_OFF_MAX ZIP_INT64_MAX
|
||||
#define ZIP_OFF_MIN ZIP_INT64_MIN
|
||||
#elif SIZEOF_OFF_T == 4
|
||||
#define ZIP_OFF_MAX ZIP_INT32_MAX
|
||||
#define ZIP_OFF_MIN ZIP_INT32_MIN
|
||||
#elif SIZEOF_OFF_T == 2
|
||||
#define ZIP_OFF_MAX ZIP_INT16_MAX
|
||||
#define ZIP_OFF_MIN ZIP_INT16_MIN
|
||||
#else
|
||||
#error unsupported size of off_t
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_FTELLO) && defined(HAVE_FSEEKO)
|
||||
#define ZIP_FSEEK_MAX ZIP_OFF_MAX
|
||||
#define ZIP_FSEEK_MIN ZIP_OFF_MIN
|
||||
#else
|
||||
#include <limits.h>
|
||||
#define ZIP_FSEEK_MAX LONG_MAX
|
||||
#define ZIP_FSEEK_MIN LONG_MIN
|
||||
#endif
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
#if SIZEOF_SIZE_T == 8
|
||||
#define SIZE_MAX ZIP_INT64_MAX
|
||||
#elif SIZEOF_SIZE_T == 4
|
||||
#define SIZE_MAX ZIP_INT32_MAX
|
||||
#elif SIZEOF_SIZE_T == 2
|
||||
#define SIZE_MAX ZIP_INT16_MAX
|
||||
#else
|
||||
#error unsupported size of size_t
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef PRId64
|
||||
#ifdef _MSC_VER
|
||||
#define PRId64 "I64d"
|
||||
#else
|
||||
#define PRId64 "lld"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef PRIu64
|
||||
#ifdef _MSC_VER
|
||||
#define PRIu64 "I64u"
|
||||
#else
|
||||
#define PRIu64 "llu"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef S_ISDIR
|
||||
#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
|
||||
#ifndef S_ISREG
|
||||
#define S_ISREG(mode) (((mode)&S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
|
||||
#endif /* compat.h */
|
||||
Vendored
+517
File diff suppressed because it is too large
Load Diff
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
zip_add.c -- add file via callback function
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
3. The names of the authors may not be used to endorse or promote
|
||||
products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#define _ZIP_COMPILING_DEPRECATED
|
||||
#include "zipint.h"
|
||||
|
||||
|
||||
/*
|
||||
NOTE: Return type is signed so we can return -1 on error.
|
||||
The index can not be larger than ZIP_INT64_MAX since the size
|
||||
of the central directory cannot be larger than
|
||||
ZIP_UINT64_MAX, and each entry is larger than 2 bytes.
|
||||
*/
|
||||
|
||||
ZIP_EXTERN zip_int64_t
|
||||
zip_add(zip_t *za, const char *name, zip_source_t *source) {
|
||||
return zip_file_add(za, name, source, 0);
|
||||
}
|
||||
Vendored
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
zip_add_dir.c -- add directory
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
3. The names of the authors may not be used to endorse or promote
|
||||
products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#define _ZIP_COMPILING_DEPRECATED
|
||||
#include "zipint.h"
|
||||
|
||||
|
||||
/* NOTE: Signed due to -1 on error. See zip_add.c for more details. */
|
||||
|
||||
ZIP_EXTERN zip_int64_t
|
||||
zip_add_dir(zip_t *za, const char *name) {
|
||||
return zip_dir_add(za, name, 0);
|
||||
}
|
||||
Vendored
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
zip_add_entry.c -- create and init struct zip_entry
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
3. The names of the authors may not be used to endorse or promote
|
||||
products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "zipint.h"
|
||||
|
||||
|
||||
/* NOTE: Signed due to -1 on error. See zip_add.c for more details. */
|
||||
|
||||
zip_int64_t
|
||||
_zip_add_entry(zip_t *za) {
|
||||
zip_uint64_t idx;
|
||||
|
||||
if (za->nentry + 1 >= za->nentry_alloc) {
|
||||
zip_entry_t *rentries;
|
||||
zip_uint64_t nalloc = za->nentry_alloc;
|
||||
zip_uint64_t additional_entries = 2 * nalloc;
|
||||
zip_uint64_t realloc_size;
|
||||
|
||||
if (additional_entries < 16) {
|
||||
additional_entries = 16;
|
||||
}
|
||||
else if (additional_entries > 1024) {
|
||||
additional_entries = 1024;
|
||||
}
|
||||
/* neither + nor * overflows can happen: nentry_alloc * sizeof(struct zip_entry) < UINT64_MAX */
|
||||
nalloc += additional_entries;
|
||||
realloc_size = sizeof(struct zip_entry) * (size_t)nalloc;
|
||||
|
||||
if (sizeof(struct zip_entry) * (size_t)za->nentry_alloc > realloc_size) {
|
||||
zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
|
||||
return -1;
|
||||
}
|
||||
rentries = (zip_entry_t *)realloc(za->entry, sizeof(struct zip_entry) * (size_t)nalloc);
|
||||
if (!rentries) {
|
||||
zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
|
||||
return -1;
|
||||
}
|
||||
za->entry = rentries;
|
||||
za->nentry_alloc = nalloc;
|
||||
}
|
||||
|
||||
idx = za->nentry++;
|
||||
|
||||
_zip_entry_init(za->entry + idx);
|
||||
|
||||
return (zip_int64_t)idx;
|
||||
}
|
||||
+293
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
zip_algorithm_bzip2.c -- bzip2 (de)compression routines
|
||||
Copyright (C) 2017-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
3. The names of the authors may not be used to endorse or promote
|
||||
products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "zipint.h"
|
||||
|
||||
#include <bzlib.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct ctx {
|
||||
zip_error_t *error;
|
||||
bool compress;
|
||||
int compression_flags;
|
||||
bool end_of_input;
|
||||
bz_stream zstr;
|
||||
};
|
||||
|
||||
|
||||
static zip_uint64_t
|
||||
maximum_compressed_size(zip_uint64_t uncompressed_size) {
|
||||
zip_uint64_t compressed_size = (zip_uint64_t)((double)uncompressed_size * 1.006);
|
||||
|
||||
if (compressed_size < uncompressed_size) {
|
||||
return ZIP_UINT64_MAX;
|
||||
}
|
||||
return compressed_size;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
allocate(bool compress, zip_uint32_t compression_flags, zip_error_t *error) {
|
||||
struct ctx *ctx;
|
||||
|
||||
if ((ctx = (struct ctx *)malloc(sizeof(*ctx))) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx->error = error;
|
||||
ctx->compress = compress;
|
||||
if (compression_flags >= 1 && compression_flags <= 9) {
|
||||
ctx->compression_flags = (int)compression_flags;
|
||||
}
|
||||
else {
|
||||
ctx->compression_flags = 9;
|
||||
}
|
||||
ctx->end_of_input = false;
|
||||
|
||||
ctx->zstr.bzalloc = NULL;
|
||||
ctx->zstr.bzfree = NULL;
|
||||
ctx->zstr.opaque = NULL;
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
compress_allocate(zip_uint16_t method, zip_uint32_t compression_flags, zip_error_t *error) {
|
||||
(void)method;
|
||||
return allocate(true, compression_flags, error);
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
decompress_allocate(zip_uint16_t method, zip_uint32_t compression_flags, zip_error_t *error) {
|
||||
(void)method;
|
||||
return allocate(false, compression_flags, error);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
deallocate(void *ud) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
|
||||
static zip_uint16_t
|
||||
general_purpose_bit_flags(void *ud) {
|
||||
(void)ud;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
map_error(int ret) {
|
||||
switch (ret) {
|
||||
case BZ_FINISH_OK:
|
||||
case BZ_FLUSH_OK:
|
||||
case BZ_OK:
|
||||
case BZ_RUN_OK:
|
||||
case BZ_STREAM_END:
|
||||
return ZIP_ER_OK;
|
||||
|
||||
case BZ_DATA_ERROR:
|
||||
case BZ_DATA_ERROR_MAGIC:
|
||||
case BZ_UNEXPECTED_EOF:
|
||||
return ZIP_ER_COMPRESSED_DATA;
|
||||
|
||||
case BZ_MEM_ERROR:
|
||||
return ZIP_ER_MEMORY;
|
||||
|
||||
case BZ_PARAM_ERROR:
|
||||
return ZIP_ER_INVAL;
|
||||
|
||||
case BZ_CONFIG_ERROR: /* actually, bzip2 miscompiled */
|
||||
case BZ_IO_ERROR:
|
||||
case BZ_OUTBUFF_FULL:
|
||||
case BZ_SEQUENCE_ERROR:
|
||||
default:
|
||||
return ZIP_ER_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
start(void *ud, zip_stat_t *st, zip_file_attributes_t *attributes) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
int ret;
|
||||
|
||||
(void)st;
|
||||
(void)attributes;
|
||||
|
||||
ctx->zstr.avail_in = 0;
|
||||
ctx->zstr.next_in = NULL;
|
||||
ctx->zstr.avail_out = 0;
|
||||
ctx->zstr.next_out = NULL;
|
||||
|
||||
if (ctx->compress) {
|
||||
ret = BZ2_bzCompressInit(&ctx->zstr, ctx->compression_flags, 0, 30);
|
||||
}
|
||||
else {
|
||||
ret = BZ2_bzDecompressInit(&ctx->zstr, 0, 0);
|
||||
}
|
||||
|
||||
if (ret != BZ_OK) {
|
||||
zip_error_set(ctx->error, map_error(ret), 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
end(void *ud) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
int err;
|
||||
|
||||
if (ctx->compress) {
|
||||
err = BZ2_bzCompressEnd(&ctx->zstr);
|
||||
}
|
||||
else {
|
||||
err = BZ2_bzDecompressEnd(&ctx->zstr);
|
||||
}
|
||||
|
||||
if (err != BZ_OK) {
|
||||
zip_error_set(ctx->error, map_error(err), 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
input(void *ud, zip_uint8_t *data, zip_uint64_t length) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
|
||||
if (length > UINT_MAX || ctx->zstr.avail_in > 0) {
|
||||
zip_error_set(ctx->error, ZIP_ER_INVAL, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
ctx->zstr.avail_in = (unsigned int)length;
|
||||
ctx->zstr.next_in = (char *)data;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
end_of_input(void *ud) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
|
||||
ctx->end_of_input = true;
|
||||
}
|
||||
|
||||
|
||||
static zip_compression_status_t
|
||||
process(void *ud, zip_uint8_t *data, zip_uint64_t *length) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
unsigned int avail_out;
|
||||
|
||||
int ret;
|
||||
|
||||
if (ctx->zstr.avail_in == 0 && !ctx->end_of_input) {
|
||||
*length = 0;
|
||||
return ZIP_COMPRESSION_NEED_DATA;
|
||||
}
|
||||
|
||||
avail_out = (unsigned int)ZIP_MIN(UINT_MAX, *length);
|
||||
ctx->zstr.avail_out = avail_out;
|
||||
ctx->zstr.next_out = (char *)data;
|
||||
|
||||
if (ctx->compress) {
|
||||
ret = BZ2_bzCompress(&ctx->zstr, ctx->end_of_input ? BZ_FINISH : BZ_RUN);
|
||||
}
|
||||
else {
|
||||
ret = BZ2_bzDecompress(&ctx->zstr);
|
||||
}
|
||||
|
||||
*length = avail_out - ctx->zstr.avail_out;
|
||||
|
||||
switch (ret) {
|
||||
case BZ_FINISH_OK: /* compression */
|
||||
return ZIP_COMPRESSION_OK;
|
||||
|
||||
case BZ_OK: /* decompression */
|
||||
case BZ_RUN_OK: /* compression */
|
||||
if (ctx->zstr.avail_in == 0) {
|
||||
return ZIP_COMPRESSION_NEED_DATA;
|
||||
}
|
||||
return ZIP_COMPRESSION_OK;
|
||||
|
||||
case BZ_STREAM_END:
|
||||
return ZIP_COMPRESSION_END;
|
||||
|
||||
default:
|
||||
zip_error_set(ctx->error, map_error(ret), 0);
|
||||
return ZIP_COMPRESSION_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
zip_compression_algorithm_t zip_algorithm_bzip2_compress = {
|
||||
maximum_compressed_size,
|
||||
compress_allocate,
|
||||
deallocate,
|
||||
general_purpose_bit_flags,
|
||||
46,
|
||||
start,
|
||||
end,
|
||||
input,
|
||||
end_of_input,
|
||||
process
|
||||
};
|
||||
|
||||
|
||||
zip_compression_algorithm_t zip_algorithm_bzip2_decompress = {
|
||||
maximum_compressed_size,
|
||||
decompress_allocate,
|
||||
deallocate,
|
||||
general_purpose_bit_flags,
|
||||
46,
|
||||
start,
|
||||
end,
|
||||
input,
|
||||
end_of_input,
|
||||
process
|
||||
};
|
||||
|
||||
/* clang-format on */
|
||||
+276
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
zip_algorithm_deflate.c -- deflate (de)compression routines
|
||||
Copyright (C) 2017-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
3. The names of the authors may not be used to endorse or promote
|
||||
products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "zipint.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <zlib.h>
|
||||
|
||||
struct ctx {
|
||||
zip_error_t *error;
|
||||
bool compress;
|
||||
int level;
|
||||
int mem_level;
|
||||
bool end_of_input;
|
||||
z_stream zstr;
|
||||
};
|
||||
|
||||
|
||||
static zip_uint64_t
|
||||
maximum_compressed_size(zip_uint64_t uncompressed_size) {
|
||||
/* max deflate size increase: size + ceil(size/16k)*5+6 */
|
||||
|
||||
zip_uint64_t compressed_size = uncompressed_size + (uncompressed_size + 16383) / 16384 * 5 + 6;
|
||||
|
||||
if (compressed_size < uncompressed_size) {
|
||||
return ZIP_UINT64_MAX;
|
||||
}
|
||||
return compressed_size;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
allocate(bool compress, zip_uint32_t compression_flags, zip_error_t *error) {
|
||||
struct ctx *ctx;
|
||||
|
||||
if ((ctx = (struct ctx *)malloc(sizeof(*ctx))) == NULL) {
|
||||
zip_error_set(error, ZIP_ET_SYS, errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx->error = error;
|
||||
ctx->compress = compress;
|
||||
if (compression_flags >= 1 && compression_flags <= 9) {
|
||||
ctx->level = (int)compression_flags;
|
||||
}
|
||||
else {
|
||||
ctx->level = Z_BEST_COMPRESSION;
|
||||
}
|
||||
ctx->mem_level = compression_flags == TORRENTZIP_COMPRESSION_FLAGS ? TORRENTZIP_MEM_LEVEL : MAX_MEM_LEVEL;
|
||||
ctx->end_of_input = false;
|
||||
|
||||
ctx->zstr.zalloc = Z_NULL;
|
||||
ctx->zstr.zfree = Z_NULL;
|
||||
ctx->zstr.opaque = NULL;
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
compress_allocate(zip_uint16_t method, zip_uint32_t compression_flags, zip_error_t *error) {
|
||||
(void)method;
|
||||
return allocate(true, compression_flags, error);
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
decompress_allocate(zip_uint16_t method, zip_uint32_t compression_flags, zip_error_t *error) {
|
||||
(void)method;
|
||||
return allocate(false, compression_flags, error);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
deallocate(void *ud) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
|
||||
static zip_uint16_t
|
||||
general_purpose_bit_flags(void *ud) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
|
||||
if (!ctx->compress) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->level < 3) {
|
||||
return 2 << 1;
|
||||
}
|
||||
else if (ctx->level > 7) {
|
||||
return 1 << 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
start(void *ud, zip_stat_t *st, zip_file_attributes_t *attributes) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
int ret;
|
||||
|
||||
(void)st;
|
||||
(void)attributes;
|
||||
|
||||
ctx->zstr.avail_in = 0;
|
||||
ctx->zstr.next_in = NULL;
|
||||
ctx->zstr.avail_out = 0;
|
||||
ctx->zstr.next_out = NULL;
|
||||
|
||||
if (ctx->compress) {
|
||||
/* negative value to tell zlib not to write a header */
|
||||
ret = deflateInit2(&ctx->zstr, ctx->level, Z_DEFLATED, -MAX_WBITS, ctx->mem_level, Z_DEFAULT_STRATEGY);
|
||||
}
|
||||
else {
|
||||
ret = inflateInit2(&ctx->zstr, -MAX_WBITS);
|
||||
}
|
||||
|
||||
if (ret != Z_OK) {
|
||||
zip_error_set(ctx->error, ZIP_ER_ZLIB, ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
end(void *ud) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
int err;
|
||||
|
||||
if (ctx->compress) {
|
||||
err = deflateEnd(&ctx->zstr);
|
||||
}
|
||||
else {
|
||||
err = inflateEnd(&ctx->zstr);
|
||||
}
|
||||
|
||||
if (err != Z_OK) {
|
||||
zip_error_set(ctx->error, ZIP_ER_ZLIB, err);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
input(void *ud, zip_uint8_t *data, zip_uint64_t length) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
|
||||
if (length > UINT_MAX || ctx->zstr.avail_in > 0) {
|
||||
zip_error_set(ctx->error, ZIP_ER_INVAL, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
ctx->zstr.avail_in = (uInt)length;
|
||||
ctx->zstr.next_in = (Bytef *)data;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
end_of_input(void *ud) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
|
||||
ctx->end_of_input = true;
|
||||
}
|
||||
|
||||
|
||||
static zip_compression_status_t
|
||||
process(void *ud, zip_uint8_t *data, zip_uint64_t *length) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
uInt avail_out;
|
||||
|
||||
int ret;
|
||||
|
||||
avail_out = (uInt)ZIP_MIN(UINT_MAX, *length);
|
||||
ctx->zstr.avail_out = avail_out;
|
||||
ctx->zstr.next_out = (Bytef *)data;
|
||||
|
||||
if (ctx->compress) {
|
||||
ret = deflate(&ctx->zstr, ctx->end_of_input ? Z_FINISH : 0);
|
||||
}
|
||||
else {
|
||||
ret = inflate(&ctx->zstr, Z_SYNC_FLUSH);
|
||||
}
|
||||
|
||||
*length = avail_out - ctx->zstr.avail_out;
|
||||
|
||||
switch (ret) {
|
||||
case Z_OK:
|
||||
return ZIP_COMPRESSION_OK;
|
||||
|
||||
case Z_STREAM_END:
|
||||
return ZIP_COMPRESSION_END;
|
||||
|
||||
case Z_BUF_ERROR:
|
||||
if (ctx->zstr.avail_in == 0) {
|
||||
return ZIP_COMPRESSION_NEED_DATA;
|
||||
}
|
||||
|
||||
/* fallthrough */
|
||||
|
||||
default:
|
||||
zip_error_set(ctx->error, ZIP_ER_ZLIB, ret);
|
||||
return ZIP_COMPRESSION_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
zip_compression_algorithm_t zip_algorithm_deflate_compress = {
|
||||
maximum_compressed_size,
|
||||
compress_allocate,
|
||||
deallocate,
|
||||
general_purpose_bit_flags,
|
||||
20,
|
||||
start,
|
||||
end,
|
||||
input,
|
||||
end_of_input,
|
||||
process
|
||||
};
|
||||
|
||||
|
||||
zip_compression_algorithm_t zip_algorithm_deflate_decompress = {
|
||||
maximum_compressed_size,
|
||||
decompress_allocate,
|
||||
deallocate,
|
||||
general_purpose_bit_flags,
|
||||
20,
|
||||
start,
|
||||
end,
|
||||
input,
|
||||
end_of_input,
|
||||
process
|
||||
};
|
||||
|
||||
/* clang-format on */
|
||||
+408
@@ -0,0 +1,408 @@
|
||||
/*
|
||||
zip_algorithm_xz.c -- LZMA/XZ (de)compression routines
|
||||
Bazed on zip_algorithm_deflate.c -- deflate (de)compression routines
|
||||
Copyright (C) 2017-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
3. The names of the authors may not be used to endorse or promote
|
||||
products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "zipint.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <lzma.h>
|
||||
#include <stdlib.h>
|
||||
#include <zlib.h>
|
||||
|
||||
enum header_state { INCOMPLETE, OUTPUT, DONE };
|
||||
|
||||
#define HEADER_BYTES_ZIP 9
|
||||
#define HEADER_MAGIC_LENGTH 4
|
||||
#define HEADER_MAGIC1_OFFSET 0
|
||||
#define HEADER_MAGIC2_OFFSET 2
|
||||
#define HEADER_SIZE_OFFSET 9
|
||||
#define HEADER_SIZE_LENGTH 8
|
||||
#define HEADER_PARAMETERS_LENGTH 5
|
||||
#define HEADER_LZMA_ALONE_LENGTH (HEADER_PARAMETERS_LENGTH + HEADER_SIZE_LENGTH)
|
||||
|
||||
struct ctx {
|
||||
zip_error_t *error;
|
||||
bool compress;
|
||||
zip_uint32_t compression_flags;
|
||||
bool end_of_input;
|
||||
lzma_stream zstr;
|
||||
zip_uint16_t method;
|
||||
/* header member is used for converting from zip to "lzma alone"
|
||||
* format
|
||||
*
|
||||
* "lzma alone" file format starts with:
|
||||
* 5 bytes lzma parameters
|
||||
* 8 bytes uncompressed size
|
||||
* compressed data
|
||||
*
|
||||
* zip archive on-disk format starts with
|
||||
* 4 bytes magic (first two bytes vary, e.g. 0x0914 or 0x1002, next bytes are 0x0500)
|
||||
* 5 bytes lzma parameters
|
||||
* compressed data
|
||||
*
|
||||
* we read the data into a header of the form
|
||||
* 4 bytes magic
|
||||
* 5 bytes lzma parameters
|
||||
* 8 bytes uncompressed size
|
||||
*/
|
||||
zip_uint8_t header[HEADER_MAGIC_LENGTH + HEADER_LZMA_ALONE_LENGTH];
|
||||
zip_uint8_t header_bytes_offset;
|
||||
enum header_state header_state;
|
||||
zip_uint64_t uncompresssed_size;
|
||||
};
|
||||
|
||||
|
||||
static zip_uint64_t
|
||||
maximum_compressed_size(zip_uint64_t uncompressed_size) {
|
||||
/*
|
||||
According to https://sourceforge.net/p/sevenzip/discussion/45797/thread/b6bd62f8/
|
||||
|
||||
1) you can use
|
||||
outSize = 1.10 * originalSize + 64 KB.
|
||||
in most cases outSize is less then 1.02 from originalSize.
|
||||
2) You can try LZMA2, where
|
||||
outSize can be = 1.001 * originalSize + 1 KB.
|
||||
*/
|
||||
/* 13 bytes added for lzma alone header */
|
||||
zip_uint64_t compressed_size = (zip_uint64_t)((double)uncompressed_size * 1.1) + 64 * 1024 + 13;
|
||||
|
||||
if (compressed_size < uncompressed_size) {
|
||||
return ZIP_UINT64_MAX;
|
||||
}
|
||||
return compressed_size;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
allocate(bool compress, zip_uint32_t compression_flags, zip_error_t *error, zip_uint16_t method) {
|
||||
struct ctx *ctx;
|
||||
|
||||
if ((ctx = (struct ctx *)malloc(sizeof(*ctx))) == NULL) {
|
||||
zip_error_set(error, ZIP_ER_MEMORY, 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx->error = error;
|
||||
ctx->compress = compress;
|
||||
if (compression_flags <= 9) {
|
||||
ctx->compression_flags = compression_flags;
|
||||
} else {
|
||||
ctx->compression_flags = 6; /* default value */
|
||||
}
|
||||
ctx->compression_flags |= LZMA_PRESET_EXTREME;
|
||||
ctx->end_of_input = false;
|
||||
memset(ctx->header, 0, sizeof(ctx->header));
|
||||
ctx->header_bytes_offset = 0;
|
||||
if (method == ZIP_CM_LZMA) {
|
||||
ctx->header_state = INCOMPLETE;
|
||||
}
|
||||
else {
|
||||
ctx->header_state = DONE;
|
||||
}
|
||||
memset(&ctx->zstr, 0, sizeof(ctx->zstr));
|
||||
ctx->method = method;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
compress_allocate(zip_uint16_t method, zip_uint32_t compression_flags, zip_error_t *error) {
|
||||
return allocate(true, compression_flags, error, method);
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
decompress_allocate(zip_uint16_t method, zip_uint32_t compression_flags, zip_error_t *error) {
|
||||
return allocate(false, compression_flags, error, method);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
deallocate(void *ud) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
|
||||
static zip_uint16_t
|
||||
general_purpose_bit_flags(void *ud) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
|
||||
if (!ctx->compress) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->method == ZIP_CM_LZMA) {
|
||||
/* liblzma always returns an EOS/EOPM marker, see
|
||||
* https://sourceforge.net/p/lzmautils/discussion/708858/thread/84c5dbb9/#a5e4/3764 */
|
||||
return 1 << 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
map_error(lzma_ret ret) {
|
||||
switch (ret) {
|
||||
case LZMA_DATA_ERROR:
|
||||
case LZMA_UNSUPPORTED_CHECK:
|
||||
return ZIP_ER_COMPRESSED_DATA;
|
||||
|
||||
case LZMA_MEM_ERROR:
|
||||
return ZIP_ER_MEMORY;
|
||||
|
||||
case LZMA_OPTIONS_ERROR:
|
||||
return ZIP_ER_INVAL;
|
||||
|
||||
default:
|
||||
return ZIP_ER_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
start(void *ud, zip_stat_t *st, zip_file_attributes_t *attributes) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
lzma_ret ret;
|
||||
|
||||
lzma_options_lzma opt_lzma;
|
||||
lzma_lzma_preset(&opt_lzma, ctx->compression_flags);
|
||||
lzma_filter filters[] = {
|
||||
{.id = (ctx->method == ZIP_CM_LZMA ? LZMA_FILTER_LZMA1 : LZMA_FILTER_LZMA2), .options = &opt_lzma},
|
||||
{.id = LZMA_VLI_UNKNOWN, .options = NULL},
|
||||
};
|
||||
|
||||
ctx->zstr.avail_in = 0;
|
||||
ctx->zstr.next_in = NULL;
|
||||
ctx->zstr.avail_out = 0;
|
||||
ctx->zstr.next_out = NULL;
|
||||
|
||||
if (ctx->compress) {
|
||||
if (ctx->method == ZIP_CM_LZMA)
|
||||
ret = lzma_alone_encoder(&ctx->zstr, filters[0].options);
|
||||
else
|
||||
ret = lzma_stream_encoder(&ctx->zstr, filters, LZMA_CHECK_CRC64);
|
||||
}
|
||||
else {
|
||||
if (ctx->method == ZIP_CM_LZMA)
|
||||
ret = lzma_alone_decoder(&ctx->zstr, UINT64_MAX);
|
||||
else
|
||||
ret = lzma_stream_decoder(&ctx->zstr, UINT64_MAX, LZMA_CONCATENATED);
|
||||
}
|
||||
|
||||
if (ret != LZMA_OK) {
|
||||
zip_error_set(ctx->error, map_error(ret), 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* If general purpose bits 1 & 2 are both zero, write real uncompressed size in header. */
|
||||
if ((attributes->valid & ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS) && (attributes->general_purpose_bit_mask & 0x6) == 0x6 && (attributes->general_purpose_bit_flags & 0x06) == 0 && (st->valid & ZIP_STAT_SIZE)) {
|
||||
ctx->uncompresssed_size = st->size;
|
||||
}
|
||||
else {
|
||||
ctx->uncompresssed_size = ZIP_UINT64_MAX;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
end(void *ud) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
|
||||
lzma_end(&ctx->zstr);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
input(void *ud, zip_uint8_t *data, zip_uint64_t length) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
|
||||
if (length > UINT_MAX || ctx->zstr.avail_in > 0) {
|
||||
zip_error_set(ctx->error, ZIP_ER_INVAL, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* For decompression of LZMA1: Have we read the full "lzma alone" header yet? */
|
||||
if (ctx->method == ZIP_CM_LZMA && !ctx->compress && ctx->header_state == INCOMPLETE) {
|
||||
/* if not, get more of the data */
|
||||
zip_uint8_t got = (zip_uint8_t)ZIP_MIN(HEADER_BYTES_ZIP - ctx->header_bytes_offset, length);
|
||||
(void)memcpy_s(ctx->header + ctx->header_bytes_offset, sizeof(ctx->header) - ctx->header_bytes_offset, data, got);
|
||||
ctx->header_bytes_offset += got;
|
||||
length -= got;
|
||||
data += got;
|
||||
/* Do we have a complete header now? */
|
||||
if (ctx->header_bytes_offset == HEADER_BYTES_ZIP) {
|
||||
Bytef empty_buffer[1];
|
||||
zip_buffer_t *buffer;
|
||||
/* check magic */
|
||||
if (ctx->header[HEADER_MAGIC2_OFFSET] != 0x05 || ctx->header[HEADER_MAGIC2_OFFSET + 1] != 0x00) {
|
||||
/* magic does not match */
|
||||
zip_error_set(ctx->error, ZIP_ER_COMPRESSED_DATA, 0);
|
||||
return false;
|
||||
}
|
||||
/* set size of uncompressed data in "lzma alone" header to "unknown" */
|
||||
if ((buffer = _zip_buffer_new(ctx->header + HEADER_SIZE_OFFSET, HEADER_SIZE_LENGTH)) == NULL) {
|
||||
zip_error_set(ctx->error, ZIP_ER_MEMORY, 0);
|
||||
return false;
|
||||
}
|
||||
_zip_buffer_put_64(buffer, ctx->uncompresssed_size);
|
||||
_zip_buffer_free(buffer);
|
||||
/* Feed header into "lzma alone" decoder, for
|
||||
* initialization; this should not produce output. */
|
||||
ctx->zstr.next_in = (void *)(ctx->header + HEADER_MAGIC_LENGTH);
|
||||
ctx->zstr.avail_in = HEADER_LZMA_ALONE_LENGTH;
|
||||
ctx->zstr.total_in = 0;
|
||||
ctx->zstr.next_out = empty_buffer;
|
||||
ctx->zstr.avail_out = sizeof(*empty_buffer);
|
||||
ctx->zstr.total_out = 0;
|
||||
/* this just initializes the decoder and does not produce output, so it consumes the complete header */
|
||||
if (lzma_code(&ctx->zstr, LZMA_RUN) != LZMA_OK || ctx->zstr.total_out > 0) {
|
||||
zip_error_set(ctx->error, ZIP_ER_COMPRESSED_DATA, 0);
|
||||
return false;
|
||||
}
|
||||
ctx->header_state = DONE;
|
||||
}
|
||||
}
|
||||
ctx->zstr.avail_in = (uInt)length;
|
||||
ctx->zstr.next_in = (Bytef *)data;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
end_of_input(void *ud) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
|
||||
ctx->end_of_input = true;
|
||||
}
|
||||
|
||||
|
||||
static zip_compression_status_t
|
||||
process(void *ud, zip_uint8_t *data, zip_uint64_t *length) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
uInt avail_out;
|
||||
lzma_ret ret;
|
||||
/* for compression of LZMA1 */
|
||||
if (ctx->method == ZIP_CM_LZMA && ctx->compress) {
|
||||
if (ctx->header_state == INCOMPLETE) {
|
||||
/* write magic to output buffer */
|
||||
ctx->header[0] = 0x09;
|
||||
ctx->header[1] = 0x14;
|
||||
ctx->header[2] = 0x05;
|
||||
ctx->header[3] = 0x00;
|
||||
/* generate lzma parameters into output buffer */
|
||||
ctx->zstr.avail_out = HEADER_LZMA_ALONE_LENGTH;
|
||||
ctx->zstr.next_out = ctx->header + HEADER_MAGIC_LENGTH;
|
||||
ret = lzma_code(&ctx->zstr, LZMA_RUN);
|
||||
if (ret != LZMA_OK || ctx->zstr.avail_out != 0) {
|
||||
/* assume that the whole header will be provided with the first call to lzma_code */
|
||||
return ZIP_COMPRESSION_ERROR;
|
||||
}
|
||||
ctx->header_state = OUTPUT;
|
||||
}
|
||||
if (ctx->header_state == OUTPUT) {
|
||||
/* write header */
|
||||
zip_uint8_t write_len = (zip_uint8_t)ZIP_MIN(HEADER_BYTES_ZIP - ctx->header_bytes_offset, *length);
|
||||
(void)memcpy_s(data, *length, ctx->header + ctx->header_bytes_offset, write_len);
|
||||
ctx->header_bytes_offset += write_len;
|
||||
*length = write_len;
|
||||
if (ctx->header_bytes_offset == HEADER_BYTES_ZIP) {
|
||||
ctx->header_state = DONE;
|
||||
}
|
||||
return ZIP_COMPRESSION_OK;
|
||||
}
|
||||
}
|
||||
|
||||
avail_out = (uInt)ZIP_MIN(UINT_MAX, *length);
|
||||
ctx->zstr.avail_out = avail_out;
|
||||
ctx->zstr.next_out = (Bytef *)data;
|
||||
|
||||
ret = lzma_code(&ctx->zstr, ctx->end_of_input ? LZMA_FINISH : LZMA_RUN);
|
||||
*length = avail_out - ctx->zstr.avail_out;
|
||||
|
||||
switch (ret) {
|
||||
case LZMA_OK:
|
||||
return ZIP_COMPRESSION_OK;
|
||||
|
||||
case LZMA_STREAM_END:
|
||||
return ZIP_COMPRESSION_END;
|
||||
|
||||
case LZMA_BUF_ERROR:
|
||||
if (ctx->zstr.avail_in == 0) {
|
||||
return ZIP_COMPRESSION_NEED_DATA;
|
||||
}
|
||||
|
||||
/* fallthrough */
|
||||
default:
|
||||
zip_error_set(ctx->error, map_error(ret), 0);
|
||||
return ZIP_COMPRESSION_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/* Version Required should be set to 63 (6.3) because this compression
|
||||
method was only defined in appnote.txt version 6.3.8, but Winzip
|
||||
does not unpack it if the value is not 20. */
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
zip_compression_algorithm_t zip_algorithm_xz_compress = {
|
||||
maximum_compressed_size,
|
||||
compress_allocate,
|
||||
deallocate,
|
||||
general_purpose_bit_flags,
|
||||
20,
|
||||
start,
|
||||
end,
|
||||
input,
|
||||
end_of_input,
|
||||
process
|
||||
};
|
||||
|
||||
|
||||
zip_compression_algorithm_t zip_algorithm_xz_decompress = {
|
||||
maximum_compressed_size,
|
||||
decompress_allocate,
|
||||
deallocate,
|
||||
general_purpose_bit_flags,
|
||||
20,
|
||||
start,
|
||||
end,
|
||||
input,
|
||||
end_of_input,
|
||||
process
|
||||
};
|
||||
|
||||
/* clang-format on */
|
||||
+298
@@ -0,0 +1,298 @@
|
||||
/*
|
||||
zip_algorithm_zstd.c -- zstd (de)compression routines
|
||||
Copyright (C) 2020-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
3. The names of the authors may not be used to endorse or promote
|
||||
products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "zipint.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <zstd.h>
|
||||
#include <zstd_errors.h>
|
||||
|
||||
struct ctx {
|
||||
zip_error_t *error;
|
||||
bool compress;
|
||||
int compression_flags;
|
||||
bool end_of_input;
|
||||
ZSTD_DStream *zdstream;
|
||||
ZSTD_CStream *zcstream;
|
||||
ZSTD_outBuffer out;
|
||||
ZSTD_inBuffer in;
|
||||
};
|
||||
|
||||
static zip_uint64_t
|
||||
maximum_compressed_size(zip_uint64_t uncompressed_size) {
|
||||
return ZSTD_compressBound(uncompressed_size);
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
allocate(bool compress, zip_uint32_t compression_flags, zip_error_t *error) {
|
||||
struct ctx *ctx;
|
||||
|
||||
if ((ctx = (struct ctx *)malloc(sizeof(*ctx))) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx->compression_flags = (zip_int32_t)compression_flags;
|
||||
if (ctx->compression_flags < ZSTD_minCLevel() || ctx->compression_flags > ZSTD_maxCLevel()) {
|
||||
ctx->compression_flags = 0; /* let zstd choose */
|
||||
}
|
||||
|
||||
ctx->error = error;
|
||||
ctx->compress = compress;
|
||||
ctx->end_of_input = false;
|
||||
|
||||
ctx->zdstream = NULL;
|
||||
ctx->zcstream = NULL;
|
||||
ctx->in.src = NULL;
|
||||
ctx->in.pos = 0;
|
||||
ctx->in.size = 0;
|
||||
ctx->out.dst = NULL;
|
||||
ctx->out.pos = 0;
|
||||
ctx->out.size = 0;
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
compress_allocate(zip_uint16_t method, zip_uint32_t compression_flags, zip_error_t *error) {
|
||||
(void)method;
|
||||
return allocate(true, compression_flags, error);
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
decompress_allocate(zip_uint16_t method, zip_uint32_t compression_flags, zip_error_t *error) {
|
||||
(void)method;
|
||||
return allocate(false, compression_flags, error);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
deallocate(void *ud) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
|
||||
static zip_uint16_t
|
||||
general_purpose_bit_flags(void *ud) {
|
||||
(void)ud;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
map_error(size_t ret) {
|
||||
switch (ret) {
|
||||
case ZSTD_error_no_error:
|
||||
return ZIP_ER_OK;
|
||||
|
||||
case ZSTD_error_corruption_detected:
|
||||
case ZSTD_error_checksum_wrong:
|
||||
case ZSTD_error_dictionary_corrupted:
|
||||
case ZSTD_error_dictionary_wrong:
|
||||
return ZIP_ER_COMPRESSED_DATA;
|
||||
|
||||
case ZSTD_error_memory_allocation:
|
||||
return ZIP_ER_MEMORY;
|
||||
|
||||
case ZSTD_error_parameter_unsupported:
|
||||
case ZSTD_error_parameter_outOfBound:
|
||||
return ZIP_ER_INVAL;
|
||||
|
||||
default:
|
||||
return ZIP_ER_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
start(void *ud, zip_stat_t *st, zip_file_attributes_t *attributes) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
|
||||
(void)st;
|
||||
(void)attributes;
|
||||
|
||||
ctx->in.src = NULL;
|
||||
ctx->in.pos = 0;
|
||||
ctx->in.size = 0;
|
||||
ctx->out.dst = NULL;
|
||||
ctx->out.pos = 0;
|
||||
ctx->out.size = 0;
|
||||
if (ctx->compress) {
|
||||
size_t ret;
|
||||
ctx->zcstream = ZSTD_createCStream();
|
||||
if (ctx->zcstream == NULL) {
|
||||
zip_error_set(ctx->error, ZIP_ER_MEMORY, 0);
|
||||
return false;
|
||||
}
|
||||
ret = ZSTD_initCStream(ctx->zcstream, ctx->compression_flags);
|
||||
if (ZSTD_isError(ret)) {
|
||||
zip_error_set(ctx->error, ZIP_ER_ZLIB, map_error(ret));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ctx->zdstream = ZSTD_createDStream();
|
||||
if (ctx->zdstream == NULL) {
|
||||
zip_error_set(ctx->error, ZIP_ER_MEMORY, 0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
end(void *ud) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
size_t ret;
|
||||
|
||||
if (ctx->compress) {
|
||||
ret = ZSTD_freeCStream(ctx->zcstream);
|
||||
ctx->zcstream = NULL;
|
||||
}
|
||||
else {
|
||||
ret = ZSTD_freeDStream(ctx->zdstream);
|
||||
ctx->zdstream = NULL;
|
||||
}
|
||||
|
||||
if (ZSTD_isError(ret)) {
|
||||
zip_error_set(ctx->error, map_error(ret), 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
input(void *ud, zip_uint8_t *data, zip_uint64_t length) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
if (length > SIZE_MAX || ctx->in.pos != ctx->in.size) {
|
||||
zip_error_set(ctx->error, ZIP_ER_INVAL, 0);
|
||||
return false;
|
||||
}
|
||||
ctx->in.src = (const void *)data;
|
||||
ctx->in.size = (size_t)length;
|
||||
ctx->in.pos = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
end_of_input(void *ud) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
|
||||
ctx->end_of_input = true;
|
||||
}
|
||||
|
||||
|
||||
static zip_compression_status_t
|
||||
process(void *ud, zip_uint8_t *data, zip_uint64_t *length) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
|
||||
size_t ret;
|
||||
|
||||
if (ctx->in.pos == ctx->in.size && !ctx->end_of_input) {
|
||||
*length = 0;
|
||||
return ZIP_COMPRESSION_NEED_DATA;
|
||||
}
|
||||
|
||||
ctx->out.dst = data;
|
||||
ctx->out.pos = 0;
|
||||
ctx->out.size = ZIP_MIN(SIZE_MAX, *length);
|
||||
|
||||
if (ctx->compress) {
|
||||
if (ctx->in.pos == ctx->in.size && ctx->end_of_input) {
|
||||
ret = ZSTD_endStream(ctx->zcstream, &ctx->out);
|
||||
if (ret == 0) {
|
||||
*length = ctx->out.pos;
|
||||
return ZIP_COMPRESSION_END;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ret = ZSTD_compressStream(ctx->zcstream, &ctx->out, &ctx->in);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ret = ZSTD_decompressStream(ctx->zdstream, &ctx->out, &ctx->in);
|
||||
}
|
||||
if (ZSTD_isError(ret)) {
|
||||
zip_error_set(ctx->error, map_error(ret), 0);
|
||||
return ZIP_COMPRESSION_ERROR;
|
||||
}
|
||||
|
||||
*length = ctx->out.pos;
|
||||
if (ctx->in.pos == ctx->in.size) {
|
||||
return ZIP_COMPRESSION_NEED_DATA;
|
||||
}
|
||||
|
||||
return ZIP_COMPRESSION_OK;
|
||||
}
|
||||
|
||||
/* Version Required should be set to 63 (6.3) because this compression
|
||||
method was only defined in appnote.txt version 6.3.7, but Winzip
|
||||
does not unpack it if the value is not 20. */
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
zip_compression_algorithm_t zip_algorithm_zstd_compress = {
|
||||
maximum_compressed_size,
|
||||
compress_allocate,
|
||||
deallocate,
|
||||
general_purpose_bit_flags,
|
||||
20,
|
||||
start,
|
||||
end,
|
||||
input,
|
||||
end_of_input,
|
||||
process
|
||||
};
|
||||
|
||||
|
||||
zip_compression_algorithm_t zip_algorithm_zstd_decompress = {
|
||||
maximum_compressed_size,
|
||||
decompress_allocate,
|
||||
deallocate,
|
||||
general_purpose_bit_flags,
|
||||
20,
|
||||
start,
|
||||
end,
|
||||
input,
|
||||
end_of_input,
|
||||
process
|
||||
};
|
||||
|
||||
/* clang-format on */
|
||||
Vendored
+337
@@ -0,0 +1,337 @@
|
||||
/*
|
||||
zip_buffer.c -- bounds checked access to memory buffer
|
||||
Copyright (C) 2014-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
3. The names of the authors may not be used to endorse or promote
|
||||
products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "zipint.h"
|
||||
|
||||
zip_uint8_t *
|
||||
_zip_buffer_data(zip_buffer_t *buffer) {
|
||||
return buffer->data;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_zip_buffer_free(zip_buffer_t *buffer) {
|
||||
if (buffer == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (buffer->free_data) {
|
||||
free(buffer->data);
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
_zip_buffer_eof(zip_buffer_t *buffer) {
|
||||
return buffer->ok && buffer->offset == buffer->size;
|
||||
}
|
||||
|
||||
|
||||
zip_uint8_t *
|
||||
_zip_buffer_get(zip_buffer_t *buffer, zip_uint64_t length) {
|
||||
zip_uint8_t *data;
|
||||
|
||||
data = _zip_buffer_peek(buffer, length);
|
||||
|
||||
if (data != NULL) {
|
||||
buffer->offset += length;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
zip_uint16_t
|
||||
_zip_buffer_get_16(zip_buffer_t *buffer) {
|
||||
zip_uint8_t *data = _zip_buffer_get(buffer, 2);
|
||||
|
||||
if (data == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (zip_uint16_t)(data[0] + (data[1] << 8));
|
||||
}
|
||||
|
||||
|
||||
zip_uint32_t
|
||||
_zip_buffer_get_32(zip_buffer_t *buffer) {
|
||||
zip_uint8_t *data = _zip_buffer_get(buffer, 4);
|
||||
|
||||
if (data == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ((((((zip_uint32_t)data[3] << 8) + data[2]) << 8) + data[1]) << 8) + data[0];
|
||||
}
|
||||
|
||||
|
||||
zip_uint64_t
|
||||
_zip_buffer_get_64(zip_buffer_t *buffer) {
|
||||
zip_uint8_t *data = _zip_buffer_get(buffer, 8);
|
||||
|
||||
if (data == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ((zip_uint64_t)data[7] << 56) + ((zip_uint64_t)data[6] << 48) + ((zip_uint64_t)data[5] << 40) + ((zip_uint64_t)data[4] << 32) + ((zip_uint64_t)data[3] << 24) + ((zip_uint64_t)data[2] << 16) + ((zip_uint64_t)data[1] << 8) + (zip_uint64_t)data[0];
|
||||
}
|
||||
|
||||
|
||||
zip_uint8_t
|
||||
_zip_buffer_get_8(zip_buffer_t *buffer) {
|
||||
zip_uint8_t *data = _zip_buffer_get(buffer, 1);
|
||||
|
||||
if (data == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return data[0];
|
||||
}
|
||||
|
||||
|
||||
zip_uint64_t
|
||||
_zip_buffer_left(zip_buffer_t *buffer) {
|
||||
return buffer->ok ? buffer->size - buffer->offset : 0;
|
||||
}
|
||||
|
||||
|
||||
zip_uint64_t
|
||||
_zip_buffer_read(zip_buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length) {
|
||||
zip_uint64_t copied;
|
||||
|
||||
if (_zip_buffer_left(buffer) < length) {
|
||||
length = _zip_buffer_left(buffer);
|
||||
}
|
||||
|
||||
copied = 0;
|
||||
while (copied < length) {
|
||||
size_t n = ZIP_MIN(length - copied, SIZE_MAX);
|
||||
(void)memcpy_s(data + copied, n, _zip_buffer_get(buffer, n), n);
|
||||
copied += n;
|
||||
}
|
||||
|
||||
return copied;
|
||||
}
|
||||
|
||||
|
||||
zip_buffer_t *
|
||||
_zip_buffer_new(zip_uint8_t *data, zip_uint64_t size) {
|
||||
bool free_data = (data == NULL);
|
||||
zip_buffer_t *buffer;
|
||||
|
||||
#if ZIP_UINT64_MAX > SIZE_MAX
|
||||
if (size > SIZE_MAX) {
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (data == NULL) {
|
||||
if ((data = (zip_uint8_t *)malloc((size_t)size)) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if ((buffer = (zip_buffer_t *)malloc(sizeof(*buffer))) == NULL) {
|
||||
if (free_data) {
|
||||
free(data);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer->ok = true;
|
||||
buffer->data = data;
|
||||
buffer->size = size;
|
||||
buffer->offset = 0;
|
||||
buffer->free_data = free_data;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
zip_buffer_t *
|
||||
_zip_buffer_new_from_source(zip_source_t *src, zip_uint64_t size, zip_uint8_t *buf, zip_error_t *error) {
|
||||
zip_buffer_t *buffer;
|
||||
|
||||
if ((buffer = _zip_buffer_new(buf, size)) == NULL) {
|
||||
zip_error_set(error, ZIP_ER_MEMORY, 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (_zip_read(src, buffer->data, size, error) < 0) {
|
||||
_zip_buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
zip_uint64_t
|
||||
_zip_buffer_offset(zip_buffer_t *buffer) {
|
||||
return buffer->ok ? buffer->offset : 0;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
_zip_buffer_ok(zip_buffer_t *buffer) {
|
||||
return buffer->ok;
|
||||
}
|
||||
|
||||
|
||||
zip_uint8_t *
|
||||
_zip_buffer_peek(zip_buffer_t *buffer, zip_uint64_t length) {
|
||||
zip_uint8_t *data;
|
||||
|
||||
if (!buffer->ok || buffer->offset + length < length || buffer->offset + length > buffer->size) {
|
||||
buffer->ok = false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = buffer->data + buffer->offset;
|
||||
return data;
|
||||
}
|
||||
|
||||
int
|
||||
_zip_buffer_put(zip_buffer_t *buffer, const void *src, size_t length) {
|
||||
zip_uint8_t *dst = _zip_buffer_get(buffer, length);
|
||||
|
||||
if (dst == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
(void)memcpy_s(dst, length, src, length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_zip_buffer_put_16(zip_buffer_t *buffer, zip_uint16_t i) {
|
||||
zip_uint8_t *data = _zip_buffer_get(buffer, 2);
|
||||
|
||||
if (data == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
data[0] = (zip_uint8_t)(i & 0xff);
|
||||
data[1] = (zip_uint8_t)((i >> 8) & 0xff);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_zip_buffer_put_32(zip_buffer_t *buffer, zip_uint32_t i) {
|
||||
zip_uint8_t *data = _zip_buffer_get(buffer, 4);
|
||||
|
||||
if (data == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
data[0] = (zip_uint8_t)(i & 0xff);
|
||||
data[1] = (zip_uint8_t)((i >> 8) & 0xff);
|
||||
data[2] = (zip_uint8_t)((i >> 16) & 0xff);
|
||||
data[3] = (zip_uint8_t)((i >> 24) & 0xff);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_zip_buffer_put_64(zip_buffer_t *buffer, zip_uint64_t i) {
|
||||
zip_uint8_t *data = _zip_buffer_get(buffer, 8);
|
||||
|
||||
if (data == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
data[0] = (zip_uint8_t)(i & 0xff);
|
||||
data[1] = (zip_uint8_t)((i >> 8) & 0xff);
|
||||
data[2] = (zip_uint8_t)((i >> 16) & 0xff);
|
||||
data[3] = (zip_uint8_t)((i >> 24) & 0xff);
|
||||
data[4] = (zip_uint8_t)((i >> 32) & 0xff);
|
||||
data[5] = (zip_uint8_t)((i >> 40) & 0xff);
|
||||
data[6] = (zip_uint8_t)((i >> 48) & 0xff);
|
||||
data[7] = (zip_uint8_t)((i >> 56) & 0xff);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_zip_buffer_put_8(zip_buffer_t *buffer, zip_uint8_t i) {
|
||||
zip_uint8_t *data = _zip_buffer_get(buffer, 1);
|
||||
|
||||
if (data == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
data[0] = i;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_zip_buffer_set_offset(zip_buffer_t *buffer, zip_uint64_t offset) {
|
||||
if (offset > buffer->size) {
|
||||
buffer->ok = false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
buffer->ok = true;
|
||||
buffer->offset = offset;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_zip_buffer_skip(zip_buffer_t *buffer, zip_uint64_t length) {
|
||||
zip_uint64_t offset = buffer->offset + length;
|
||||
|
||||
if (offset < buffer->offset) {
|
||||
buffer->ok = false;
|
||||
return -1;
|
||||
}
|
||||
return _zip_buffer_set_offset(buffer, offset);
|
||||
}
|
||||
|
||||
zip_uint64_t
|
||||
_zip_buffer_size(zip_buffer_t *buffer) {
|
||||
return buffer->size;
|
||||
}
|
||||
Vendored
+745
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user