--- /dev/null
+---
+name: Bug Report
+about: Report where libzip didn't behave like you expected.
+title: ''
+labels: bug
+assignees: ''
+
+---
+
+**Describe the Bug**
+A clear and concise description of what the bug is.
+
+**Expected Behavior**
+A clear and concise description of what you expected to happen.
+
+**Observed Behavior**
+A clear and concise description of what actually happened.
+
+**To Reproduce**
+Short program or code snippet that reproduces the problem.
+
+**libzip Version**
+Version of libzip or revision repository used.
+
+**Operating System**
+Operating system and version, used compiler.
+
+**Test Files**
+If applicable, attach and describe zip archives that trigger the problem.
+
+**Additional context**
+Add any other context about the problem here.
--- /dev/null
+---
+name: Compile Error
+about: Report when libzip does not compile.
+title: ''
+labels: compile
+assignees: ''
+
+---
+
+**Compiler Error**
+Output from the compiler, including exact and complete error message, file name and line number.
+
+**libzip Version**
+Version of libzip or revision repository used.
+
+**Operating System and Compiler**
+The operating system and compiler used, including version number.
+
+Also, any flags passed to `cmake`.
+
+**Autodetected Configuration**
+Attach `CmakeCache.txt` from your build directory. This list everything `cmake` detected on your system.
+
+**Additional context**
+Add any other context about the problem here.
--- /dev/null
+---
+name: Feature Request
+about: Suggest an idea for this project.
+title: ''
+labels: enhancement
+assignees: ''
+
+---
+
+**Description**
+A clear and concise description of what you want to achieve, why the current features are insufficient, and why you think it is generally useful.
+
+Also, have you checked wether the feature is already mentioned in TODO.md? If so, only submit a new issue if you expand on it.
+
+**Solution**
+A clear and concise description of what you want to happen.
+
+**Describe alternatives you've considered**
+A clear and concise description of any alternative solutions or features you've considered.
+
+**Additional context**
+Add any other context about the feature request here.
OPTION(ENABLE_WINDOWS_CRYPTO "Enable use of Windows cryptography libraries" ON)
OPTION(ENABLE_BZIP2 "Enable use of BZip2" ON)
+OPTION(ENABLE_LZMA "Enable use of LZMA" ON)
OPTION(BUILD_TOOLS "Build tools in the src directory (zipcmp, zipmerge, ziptool)" ON)
OPTION(BUILD_REGRESS "Build regression tests" ON)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckIncludeFiles)
+INCLUDE(CheckLibraryExists)
INCLUDE(CheckSymbolExists)
INCLUDE(CheckTypeSize)
INCLUDE(CheckCSourceRuns)
ENDIF()
IF(ENABLE_MBEDTLS)
FIND_PATH(MBEDTLS_INCLUDE_DIR mbedtls/aes.h)
- FIND_LIBRARY(MBEDTLS_LIBRARIES NAMES mbedtls)
+ FIND_LIBRARY(MBEDTLS_LIBRARIES NAMES mbedcrypto)
ELSE()
SET(MBEDTLS_LIBRARIES FALSE)
ENDIF()
SET(PACKAGE "libzip")
SET(PACKAGE_NAME ${PACKAGE})
SET(PACKAGE_VERSION_MAJOR "1")
-SET(PACKAGE_VERSION_MINOR "5")
-SET(PACKAGE_VERSION_MICRO "2")
+SET(PACKAGE_VERSION_MINOR "6")
+SET(PACKAGE_VERSION_MICRO "0")
#SET(VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}")
SET(VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_MICRO}")
SET(PACKAGE_VERSION ${VERSION})
SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
SET(ARCHIVE_NAME ${PACKAGE_NAME}-${PACKAGE_VERSION})
+IF(NOT TARGET dist)
ADD_CUSTOM_TARGET(dist
COMMAND git config tar.tar.xz.command "xz -c"
COMMAND git archive --prefix=${ARCHIVE_NAME}/ -o ${ARCHIVE_NAME}.tar.gz HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
ADD_DEPENDENCIES(distcheck dist)
+ENDIF(NOT TARGET dist)
IF(BUILD_SHARED_LIBS)
SET(HAVE_SHARED TRUE)
CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
CHECK_FUNCTION_EXISTS(_strtoi64 HAVE__STRTOI64)
CHECK_FUNCTION_EXISTS(_strtoui64 HAVE__STRTOUI64)
-CHECK_FUNCTION_EXISTS(_umask HAVE__UMASK)
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(fseeko HAVE_FSEEKO)
CHECK_FUNCTION_EXISTS(ftello HAVE_FTELLO)
CHECK_FUNCTION_EXISTS(getprogname HAVE_GETPROGNAME)
+CHECK_FUNCTION_EXISTS(localtime_r HAVE_LOCALTIME_R)
CHECK_FUNCTION_EXISTS(open HAVE_OPEN)
-CHECK_FUNCTION_EXISTS(mkstemp HAVE_MKSTEMP)
CHECK_FUNCTION_EXISTS(setmode HAVE_SETMODE)
CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
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)
TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
-FIND_PACKAGE(ZLIB REQUIRED)
+FIND_PACKAGE(ZLIB 1.1.2 REQUIRED)
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
SET(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR})
-IF(ZLIB_VERSION_STRING VERSION_LESS "1.1.2")
- MESSAGE(FATAL_ERROR "-- ZLIB version too old, please install at least v1.1.2")
-ENDIF(ZLIB_VERSION_STRING VERSION_LESS "1.1.2")
IF(ENABLE_BZIP2)
FIND_PACKAGE(BZip2)
SET (HAVE_LIBBZ2 1)
INCLUDE_DIRECTORIES(${BZIP2_INCLUDE_DIR})
- SET (OPTIONAL_LIBRARY ${BZIP2_LIBRARY})
+ SET (OPTIONAL_LIBRARY ${OPTIONAL_LIBRARY} ${BZIP2_LIBRARIES})
ELSE()
MESSAGE(WARNING "-- bzip2 library not found; bzip2 support disabled")
ENDIF(BZIP2_FOUND)
ENDIF(ENABLE_BZIP2)
+IF(ENABLE_LZMA)
+ FIND_PACKAGE(LibLZMA)
+ IF(LIBLZMA_FOUND)
+ SET (HAVE_LIBLZMA 1)
+
+ INCLUDE_DIRECTORIES(${LIBLZMA_INCLUDE_DIR})
+ SET (OPTIONAL_LIBRARY ${OPTIONAL_LIBRARY} ${LIBLZMA_LIBRARY})
+ ELSE()
+ MESSAGE(WARNING "-- lzma library not found; lzma support disabled")
+ ENDIF(LIBLZMA_FOUND)
+ENDIF(ENABLE_LZMA)
+
+
IF (COMMONCRYPTO_FOUND)
SET (HAVE_CRYPTO 1)
SET (HAVE_COMMONCRYPTO 1)
if(WIN32)
if(HAVE_WINDOWS_CRYPTO)
- SET (OPTIONAL_LIBRARY "${OPTIONAL_LIBRARY}" bcrypt)
+ SET (OPTIONAL_LIBRARY ${OPTIONAL_LIBRARY} bcrypt)
endif()
if(CMAKE_SYSTEM_NAME MATCHES WindowsPhone OR CMAKE_SYSTEM_NAME MATCHES WindowsStore)
ADD_DEFINITIONS(-DMS_UWP)
else(CMAKE_SYSTEM_NAME MATCHES WindowsPhone OR CMAKE_SYSTEM_NAME MATCHES WindowsStore)
- SET (OPTIONAL_LIBRARY "${OPTIONAL_LIBRARY}" advapi32)
+ SET (OPTIONAL_LIBRARY ${OPTIONAL_LIBRARY} advapi32)
endif(CMAKE_SYSTEM_NAME MATCHES WindowsPhone OR CMAKE_SYSTEM_NAME MATCHES WindowsStore)
endif(WIN32)
SET(bindir \${exec_prefix}/${CMAKE_INSTALL_BINDIR})
SET(libdir \${exec_prefix}/${CMAKE_INSTALL_LIBDIR})
SET(includedir \${prefix}/${CMAKE_INSTALL_INCLUDEDIR})
-IF(BZIP2_FOUND)
- SET(LIBS "${LIBS} -lbz2")
-ENDIF()
-SET(LIBS "${LIBS} -lz")
IF(CMAKE_SYSTEM_NAME MATCHES BSD)
SET(PKG_CONFIG_RPATH "-Wl,-R\${libdir}")
ENDIF(CMAKE_SYSTEM_NAME MATCHES BSD)
+get_target_property(LIBS_PRIVATE zip LINK_LIBRARIES)
+foreach(LIB ${LIBS_PRIVATE})
+ if(LIB MATCHES "^/")
+ get_filename_component(LIB ${LIB} NAME_WE)
+ string(REGEX REPLACE "^lib" "" LIB ${LIB})
+ endif()
+ set(LIBS "${LIBS} -l${LIB}")
+endforeach()
CONFIGURE_FILE(libzip.pc.in libzip.pc @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libzip.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# fixed size integral types
-IF(HAVE_STDINT_H_LIBZIP)
+IF(HAVE_INTTYPES_H_LIBZIP)
+ SET(LIBZIP_TYPES_INCLUDE "#define __STDC_FORMAT_MACROS 1
+#include <inttypes.h>")
+ELSEIF(HAVE_STDINT_H_LIBZIP)
SET(LIBZIP_TYPES_INCLUDE "#include <stdint.h>")
-ELSEIF(HAVE_INTTYPES_H_LIBZIP)
- SET(LIBZIP_TYPES_INCLUDE "#include <inttypes.h>")
ELSEIF(HAVE_SYS_TYPES_H_LIBZIP)
SET(LIBZIP_TYPES_INCLUDE "#include <sys/types.h>")
ENDIF()
SET(srcdir ${CMAKE_CURRENT_SOURCE_DIR}/regress)
SET(abs_srcdir ${CMAKE_CURRENT_SOURCE_DIR}/regress)
-SET(top_builddir ${CMAKE_BINARY_DIR})
+SET(top_builddir ${CMAKE_CURRENT_BINARY_DIR}) # used to find config.h
-CONFIGURE_FILE(regress/runtest.in ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/runtest @ONLY)
-FILE(COPY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/runtest
- DESTINATION ${CMAKE_BINARY_DIR}/regress
+CONFIGURE_FILE(regress/runtest.in ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/runtest @ONLY)
+FILE(COPY ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/runtest
+ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/regress
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
For supporting bzip2-compressed zip archives, you need
[bzip2](http://bzip.org/).
+For supporting xz-compressed zip archives, you need
+[liblzma](https://tukaani.org/xz/) which is part of xz.
+
For AES (encryption) support, you need one of these cryptographic libraries,
listed in order of preference:
If you are compiling on a system with a small stack size, add
`-DZIP_ALLOCATE_BUFFER` to `CFLAGS`.
+If you are building on a 32-bit Linux system it might be necessary
+to define `_FILE_OFFSET_BITS` to `64`. Your distro will need to provide
+a `fts.h` file that is new enough to support this, or the build
+will break in `zipcmp`.
+
You can get verbose build output with by passing `VERBOSE=1` to
`make`.
-Copyright (C) 1999-2017 Dieter Baron and Thomas Klausner
+Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
The authors can be contacted at <libzip@nih.at>
+1.6.0 [2020-01-24]
+==================
+
+* Avoid using umask() since it's not thread-safe.
+* Set close-on-exec flag when opening files.
+* Do not accept empty files as valid zip archives any longer.
+* Add support for XZ compressed files (using liblzma).
+* Add support for cancelling while closing zip archives.
+* Add support for setting the time in the on-disk format.
+
1.5.2 [2019-03-12]
==================
* Fix bug in AES encryption affecting certain file sizes
-This is libzip, a C library for reading, creating, and modifying zip
-archives. Files can be added from data buffers, files, or compressed
-data copied directly from other zip archives. Changes made without
-closing the archive can be reverted. Decryption and encryption of
-Winzip AES and decryption of legacy PKware encrypted files is
-supported. The API is documented by man pages.
+This is libzip, a C library for reading, creating, and modifying
+zip and zip64 archives. Files can be added from data buffers, files,
+or compressed data copied directly from other zip archives. Changes
+made without closing the archive can be reverted. Decryption and
+encryption of Winzip AES and decryption of legacy PKware encrypted
+files is supported. The API is documented by man pages.
libzip is fully documented via man pages. HTML versions of the man
pages are on [libzip.org](https://libzip.org/documentation/) and
Agostino Sarubbo
Alexander Galanin <al@galanin.nnov.ru>
Alexandr Shadchin <alexandr.shadchin@gmail.com>
+Alexey Bykov <gnfalex@rambler.ru>
Andreas Falkenhahn <andreas@falkenhahn.com>
Andrew Brampton <brampton@gmail.com>
Andrew Molyneux <andrew@molyneuxfamily.co.uk>
Ankur Kothari <ankz.kothari@gmail.com>
BALATON Zoltan <balaton@eik.bme.hu>
Benjamin Gilbert <bgilbert@backtick.net>
+Beuc <beuc@beuc.net>
Boaz Stolk <bstolk@aweta.nl>
Bogdan <bogiebog@gmail.com>
Brian 'geeknik' Carpenter <geeknik@protonmail.ch>
Carl Mastrangelo <notcarl@google.com>
Cédric Tabin
+celan69
Chris Nehren <cnehren+libzip@pobox.com>
Coverity <info@coverity.com>
Dane Springmeyer <dane.springmeyer@gmail.com>
David Demelier <demelier.david@gmail.com>
+Declan Moran
Del Merritt <del@alum.mit.edu>
Dmytro Rybachenko <atmoliton@gmail.com>
Elvis Angelaccio
Info-ZIP group
Jan Weiß <jan@geheimwerk.de>
Jay Freeman (saurik) <saurik@saurik.com>
+Joachim Reichel <joachim.reichel@gmx.de>
João Custódio <joao_custodio@symantec.com>
Joel Ebrahimi <joel.ebrahimi@gmail.com>
Jono Spiro <jono.spiro@gmail.com>
Julien Schueller <schueller@phimeca.com>
+kensington <kensington@gentoo.org>
Keith Jones <keith@keithjjones.com>
Kohei Yoshida <kohei.yoshida@gmail.com>
Leith Bade <leith@mapbox.com>
Lubomir I. Ivanov <neolit123@gmail.com>
Maël Nison
Martin Buchholz <martinrb@google.com>
-Martin Herkt
+Martin Herkt <lachs0r@srsfckn.biz>
Martin Szulecki <m.szulecki@libimobiledevice.org>
Michael Balzer
Michael Beck <mm.beck@gmx.net>
Michal Vyskocil <mvyskocil@suse.cz>
Mikhail Gusarov <dottedmag@dottedmag.net>.
Miklos Vajna
+Morris Hafner
Oliver Kaiser <under.northern.sky@googlemail.com>
Oliver Kuckertz <oliver.kuckertz@mologie.de>
+OSS-Fuzz Team
Pascal Terjan <pterjan@gmail.com>
Patrick Spendrin <ps_ml@gmx.de>
Paul Harris <harris.pc@gmail.com>
Pavel Raiskup <praiskup@redhat.com>
Pierre Joye <pierre.php@gmail.com>
Pierre-Louis Cabelguen <plcabelguen@googlemail.com>
+Randy <randy408@protonmail.com>
Remi Collet <remi@fedoraproject.org>
Richard Schütz
Rick Carback <carback1@umbc.edu>
Robert Norris <rw_norris@hotmail.com>
Roberto Tirabassi <rtirabassi@3di.it>
Roland Ortloff <Ortloff.R@gmx.de>
+Rosen Penev <rosenp@gmail.com>
+Sebastian Kemper <sebastian_ml@gmx.net>
+Sebastian Schmitt <sebastian.schmitt@auvesy.de>
Sergei Ozerov <ru.programmist@gmail.com>
Simon Talbot <simont@nse.co.uk>
Stephen Bryant <steve@bawue.de>
Timo Warns <warns@pre-sense.de>
Tom Callaway <tcallawa@redhat.com>
Tomas Hoger <thoger@redhat.com>
-Tomáš Malý
+Tomáš Malý <malytomas@ucpu.cz>
Torsten Paul <Torsten.Paul@gmx.de>
Vassili Courzakis <vcoxvco@googlemail.com>
William Lee
--- /dev/null
+
+# Author: Declan Moran
+# www.silverglint.com
+# Thanks to damaex (https://github.com/damaex), for significant contributions
+
+ANDROID_NDK_ROOT=/home/android/android-ndk-r19c
+
+INSTALL_DIR=install
+BUILD_DIR=build
+START_DIR=$(pwd)
+
+rm -rf $INSTALL_DIR
+rm -rf $BUILD_DIR
+mkdir -p $BUILD_DIR #"${ANDROID_TARGET_PLATFORM}"
+
+#--------------------------------------------------------------------
+build_it()
+{
+ # builds either a static or shared lib depending on parm passed (ON or OFF)
+ want_shared=$1
+
+ cmake -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake \
+ -DCMAKE_INSTALL_PREFIX:PATH=../../${INSTALL_DIR}/${ANDROID_TARGET_PLATFORM} \
+ -DANDROID_ABI=${ANDROID_TARGET_PLATFORM} \
+ -DENABLE_OPENSSL:BOOL=OFF \
+ -DENABLE_COMMONCRYPTO:BOOL=OFF \
+ -DENABLE_GNUTLS:BOOL=OFF \
+ -DENABLE_MBEDTLS:BOOL=OFF \
+ -DENABLE_OPENSSL:BOOL=OFF \
+ -DENABLE_WINDOWS_CRYPTO:BOOL=OFF \
+ -DBUILD_TOOLS:BOOL=OFF \
+ -DBUILD_REGRESS:BOOL=OFF \
+ -DBUILD_EXAMPLES:BOOL=OFF \
+ -DBUILD_SHARED_LIBS:BOOL=$want_shared \
+ -DBUILD_DOC:BOOL=OFF \
+ -DANDROID_TOOLCHAIN=clang cmake -H.. -B$BUILD_DIR/${ANDROID_TARGET_PLATFORM}
+
+ #run make with all system threads and install
+ cd $BUILD_DIR/${ANDROID_TARGET_PLATFORM}
+ make install -j$(nproc --all)
+ cd $START_DIR
+ }
+
+#--------------------------------------------------------------------
+for ANDROID_TARGET_PLATFORM in armeabi-v7a arm64-v8a x86 x86_64
+do
+ echo "Building libzip for ${ANDROID_TARGET_PLATFORM}"
+
+ build_it ON
+ build_it OFF
+
+ if [ $? -ne 0 ]; then
+ echo "Error executing: cmake"
+ exit 1
+ fi
+
+
+ if [ $? -ne 0 ]; then
+ echo "Error executing make install for platform: ${ANDROID_TARGET_PLATFORM}"
+ exit 1
+ fi
+
+done
--- /dev/null
+# Version: 1.0
+
+# Dockerfile for building libzip for android
+# https://github.com/dec1/libzip.git
+# creates docker container with all tools, libraries and sources required to build libzip for android.
+
+# Author: Declan Moran
+# www.silverglint.com
+
+
+# Usage:
+#---------
+# download the libzip repository
+# > git clone https://github.com/dec1/libzip.git
+# > cd libzip
+#
+# build docker image "my_img_zip" from the dockerfile in "docker" dir
+# > docker build -t my_img_zip ./android/docker
+#
+# run docker container "my_ctr_zip" from this image, mounting the current dir. (Need to pass absolute host paths to mount volume- hence "pwd")
+# > docker run -v $(pwd):/home/docker-share/libzip -it --entrypoint=/bin/bash --name my_ctr_zip my_img_zip
+#
+# Now inside docker container
+# $ cd /home/docker-share/libzip/android
+#
+# Modify ./do.sh (on host), to match the boost and android ndk versions/paths in the "Configure here" section below
+# Build from running docker container.
+# $./do.sh
+#
+# "./build" dir contains required build, but owned by root. chown to your username/group
+# > sudo chown -R <userid>:<groupid> ./build
+# > sudo chown -R <userid>:<groupid> ./install
+#
+# Exit container, when build is finsihed.
+# $ exit
+#
+
+
+
+
+FROM ubuntu:18.04
+
+
+## --------------------------------------------------------------------
+## Configure here
+# ---------------------------------------------------------------------
+# ---------------------------------------------------------------------
+# Here you can speciofy exactly what android ndk (and sdk) version you want to use.
+
+
+
+# (2) Android SDK
+# https://developer.android.com/studio#downloads
+ARG SDK_URL_BASE=https://dl.google.com/android/repository
+ARG SDK_FILE=sdk-tools-linux-4333796.zip
+
+# the sdk plaform to use
+# https://developer.android.com/guide/topics/manifest/uses-sdk-element
+ARG ANDROID_SDK_PLATFORM_VERS="platforms;android-28"
+
+
+
+# (3) Android NDK
+# https://developer.android.com/ndk/downloads
+ARG NDK_URL_BASE=https://dl.google.com/android/repository
+ARG NDK_FILE=android-ndk-r19c-linux-x86_64.zip
+# ---------------------------------------------------------------------
+## --------------------------------------------------------------------
+
+RUN apt-get update
+RUN apt-get -y dist-upgrade
+
+
+# for downloading archives
+RUN apt-get -y install wget
+
+# for unzipping downloaded android archives
+RUN apt-get -y install zip
+RUN apt-get -y install cmake
+
+RUN apt-get -y install lib32z1
+
+
+# need this this to install some (32 bit) prerequisites for android builds
+RUN dpkg --add-architecture i386
+RUN apt-get update
+RUN apt-get -y dist-upgrade
+RUN apt-get install -y libc6:i386 libncurses5:i386 libstdc++6:i386 libbz2-1.0:i386
+
+
+# need c compiler to set up create boost build system (before building boost with it and android toolchain)
+RUN apt-get -y install build-essential
+RUN apt-get -y install libc6-dev-i386
+RUN apt-get -y install clang
+
+RUN apt-get -y install openjdk-8-jdk
+#--------------------------------------
+
+ARG ANDROID_HOME=/home/android
+WORKDIR ${ANDROID_HOME}
+
+
+# SDK
+# ----
+# download android sdk command line tools
+RUN wget ${SDK_URL_BASE}/$SDK_FILE
+RUN unzip $SDK_FILE
+
+ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools
+
+
+RUN yes | sdkmanager --licenses
+
+RUN sdkmanager "platform-tools" $ANDROID_SDK_PLATFORM_VERS
+#RUN sdkmanager "platform-tools" "platforms;android-28"
+
+
+# NDK
+# ----
+RUN wget ${NDK_URL_BASE}/$NDK_FILE
+RUN unzip $NDK_FILE
+
--- /dev/null
+
+Cross compile libzip for android.
+--------------------------------
+Modify "do.sh" as appropriate if you need to specify a different ndk dir or wish to specify different build parameters
+
+Prerequisites for the development machine - see docker/Dockerfile
+
+You can either set you host machine up with these prerequisites or simply use docker (in which case you need not install anything on your host machine except docker itself).
+
+See "Usage" in docker/Dockerfile for detailed instructions.
os:
- Visual Studio 2017
+
environment:
matrix:
- GENERATOR: "Visual Studio 15 2017 Win64"
TRIPLET: x64-windows
CMAKE_OPTS: "-DBUILD_SHARED_LIBS=off"
+ CMAKE_CONFIG: Release
+ - GENERATOR: "Visual Studio 15 2017 Win64"
+ TRIPLET: x64-windows
+ CMAKE_OPTS: "-DBUILD_SHARED_LIBS=off"
+ CMAKE_CONFIG: Debug
+ - GENERATOR: "Visual Studio 15 2017 Win64"
+ TRIPLET: x64-uwp
+ CMAKE_OPTS: "-DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0"
+ CMAKE_CONFIG: Release
+ - GENERATOR: "Visual Studio 15 2017"
+ TRIPLET: x86-windows
+ CMAKE_OPTS: "-DBUILD_SHARED_LIBS=off"
+ CMAKE_CONFIG: Release
- GENERATOR: "Visual Studio 15 2017"
TRIPLET: x86-windows
CMAKE_OPTS: "-DBUILD_SHARED_LIBS=off"
+ CMAKE_CONFIG: Debug
+ - GENERATOR: "Visual Studio 15 2017"
+ TRIPLET: x86-uwp
+ CMAKE_OPTS: "-DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0"
+ CMAKE_CONFIG: Release
- GENERATOR: "Visual Studio 15 2017 ARM"
TRIPLET: arm-windows
CMAKE_OPTS: "-DENABLE_OPENSSL=off"
- - GENERATOR: "Visual Studio 15 2017"
- TRIPLET: x86-uwp
- CMAKE_OPTS: "-DCMAKE_SYSTEM_NAME=WindowsStore"
- - GENERATOR: "Visual Studio 15 2017 Win64"
- TRIPLET: x64-uwp
- CMAKE_OPTS: "-DCMAKE_SYSTEM_NAME=WindowsStore"
+ CMAKE_CONFIG: Release
- GENERATOR: "Visual Studio 15 2017 ARM"
TRIPLET: arm-uwp
- CMAKE_OPTS: "-DCMAKE_SYSTEM_NAME=WindowsStore -DENABLE_OPENSSL=off"
+ CMAKE_OPTS: "-DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 -DENABLE_OPENSSL=off"
+ CMAKE_CONFIG: Release
- GENERATOR: "Visual Studio 15 2017"
TRIPLET: arm64-windows
CMAKE_OPTS: "-AARM64 -DENABLE_OPENSSL=off"
+ CMAKE_CONFIG: Release
- GENERATOR: "Visual Studio 15 2017"
TRIPLET: arm64-uwp
- CMAKE_OPTS: "-AARM64 -DCMAKE_SYSTEM_NAME=WindowsStore -DENABLE_OPENSSL=off"
+ CMAKE_OPTS: "-AARM64 -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 -DENABLE_OPENSSL=off"
+ CMAKE_CONFIG: Release
+
before_build:
cmd: >-
git clone https://github.com/Microsoft/vcpkg
build_script:
cmd: >-
- cmake --build . --config Release --target INSTALL
+ cmake --build . --config %CMAKE_CONFIG% --target INSTALL
+
+ cmake --build . --config %CMAKE_CONFIG%
+
+test_script:
+ cmd: >-
+ set VERBOSE=yes
- cmake --build . --config Debug --target INSTALL
+ ctest -C %CMAKE_CONFIG% --output-on-failure
#cmakedefine HAVE__STRTOUI64
#cmakedefine HAVE__UMASK
#cmakedefine HAVE__UNLINK
+#cmakedefine HAVE_ARC4RANDOM
#cmakedefine HAVE_CLONEFILE
#cmakedefine HAVE_COMMONCRYPTO
#cmakedefine HAVE_CRYPTO
#cmakedefine HAVE_GETPROGNAME
#cmakedefine HAVE_GNUTLS
#cmakedefine HAVE_LIBBZ2
+#cmakedefine HAVE_LIBLZMA
+#cmakedefine HAVE_LOCALTIME_R
#cmakedefine HAVE_MBEDTLS
#cmakedefine HAVE_MKSTEMP
#cmakedefine HAVE_NULLABLE
/*
in-memory.c -- modify zip file in memory
- Copyright (C) 2014-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
windows-open.c -- open zip archive using Windows UTF-16/Unicode file name
- Copyright (C) 2015-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2015-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
IF(${_variable} STREQUAL NOTFOUND)
SET(${_variable} ${_default_value})
ENDIF()
-
+
ENDMACRO()
-
+
MACRO(CREATE_LIBTOOL_FILE _target _install_DIR)
GET_TARGET_PROPERTY(_target_location ${_target} LOCATION)
GET_TARGET_PROPERTY_WITH_DEFAULT(_target_static_lib ${_target} STATIC_LIB "")
FILE(APPEND ${_laname} "libdir='${CMAKE_INSTALL_PREFIX}/${_install_DIR}'\n")
INSTALL( FILES ${_laname} ${_soname} DESTINATION ${CMAKE_INSTALL_PREFIX}${_install_DIR})
ENDMACRO()
-
+
SET(LIBZIP_SOURCES
zip_add.c
zip_add_dir.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
ENDIF()
ELSE(WIN32)
SET(LIBZIP_OPSYS_FILES
+ zip_mkstempm.c
zip_source_file.c
+ zip_random_unix.c
)
ENDIF(WIN32)
COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/make_zip_err_str.sh ${CMAKE_CURRENT_SOURCE_DIR}/zip.h ${CMAKE_CURRENT_SOURCE_DIR}/zip_err_str.c
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/zip.h ${CMAKE_CURRENT_SOURCE_DIR}/make_zip_err_str.sh
)
-CHECK_FUNCTION_EXISTS(mkstemp HAVE_MKSTEMP)
-IF(NOT HAVE_MKSTEMP)
- SET(LIBZIP_EXTRA_FILES mkstemp.c)
-ENDIF(NOT HAVE_MKSTEMP)
IF(HAVE_LIBBZ2)
SET(LIBZIP_OPTIONAL_FILES zip_algorithm_bzip2.c)
ENDIF()
+IF(HAVE_LIBLZMA)
+ SET(LIBZIP_OPTIONAL_FILES ${LIBZIP_OPTIONAL_FILES} zip_algorithm_xz.c)
+ENDIF()
+
IF(HAVE_COMMONCRYPTO)
SET(LIBZIP_OPTIONAL_FILES ${LIBZIP_OPTIONAL_FILES} zip_crypto_commoncrypto.c
-)
+)
ELSEIF(HAVE_WINDOWS_CRYPTO)
SET(LIBZIP_OPTIONAL_FILES ${LIBZIP_OPTIONAL_FILES} zip_crypto_win.c
)
ADD_LIBRARY(zip ${LIBZIP_SOURCES} ${LIBZIP_EXTRA_FILES} ${LIBZIP_OPTIONAL_FILES} ${LIBZIP_OPSYS_FILES})
IF(SHARED_LIB_VERSIONNING)
-SET_TARGET_PROPERTIES(zip PROPERTIES VERSION 5.0 SOVERSION 5)
+SET_TARGET_PROPERTIES(zip PROPERTIES VERSION 5.1 SOVERSION 5)
ENDIF()
-TARGET_LINK_LIBRARIES(zip ${ZLIB_LIBRARY} ${OPTIONAL_LIBRARY})
+TARGET_LINK_LIBRARIES(zip PRIVATE ${ZLIB_LIBRARIES} ${OPTIONAL_LIBRARY})
INSTALL(TARGETS zip
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
/*
compat.h -- compatibility defines.
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
#define EOVERFLOW EFBIG
#endif
+/* not supported on at least Windows */
+#ifndef O_CLOEXEC
+#define O_CLOEXEC 0
+#endif
+
#ifdef _WIN32
#if defined(HAVE__CHMOD)
#define chmod _chmod
#if !defined(HAVE_STRTOULL) && defined(HAVE__STRTOUI64)
#define strtoull _strtoui64
#endif
-#if defined(HAVE__UMASK)
-#define umask _umask
-#endif
#if defined(HAVE__UNLINK)
#define unlink _unlink
#endif
#define ftello(s) ((long)ftell((s)))
#endif
-#ifndef HAVE_MKSTEMP
-int _zip_mkstemp(char *);
-#define mkstemp _zip_mkstemp
-#endif
-
#if !defined(HAVE_STRCASECMP)
#if defined(HAVE__STRICMP)
#define strcasecmp _stricmp
#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 */
+++ /dev/null
-/* Adapted from NetBSB libc by Dieter Baron */
-
-/* NetBSD: gettemp.c,v 1.13 2003/12/05 00:57:36 uebayasi Exp */
-
-/*
- * Copyright (c) 1987, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * 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. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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 <sys/stat.h>
-#include <sys/types.h>
-
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#ifdef _WIN32
-#include <io.h>
-#include <process.h>
-#else
-#include <unistd.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
-
-int
-_zip_mkstemp(char *path) {
-#ifdef _WIN32
- int ret;
- ret = _creat(_mktemp(path), _S_IREAD | _S_IWRITE);
- if (ret == -1) {
- return 0;
- }
- else {
- return ret;
- }
-#else
- int fd;
- char *start, *trv;
- struct stat sbuf;
- pid_t pid;
-
- /* To guarantee multiple calls generate unique names even if
- the file is not created. 676 different possibilities with 7
- or more X's, 26 with 6 or less. */
- static char xtra[2] = "aa";
- int xcnt = 0;
-
- pid = getpid();
-
- /* Move to end of path and count trailing X's. */
- for (trv = path; *trv; ++trv)
- if (*trv == 'X')
- xcnt++;
- else
- xcnt = 0;
-
- /* Use at least one from xtra. Use 2 if more than 6 X's. */
- if (*(trv - 1) == 'X')
- *--trv = xtra[0];
- if (xcnt > 6 && *(trv - 1) == 'X')
- *--trv = xtra[1];
-
- /* Set remaining X's to pid digits with 0's to the left. */
- while (*--trv == 'X') {
- *trv = (pid % 10) + '0';
- pid /= 10;
- }
-
- /* update xtra for next call. */
- if (xtra[0] != 'z')
- xtra[0]++;
- else {
- xtra[0] = 'a';
- if (xtra[1] != 'z')
- xtra[1]++;
- else
- xtra[1] = 'a';
- }
-
- /*
- * check the target directory; if you have six X's and it
- * doesn't exist this runs for a *very* long time.
- */
- for (start = trv + 1;; --trv) {
- if (trv <= path)
- break;
- if (*trv == '/') {
- *trv = '\0';
- if (stat(path, &sbuf))
- return (0);
- if (!S_ISDIR(sbuf.st_mode)) {
- errno = ENOTDIR;
- return (0);
- }
- *trv = '/';
- break;
- }
- }
-
- for (;;) {
- if ((fd = open(path, O_CREAT | O_EXCL | O_RDWR | O_BINARY, 0600)) >= 0)
- return (fd);
- if (errno != EEXIST)
- return (0);
-
- /* tricky little algorithm for backward compatibility */
- for (trv = start;;) {
- if (!*trv)
- return (0);
- if (*trv == 'z')
- *trv++ = 'a';
- else {
- if (isdigit((unsigned char)*trv))
- *trv = 'a';
- else
- ++*trv;
- break;
- }
- }
- }
- /*NOTREACHED*/
-#endif
-}
/*
zip.h -- exported declarations.
- Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2020 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
#define ZIP_ER_INUSE 29 /* N Resource still in use */
#define ZIP_ER_TELL 30 /* S Tell error */
#define ZIP_ER_COMPRESSED_DATA 31 /* N Compressed data invalid */
+#define ZIP_ER_CANCELLED 32 /* N Operation cancelled */
/* type of system error value */
/* 15-17 - Reserved by PKWARE */
#define ZIP_CM_TERSE 18 /* compressed using IBM TERSE (new) */
#define ZIP_CM_LZ77 19 /* IBM LZ77 z Architecture (PFS) */
+#define ZIP_CM_LZMA2 33
#define ZIP_CM_XZ 95 /* XZ compressed data */
#define ZIP_CM_JPEG 96 /* Compressed Jpeg data */
#define ZIP_CM_WAVPACK 97 /* WavPack compressed data */
ZIP_SOURCE_SUPPORTS, /* check whether source supports command */
ZIP_SOURCE_REMOVE, /* remove file */
ZIP_SOURCE_GET_COMPRESSION_FLAGS, /* get compression flags, internal only */
- ZIP_SOURCE_BEGIN_WRITE_CLONING /* like ZIP_SOURCE_BEGIN_WRITE, but keep part of original file */
+ ZIP_SOURCE_BEGIN_WRITE_CLONING, /* like ZIP_SOURCE_BEGIN_WRITE, but keep part of original file */
+ ZIP_SOURCE_ACCEPT_EMPTY /* whether empty files are valid archives */
};
typedef enum zip_source_cmd zip_source_cmd_t;
typedef zip_int64_t (*zip_source_callback)(void * _Nullable, void * _Nullable, zip_uint64_t, zip_source_cmd_t);
typedef void (*zip_progress_callback)(zip_t * _Nonnull, double, void * _Nullable);
+typedef int (*zip_cancel_callback)(zip_t * _Nonnull, void * _Nullable);
#ifndef ZIP_DISABLE_DEPRECATED
typedef void (*zip_progress_callback_t)(double);
ZIP_EXTERN int zip_file_rename(zip_t * _Nonnull, zip_uint64_t, const char * _Nonnull, zip_flags_t);
ZIP_EXTERN int zip_file_replace(zip_t * _Nonnull, zip_uint64_t, zip_source_t * _Nonnull, zip_flags_t);
ZIP_EXTERN int zip_file_set_comment(zip_t * _Nonnull, zip_uint64_t, const char * _Nullable, zip_uint16_t, zip_flags_t);
+ZIP_EXTERN int zip_file_set_dostime(zip_t * _Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t, zip_flags_t);
ZIP_EXTERN int zip_file_set_encryption(zip_t * _Nonnull, zip_uint64_t, zip_uint16_t, const char * _Nullable);
ZIP_EXTERN int zip_file_set_external_attributes(zip_t * _Nonnull, zip_uint64_t, zip_flags_t, zip_uint8_t, zip_uint32_t);
ZIP_EXTERN int zip_file_set_mtime(zip_t * _Nonnull, zip_uint64_t, time_t, zip_flags_t);
ZIP_EXTERN zip_t * _Nullable zip_open(const char * _Nonnull, int, int * _Nullable);
ZIP_EXTERN zip_t * _Nullable zip_open_from_source(zip_source_t * _Nonnull, int, zip_error_t * _Nullable);
ZIP_EXTERN int zip_register_progress_callback_with_state(zip_t * _Nonnull, double, zip_progress_callback _Nullable, void (* _Nullable)(void * _Nullable), void * _Nullable);
+ZIP_EXTERN int zip_register_cancel_callback_with_state(zip_t * _Nonnull, zip_cancel_callback _Nullable, void (* _Nullable)(void * _Nullable), void * _Nullable);
ZIP_EXTERN int zip_set_archive_comment(zip_t * _Nonnull, const char * _Nullable, zip_uint16_t);
ZIP_EXTERN int zip_set_archive_flag(zip_t * _Nonnull, zip_flags_t, int);
ZIP_EXTERN int zip_set_default_password(zip_t * _Nonnull, const char * _Nullable);
ZIP_EXTERN zip_source_t * _Nullable zip_source_buffer(zip_t * _Nonnull, const void * _Nullable, zip_uint64_t, int);
ZIP_EXTERN zip_source_t * _Nullable zip_source_buffer_create(const void * _Nullable, zip_uint64_t, int, zip_error_t * _Nullable);
ZIP_EXTERN zip_source_t * _Nullable zip_source_buffer_fragment(zip_t * _Nonnull, const zip_buffer_fragment_t * _Nonnull, zip_uint64_t, int);
-ZIP_EXTERN zip_source_t * _Nullable zip_source_buffer_fragment_create(const zip_buffer_fragment_t * _Nonnull, zip_uint64_t, int, zip_error_t * _Nullable);
+ZIP_EXTERN zip_source_t * _Nullable zip_source_buffer_fragment_create(const zip_buffer_fragment_t * _Nullable, zip_uint64_t, int, zip_error_t * _Nullable);
ZIP_EXTERN int zip_source_close(zip_source_t * _Nonnull);
ZIP_EXTERN int zip_source_commit_write(zip_source_t * _Nonnull);
ZIP_EXTERN zip_error_t * _Nonnull zip_source_error(zip_source_t * _Nonnull);
/*
zip_add.c -- add file via callback function
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_add_dir.c -- add directory
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_add_entry.c -- create and init struct zip_entry
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_algorithm_bzip2.c -- bzip2 (de)compression routines
- Copyright (C) 2017-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2017-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_algorithm_deflate.c -- deflate (de)compression routines
- Copyright (C) 2017-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2017-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
struct ctx *ctx;
if ((ctx = (struct ctx *)malloc(sizeof(*ctx))) == NULL) {
+ zip_error_set(error, ZIP_ET_SYS, errno);
return NULL;
}
--- /dev/null
+/*
+ zip_algorithm_xz.c -- XZ (de)compression routines
+ Bazed on zip_algorithm_deflate.c -- deflate (de)compression routines
+ Copyright (C) 2017-2019 Dieter Baron and Thomas Klausner
+
+ This file is part of libzip, a library to manipulate ZIP archives.
+ The authors can be contacted at <libzip@nih.at>
+
+ 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 <lzma.h>
+
+struct ctx {
+ zip_error_t *error;
+ bool compress;
+ int compression_flags;
+ bool end_of_input;
+ lzma_stream zstr;
+ zip_uint16_t method;
+};
+
+
+static void *
+allocate(bool compress, int 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_ET_SYS, errno);
+ return NULL;
+ }
+
+ ctx->error = error;
+ ctx->compress = compress;
+ ctx->compression_flags = compression_flags;
+ ctx->compression_flags |= LZMA_PRESET_EXTREME;
+ ctx->end_of_input = false;
+ memset(&ctx->zstr, 0, sizeof(ctx->zstr));
+ ctx->method = method;
+ return ctx;
+}
+
+
+static void *
+compress_allocate(zip_uint16_t method, int compression_flags, zip_error_t *error) {
+ return allocate(true, compression_flags, error, method);
+}
+
+
+static void *
+decompress_allocate(zip_uint16_t method, int 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 int
+compression_flags(void *ud) {
+ /* struct ctx *ctx = (struct ctx *)ud; */
+ return 0;
+}
+
+static int
+map_error(lzma_ret ret) {
+ switch (ret) {
+ 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) {
+ 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;
+ }
+
+ 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;
+ }
+
+ 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;
+ lzma_ret ret;
+
+ ctx->zstr.avail_out = (uInt)ZIP_MIN(UINT_MAX, *length);
+ ctx->zstr.next_out = (Bytef *)data;
+
+ ret = lzma_code(&ctx->zstr, ctx->end_of_input ? LZMA_FINISH : LZMA_RUN);
+ *length = *length - 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;
+ }
+}
+
+// clang-format off
+
+zip_compression_algorithm_t zip_algorithm_xz_compress = {
+ compress_allocate,
+ deallocate,
+ compression_flags,
+ start,
+ end,
+ input,
+ end_of_input,
+ process
+};
+
+
+zip_compression_algorithm_t zip_algorithm_xz_decompress = {
+ decompress_allocate,
+ deallocate,
+ compression_flags,
+ start,
+ end,
+ input,
+ end_of_input,
+ process
+};
+
+// clang-format on
/*
zip_buffer.c -- bounds checked access to memory buffer
- Copyright (C) 2014-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_close.c -- close zip archive and update changes
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2020 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
if (survivors == 0) {
if ((za->open_flags & ZIP_TRUNCATE) || changed) {
if (zip_source_remove(za->src) < 0) {
- _zip_error_set_from_source(&za->error, za->src);
- return -1;
+ if (!((zip_error_code_zip(zip_source_error(za->src)) == ZIP_ER_REMOVE) && (zip_error_code_system(zip_source_error(za->src)) == ENOENT))) {
+ _zip_error_set_from_source(&za->error, za->src);
+ return -1;
+ }
}
}
zip_discard(za);
}
}
- _zip_progress_start(za->progress);
+ if (_zip_progress_start(za->progress) != 0) {
+ zip_error_set(&za->error, ZIP_ER_CANCELLED, 0);
+ zip_source_rollback_write(za->src);
+ free(filelist);
+ return -1;
+ }
error = 0;
for (j = 0; j < survivors; j++) {
int new_data;
zip_entry_t *entry;
zip_dirent_t *de;
- _zip_progress_subrange(za->progress, (double)j / (double)survivors, (double)(j + 1) / (double)survivors);
+ if (_zip_progress_subrange(za->progress, (double)j / (double)survivors, (double)(j + 1) / (double)survivors) != 0) {
+ zip_error_set(&za->error, ZIP_ER_CANCELLED, 0);
+ error = 1;
+ break;
+ }
i = filelist[j].idx;
entry = za->entry + i;
_zip_error_set_from_source(&za->error, za->src);
error = 1;
}
+ _zip_progress_end(za->progress);
}
- _zip_progress_end(za->progress);
-
if (error) {
zip_source_rollback_write(za->src);
return -1;
len -= n;
- _zip_progress_update(za->progress, (total - (double)len) / total);
+ if (_zip_progress_update(za->progress, (total - (double)len) / total) != 0) {
+ zip_error_set(&za->error, ZIP_ER_CANCELLED, 0);
+ return -1;
+ }
}
byte_array_fini(buf);
}
if (n == BUFSIZE && za->progress && data_length > 0) {
current += n;
- _zip_progress_update(za->progress, (double)current / (double)data_length);
+ if (_zip_progress_update(za->progress, (double)current / (double)data_length) != 0) {
+ zip_error_set(&za->error, ZIP_ER_CANCELLED, 0);
+ ret = -1;
+ break;
+ }
}
}
/*
zip_crypto.h -- crypto definitions
- Copyright (C) 2017-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2017-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_crypto_commoncrypto.c -- CommonCrypto wrapper.
- Copyright (C) 2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2018-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
return hmac;
}
-
-
-ZIP_EXTERN bool
-zip_random(zip_uint8_t *buffer, zip_uint16_t length) {
- int fd;
-
- if ((fd = open("/dev/urandom", O_RDONLY)) < 0) {
- return false;
- }
-
- if (read(fd, buffer, length) != length) {
- close(fd);
- return false;
- }
-
- close(fd);
- return true;
-}
/*
zip_crypto_gnutls.c -- GnuTLS wrapper.
- Copyright (C) 2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2018-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
ZIP_EXTERN bool
-zip_random(zip_uint8_t *buffer, zip_uint16_t length) {
+zip_secure_random(zip_uint8_t *buffer, zip_uint16_t length) {
return gnutls_rnd(GNUTLS_RND_KEY, buffer, length) == 0;
}
/*
zip_crypto_gnutls.h -- definitions for GnuTLS wrapper.
- Copyright (C) 2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2018-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
#ifndef HAD_ZIP_CRYPTO_GNUTLS_H
#define HAD_ZIP_CRYPTO_GNUTLS_H
+#define HAVE_SECURE_RANDOM
+
#include <nettle/aes.h>
#include <nettle/pbkdf2.h>
-#include <gnutls/crypto.h>
#include <gnutls/gnutls.h>
+#include <gnutls/crypto.h>
typedef struct {
union {
/*
zip_crypto_mbedtls.c -- mbed TLS wrapper
- Copyright (C) 2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2018-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
} zip_random_context_t;
ZIP_EXTERN bool
-zip_random(zip_uint8_t *buffer, zip_uint16_t length) {
+zip_secure_random(zip_uint8_t *buffer, zip_uint16_t length) {
static zip_random_context_t *ctx = NULL;
const unsigned char *pers = "zip_crypto_mbedtls";
/*
zip_crypto_mbedtls.h -- definitions for mbedtls wrapper
- Copyright (C) 2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2018-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
#ifndef HAD_ZIP_CRYPTO_MBEDTLS_H
#define HAD_ZIP_CRYPTO_MBEDTLS_H
+#define HAVE_SECURE_RANDOM
+
#include <mbedtls/aes.h>
#include <mbedtls/md.h>
/*
zip_crypto_openssl.c -- OpenSSL wrapper.
- Copyright (C) 2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2018-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
ZIP_EXTERN bool
-zip_random(zip_uint8_t *buffer, zip_uint16_t length) {
+zip_secure_random(zip_uint8_t *buffer, zip_uint16_t length) {
return RAND_bytes(buffer, length) == 1;
}
/*
zip_crypto_openssl.h -- definitions for OpenSSL wrapper.
- Copyright (C) 2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2018-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
#ifndef HAD_ZIP_CRYPTO_OPENSSL_H
#define HAD_ZIP_CRYPTO_OPENSSL_H
+#define HAVE_SECURE_RANDOM
+
#include <openssl/aes.h>
#include <openssl/hmac.h>
/*
zip_crypto_win.c -- Windows Crypto API wrapper.
- Copyright (C) 2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2018-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
#define WIN32_LEAN_AND_MEAN
#define NOCRYPT
-#include <Windows.h>
+#include <windows.h>
#include <bcrypt.h>
#pragma comment(lib, "bcrypt.lib")
if (cbPassword > BLOCK_SIZE) {
BCRYPT_HASH_HANDLE hHash = NULL;
PUCHAR pbHashObject = malloc(pContext->cbHashObject);
+ if (pbHashObject == NULL) {
+ goto hmacInit_end;
+ }
bStatus = BCRYPT_SUCCESS(BCryptCreateHash(pContext->hAlgorithm, &hHash, pbHashObject, pContext->cbHashObject, NULL, 0, 0)) && BCRYPT_SUCCESS(BCryptHashData(hHash, pbPassword, cbPassword, 0)) && BCRYPT_SUCCESS(BCryptGetProperty(hHash, BCRYPT_HASH_LENGTH, (PUCHAR)&cbPassword, sizeof(cbPassword), &cbResult, 0)) && BCRYPT_SUCCESS(BCryptFinishHash(hHash, key, cbPassword, 0));
BCRYPT_HASH_HANDLE hHash = NULL;
PUCHAR pbHashObject = malloc(cbHashObject);
+ if (pbHashObject == NULL) {
+ return FALSE;
+ }
+
if (BCRYPT_SUCCESS(BCryptDuplicateHash(hHashTemplate, &hHash, pbHashObject, cbHashObject, 0))) {
success = BCRYPT_SUCCESS(BCryptHashData(hHash, pbData, cbData, 0)) && BCRYPT_SUCCESS(BCryptFinishHash(hHash, pbOutput, cbOutput, 0));
return BCRYPT_SUCCESS(BCryptGetProperty(pContext->hAlgorithm, BCRYPT_OBJECT_LENGTH, (PUCHAR)&cbHashObject, sizeof(cbHashObject), &cbResult, 0)) && hmacCalculateInternal(pContext->hInnerHash, pbData, cbData, pbDigest, DIGEST_SIZE, cbHashObject) && hmacCalculateInternal(pContext->hOuterHash, pbDigest, DIGEST_SIZE, pbDigest, DIGEST_SIZE, cbHashObject);
}
-static void xor
- (LPBYTE ptr1, LPBYTE ptr2, DWORD dwLen) {
- while (dwLen--)
- *ptr1++ ^= *ptr2++;
- }
+static void
+xor(LPBYTE ptr1, LPBYTE ptr2, DWORD dwLen) {
+ while (dwLen--)
+ *ptr1++ ^= *ptr2++;
+}
- BOOL pbkdf2(PUCHAR pbPassword, ULONG cbPassword, PUCHAR pbSalt, ULONG cbSalt, DWORD cIterations, PUCHAR pbDerivedKey, ULONG cbDerivedKey) {
+BOOL
+pbkdf2(PUCHAR pbPassword, ULONG cbPassword, PUCHAR pbSalt, ULONG cbSalt, DWORD cIterations, PUCHAR pbDerivedKey, ULONG cbDerivedKey) {
BOOL bStatus = FALSE;
DWORD l, r, dwULen, i, j;
BYTE Ti[DIGEST_SIZE];
LPBYTE U = malloc(max((cbSalt + 4), DIGEST_SIZE));
PRF_CTX prfCtx = {0};
+ if (U == NULL) {
+ return FALSE;
+ }
+
if (pbPassword == NULL || cbPassword == 0 || pbSalt == NULL || cbSalt == 0 || cIterations == 0 || pbDerivedKey == NULL || cbDerivedKey == 0) {
free(U);
return FALSE;
}
aes->pbKeyObject = malloc(aes->cbKeyObject);
+ if (aes->pbKeyObject == NULL) {
+ _zip_crypto_aes_free(aes);
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
+ return NULL;
+ }
if (!BCRYPT_SUCCESS(BCryptGenerateSymmetricKey(aes->hAlgorithm, &aes->hKey, aes->pbKeyObject, aes->cbKeyObject, (PUCHAR)key, key_length, 0))) {
_zip_crypto_aes_free(aes);
}
hmac->pbHashObject = malloc(hmac->cbHashObject);
+ if (hmac->pbHashObject == NULL) {
+ _zip_crypto_hmac_free(hmac);
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
+ return NULL;
+ }
status = BCryptGetProperty(hmac->hAlgorithm, BCRYPT_HASH_LENGTH, (PUCHAR)&hmac->cbHash, sizeof(hmac->cbHash), &cbResult, 0);
if (!BCRYPT_SUCCESS(status)) {
}
hmac->pbHash = malloc(hmac->cbHash);
+ if (hmac->pbHash == NULL) {
+ _zip_crypto_hmac_free(hmac);
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
+ return NULL;
+ }
status = BCryptCreateHash(hmac->hAlgorithm, &hmac->hHash, hmac->pbHashObject, hmac->cbHashObject, (PUCHAR)secret, (ULONG)secret_length, 0);
if (!BCRYPT_SUCCESS(status)) {
}
ZIP_EXTERN bool
-zip_random(zip_uint8_t *buffer, zip_uint16_t length) {
+zip_secure_random(zip_uint8_t *buffer, zip_uint16_t length) {
return BCRYPT_SUCCESS(BCryptGenRandom(NULL, buffer, length, BCRYPT_USE_SYSTEM_PREFERRED_RNG));
}
/*
zip_crypto_win.h -- Windows Crypto API wrapper.
- Copyright (C) 2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2018-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
#ifndef HAD_ZIP_CRYPTO_WIN_H
#define HAD_ZIP_CRYPTO_WIN_H
+#define HAVE_SECURE_RANDOM
+
typedef struct _zip_crypto_aes_s _zip_crypto_aes_t;
typedef struct _zip_crypto_hmac_s _zip_crypto_hmac_t;
/*
zip_delete.c -- delete file from zip archive
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_dir_add.c -- add directory
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_dirent.c -- read directory entry (local or central), clean dirent
- Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2020 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
#include "zipint.h"
-static time_t _zip_d2u_time(zip_uint16_t, zip_uint16_t);
static zip_string_t *_zip_dirent_process_ef_utf_8(const zip_dirent_t *de, zip_uint16_t id, zip_string_t *str);
static zip_extra_field_t *_zip_ef_utf8(zip_uint16_t, zip_string_t *, zip_error_t *);
static bool _zip_dirent_process_winzip_aes(zip_dirent_t *de, zip_error_t *error);
}
-static time_t
+time_t
_zip_d2u_time(zip_uint16_t dtime, zip_uint16_t ddate) {
struct tm tm;
void
_zip_u2d_time(time_t intime, zip_uint16_t *dtime, zip_uint16_t *ddate) {
- struct tm *tm;
+ struct tm *tpm;
- tm = localtime(&intime);
- if (tm == NULL) {
+#ifdef HAVE_LOCALTIME_R
+ struct tm tm;
+ tpm = localtime_r(&intime, &tm);
+#else
+ tpm = localtime(&intime);
+#endif
+ if (tpm == NULL) {
/* if localtime() fails, return an arbitrary date (1980-01-01 00:00:00) */
*ddate = (1 << 5) + 1;
*dtime = 0;
return;
}
- if (tm->tm_year < 80) {
- tm->tm_year = 80;
+ if (tpm->tm_year < 80) {
+ tpm->tm_year = 80;
}
- *ddate = (zip_uint16_t)(((tm->tm_year + 1900 - 1980) << 9) + ((tm->tm_mon + 1) << 5) + tm->tm_mday);
- *dtime = (zip_uint16_t)(((tm->tm_hour) << 11) + ((tm->tm_min) << 5) + ((tm->tm_sec) >> 1));
+ *ddate = (zip_uint16_t)(((tpm->tm_year + 1900 - 1980) << 9) + ((tpm->tm_mon + 1) << 5) + tpm->tm_mday);
+ *dtime = (zip_uint16_t)(((tpm->tm_hour) << 11) + ((tpm->tm_min) << 5) + ((tpm->tm_sec) >> 1));
return;
}
/*
zip_discard.c -- discard and free struct zip
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_entry.c -- struct zip_entry helper functions
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
#include "zipint.h"
-const char *const _zip_err_str[] = {
- "No error", "Multi-disk zip archives not supported", "Renaming temporary file failed", "Closing zip archive failed", "Seek error", "Read error", "Write error", "CRC error", "Containing zip archive was closed", "No such file", "File already exists", "Can't open file", "Failure to create temporary file", "Zlib error", "Malloc failure", "Entry has been changed", "Compression method not supported", "Premature end of file", "Invalid argument", "Not a zip archive", "Internal error", "Zip archive inconsistent", "Can't remove file", "Entry has been deleted", "Encryption method not supported", "Read-only archive", "No password provided", "Wrong password provided", "Operation not supported", "Resource still in use", "Tell error", "Compressed data invalid",
+const char * const _zip_err_str[] = {
+ "No error",
+ "Multi-disk zip archives not supported",
+ "Renaming temporary file failed",
+ "Closing zip archive failed",
+ "Seek error",
+ "Read error",
+ "Write error",
+ "CRC error",
+ "Containing zip archive was closed",
+ "No such file",
+ "File already exists",
+ "Can't open file",
+ "Failure to create temporary file",
+ "Zlib error",
+ "Malloc failure",
+ "Entry has been changed",
+ "Compression method not supported",
+ "Premature end of file",
+ "Invalid argument",
+ "Not a zip archive",
+ "Internal error",
+ "Zip archive inconsistent",
+ "Can't remove file",
+ "Entry has been deleted",
+ "Encryption method not supported",
+ "Read-only archive",
+ "No password provided",
+ "Wrong password provided",
+ "Operation not supported",
+ "Resource still in use",
+ "Tell error",
+ "Compressed data invalid",
+ "Operation cancelled",
};
-const int _zip_nerr_str = sizeof(_zip_err_str) / sizeof(_zip_err_str[0]);
+const int _zip_nerr_str = sizeof(_zip_err_str)/sizeof(_zip_err_str[0]);
#define N ZIP_ET_NONE
#define S ZIP_ET_SYS
#define Z ZIP_ET_ZLIB
const int _zip_err_type[] = {
- N, N, S, S, S, S, S, N, N, N, N, S, S, Z, N, N, N, N, N, N, N, N, S, N, N, N, N, N, N, N, S, N,
+ N,
+ N,
+ S,
+ S,
+ S,
+ S,
+ S,
+ N,
+ N,
+ N,
+ N,
+ S,
+ S,
+ Z,
+ N,
+ N,
+ N,
+ N,
+ N,
+ N,
+ N,
+ N,
+ S,
+ N,
+ N,
+ N,
+ N,
+ N,
+ N,
+ N,
+ S,
+ N,
+ N,
};
/*
zip_error.c -- zip_error_t helper functions
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_error_clear.c -- clear zip error
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_error_get.c -- get zip error
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_error_get_sys_type.c -- return type of system error code
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_error_sterror.c -- get string representation of struct zip_error
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_error_to_str.c -- get string representation of zip error code
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_extra_field.c -- manipulate extra fields
- Copyright (C) 2012-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2012-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_extra_field_api.c -- public extra fields API functions
- Copyright (C) 2012-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2012-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_fclose.c -- close file in zip archive
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_fdopen.c -- open read-only archive from file descriptor
- Copyright (C) 2009-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2009-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_file_add.c -- add file via callback function
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_file_error_clear.c -- clear zip file error
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_file_error_get.c -- get zip file error
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_file_get_comment.c -- get file comment
- Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_file_get_external_attributes.c -- get opsys/external attributes
- Copyright (C) 2013-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2013-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_file_get_offset.c -- get offset of file data in archive.
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_file_rename.c -- rename file in zip archive
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_file_replace.c -- replace file via callback function
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_file_set_comment.c -- set comment for file in archive
- Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_file_set_encryption.c -- set encryption for file in archive
- Copyright (C) 2016-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2016-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_file_set_external_attributes.c -- set external attributes for entry
- Copyright (C) 2013-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2013-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_file_set_mtime.c -- set modification time of entry.
- Copyright (C) 2014-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2020 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
#include "zipint.h"
ZIP_EXTERN int
+zip_file_set_dostime(zip_t *za, zip_uint64_t idx, zip_uint16_t dtime, zip_uint16_t ddate, zip_flags_t flags) {
+ time_t mtime;
+ mtime = _zip_d2u_time(dtime, ddate);
+ return zip_file_set_mtime(za, idx, mtime, flags);
+}
+
+ZIP_EXTERN int
zip_file_set_mtime(zip_t *za, zip_uint64_t idx, time_t mtime, zip_flags_t flags) {
zip_entry_t *e;
- int changed;
if (_zip_get_dirent(za, idx, 0, NULL) == NULL)
return -1;
e = za->entry + idx;
- changed = e->orig == NULL || mtime != e->orig->last_mod;
-
- if (changed) {
- if (e->changes == NULL) {
- if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
- zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
- return -1;
- }
- }
- e->changes->last_mod = mtime;
- e->changes->changed |= ZIP_DIRENT_LAST_MOD;
- }
- else {
- if (e->changes) {
- e->changes->changed &= ~ZIP_DIRENT_LAST_MOD;
- if (e->changes->changed == 0) {
- _zip_dirent_free(e->changes);
- e->changes = NULL;
- }
+ if (e->changes == NULL) {
+ if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
+ zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+ return -1;
}
}
+ e->changes->last_mod = mtime;
+ e->changes->changed |= ZIP_DIRENT_LAST_MOD;
+
return 0;
}
/*
zip_file_sterror.c -- get string representation of zip file error
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_filerange_crc.c -- compute CRC32 for a range of a file
- Copyright (C) 2008-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2008-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_fopen.c -- open file in zip archive for reading
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_fopen_encrypted.c -- open file for reading with password
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_fopen_index.c -- open file in zip archive for reading by index
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_fopen_index_encrypted.c -- open file for reading by index w/ password
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_fread.c -- read from file
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_fseek.c -- seek in file
- Copyright (C) 2016-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2016-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_ftell.c -- tell position in file
- Copyright (C) 2016-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2016-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_get_archive_comment.c -- get archive comment
- Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_get_archive_flag.c -- get archive global flag
- Copyright (C) 2008-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2008-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_get_encryption_implementation.c -- get encryption implementation
- Copyright (C) 2009-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2009-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_get_file_comment.c -- get file comment
- Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_get_name.c -- get filename for a file in zip file
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_get_num_entries.c -- get number of entries in archive
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_get_num_files.c -- get number of files in archive
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_hash.c -- hash table string -> uint64
- Copyright (C) 2015-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2015-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_io_util.c -- I/O helper functions
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_libzip_version.c -- return run-time version of library
- Copyright (C) 2017-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2017-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_memdup.c -- internal zip function, "strdup" with len
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
--- /dev/null
+/*
+ zip_mkstempm.c -- mkstemp replacement that accepts a mode argument
+ Copyright (C) 2019 Dieter Baron and Thomas Klausner
+
+ This file is part of libzip, a library to manipulate ZIP archives.
+ The authors can be contacted at <libzip@nih.at>
+
+ 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 <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "zipint.h"
+
+/*
+ * create temporary file with same permissions as previous one;
+ * or default permissions if there is no previous file
+ */
+int
+_zip_mkstempm(char *path, int mode) {
+ int fd;
+ char *start, *end, *xs;
+
+ int xcnt = 0;
+
+ end = path + strlen(path);
+ start = end - 1;
+ while (start >= path && *start == 'X') {
+ xcnt++;
+ start--;
+ }
+
+ if (xcnt == 0) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ start++;
+
+ for (;;) {
+ zip_uint32_t value = zip_random_uint32();
+
+ xs = start;
+
+ while (xs < end) {
+ char digit = value % 36;
+ if (digit < 10) {
+ *(xs++) = digit + '0';
+ }
+ else {
+ *(xs++) = digit - 10 + 'a';
+ }
+ value /= 36;
+ }
+
+ if ((fd = open(path, O_CREAT | O_EXCL | O_RDWR | O_CLOEXEC, mode == -1 ? 0666 : (mode_t)mode)) >= 0) {
+ if (mode != -1) {
+ /* open() honors umask(), which we don't want in this case */
+ (void)chmod(path, (mode_t)mode);
+ }
+ return fd;
+ }
+ if (errno != EEXIST) {
+ return -1;
+ }
+ }
+}
/*
zip_name_locate.c -- get index by name
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_new.c -- create and init struct zip
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_open.c -- open zip archive by name
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
typedef enum {
EXISTS_ERROR = -1,
EXISTS_NOT = 0,
- EXISTS_EMPTY,
- EXISTS_NONEMPTY,
+ EXISTS_OK
} exists_t;
static zip_t *_zip_allocate_new(zip_source_t *src, unsigned int flags, zip_error_t *error);
static zip_int64_t _zip_checkcons(zip_t *za, zip_cdir_t *cdir, zip_error_t *error);
}
len = st.size;
- /* treat empty files as empty archives */
- if (len == 0) {
- if ((za = _zip_allocate_new(src, flags, error)) == NULL) {
- return NULL;
- }
-
- return za;
- }
if ((za = _zip_allocate_new(src, flags, error)) == NULL) {
return NULL;
}
+ /* treat empty files as empty archives */
+ if (len == 0 && zip_source_accept_empty(src)) {
+ return za;
+ }
+
if ((cdir = _zip_find_central_dir(za, len)) == NULL) {
_zip_error_copy(error, &za->error);
/* keep src so discard does not get rid of it */
return EXISTS_ERROR;
}
- return (st.valid & ZIP_STAT_SIZE) && st.size == 0 ? EXISTS_EMPTY : EXISTS_NONEMPTY;
+ return EXISTS_OK;
}
eocd_disk = _zip_buffer_get_16(buffer);
eocd_offset = _zip_buffer_get_64(buffer);
- if (eocd_offset > ZIP_INT64_MAX || eocd_offset + EOCD64LEN < eocd_offset) {
+ /* valid seek value for start of EOCD */
+ if (eocd_offset > ZIP_INT64_MAX) {
zip_error_set(error, ZIP_ER_SEEK, EFBIG);
return NULL;
}
+ /* does EOCD fit before EOCD locator? */
if (eocd_offset + EOCD64LEN > eocdloc_offset + buf_offset) {
zip_error_set(error, ZIP_ER_INCONS, 0);
return NULL;
}
+ /* make sure current position of buffer is beginning of EOCD */
if (eocd_offset >= buf_offset && eocd_offset + EOCD64LEN <= buf_offset + _zip_buffer_size(buffer)) {
_zip_buffer_set_offset(buffer, eocd_offset - buf_offset);
free_buffer = false;
return NULL;
}
+ /* size of EOCD */
size = _zip_buffer_get_64(buffer);
+ /* is there a hole between EOCD and EOCD locator, or do they overlap? */
if ((flags & ZIP_CHECKCONS) && size + eocd_offset + 12 != buf_offset + eocdloc_offset) {
zip_error_set(error, ZIP_ER_INCONS, 0);
if (free_buffer) {
size = _zip_buffer_get_64(buffer);
offset = _zip_buffer_get_64(buffer);
+ /* did we read past the end of the buffer? */
if (!_zip_buffer_ok(buffer)) {
zip_error_set(error, ZIP_ER_INTERNAL, 0);
if (free_buffer) {
return NULL;
}
+ if (nentry > size / CDENTRYSIZE) {
+ zip_error_set(error, ZIP_ER_INCONS, 0);
+ return NULL;
+ }
+
if ((cd = _zip_cdir_new(nentry, error)) == NULL)
return NULL;
/*
zip_progress.c -- progress reporting
- Copyright (C) 2017-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2017-2020 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
struct zip_progress {
zip_t *za;
- zip_progress_callback callback;
- void (*ud_free)(void *);
- void *ud;
+ zip_progress_callback callback_progress;
+ void (*ud_progress_free)(void *);
+ void *ud_progress;
+
+ zip_cancel_callback callback_cancel;
+ void (*ud_cancel_free)(void *);
+ void *ud_cancel;
double precision;
double end; /* end of sub-progress section */
};
+static void _zip_progress_free_cancel_callback(zip_progress_t *progress);
+static void _zip_progress_free_progress_callback(zip_progress_t *progress);
+static zip_progress_t *_zip_progress_new(zip_t *za);
+static void _zip_progress_set_cancel_callback(zip_progress_t *progress, zip_cancel_callback callback, void (*ud_free)(void *), void *ud);
+static void _zip_progress_set_progress_callback(zip_progress_t *progress, double precision, zip_progress_callback callback, void (*ud_free)(void *), void *ud);
void
_zip_progress_end(zip_progress_t *progress) {
return;
}
- if (progress->ud_free) {
- progress->ud_free(progress->ud);
- }
+ _zip_progress_free_progress_callback(progress);
+ _zip_progress_free_cancel_callback(progress);
free(progress);
}
-zip_progress_t *
-_zip_progress_new(zip_t *za, double precision, zip_progress_callback callback, void (*ud_free)(void *), void *ud) {
+static zip_progress_t *
+_zip_progress_new(zip_t *za) {
zip_progress_t *progress = (zip_progress_t *)malloc(sizeof(*progress));
if (progress == NULL) {
}
progress->za = za;
- progress->callback = callback;
- progress->ud_free = ud_free;
- progress->ud = ud;
- progress->precision = precision;
+
+ progress->callback_progress = NULL;
+ progress->ud_progress_free = NULL;
+ progress->ud_progress = NULL;
+ progress->precision = 0.0;
+
+ progress->callback_cancel = NULL;
+ progress->ud_cancel_free = NULL;
+ progress->ud_cancel = NULL;
return progress;
}
+static void
+_zip_progress_free_progress_callback(zip_progress_t *progress) {
+ if (progress->ud_progress_free) {
+ progress->ud_progress_free(progress->ud_progress);
+ }
+
+ progress->callback_progress = NULL;
+ progress->ud_progress = NULL;
+ progress->ud_progress_free = NULL;
+}
+
+static void
+_zip_progress_free_cancel_callback(zip_progress_t *progress) {
+ if (progress->ud_cancel_free) {
+ progress->ud_cancel_free(progress->ud_cancel);
+ }
+
+ progress->callback_cancel = NULL;
+ progress->ud_cancel = NULL;
+ progress->ud_cancel_free = NULL;
+}
+
+static void
+_zip_progress_set_progress_callback(zip_progress_t *progress, double precision, zip_progress_callback callback, void (*ud_free)(void *), void *ud) {
+ _zip_progress_free_progress_callback(progress);
+
+ progress->callback_progress = callback;
+ progress->ud_progress_free = ud_free;
+ progress->ud_progress = ud;
+ progress->precision = precision;
+}
void
+_zip_progress_set_cancel_callback(zip_progress_t *progress, zip_cancel_callback callback, void (*ud_free)(void *), void *ud) {
+ _zip_progress_free_cancel_callback(progress);
+
+ progress->callback_cancel = callback;
+ progress->ud_cancel_free = ud_free;
+ progress->ud_cancel = ud;
+}
+
+int
_zip_progress_start(zip_progress_t *progress) {
if (progress == NULL) {
- return;
+ return 0;
+ }
+
+ if (progress->callback_progress != NULL) {
+ progress->last_update = 0.0;
+ progress->callback_progress(progress->za, 0.0, progress->ud_progress);
+ }
+
+ if (progress->callback_cancel != NULL) {
+ if (progress->callback_cancel(progress->za, progress->ud_cancel)) {
+ return -1;
+ }
}
- progress->last_update = 0.0;
- progress->callback(progress->za, 0.0, progress->ud);
+ return 0;
}
-void
+int
_zip_progress_subrange(zip_progress_t *progress, double start, double end) {
if (progress == NULL) {
- return;
+ return 0;
}
progress->start = start;
progress->end = end;
- _zip_progress_update(progress, 0.0);
+ return _zip_progress_update(progress, 0.0);
}
-void
+int
_zip_progress_update(zip_progress_t *progress, double sub_current) {
double current;
if (progress == NULL) {
- return;
+ return 0;
}
- current = ZIP_MIN(ZIP_MAX(sub_current, 0.0), 1.0) * (progress->end - progress->start) + progress->start;
+ if (progress->callback_progress != NULL) {
+ current = ZIP_MIN(ZIP_MAX(sub_current, 0.0), 1.0) * (progress->end - progress->start) + progress->start;
- if (current - progress->last_update > progress->precision) {
- progress->callback(progress->za, current, progress->ud);
- progress->last_update = current;
+ if (current - progress->last_update > progress->precision) {
+ progress->callback_progress(progress->za, current, progress->ud_progress);
+ progress->last_update = current;
+ }
}
+
+ if (progress->callback_cancel != NULL) {
+ if (progress->callback_cancel(progress->za, progress->ud_cancel)) {
+ return -1;
+ }
+ }
+
+ return 0;
}
zip_progress_t *progress = NULL;
if (callback != NULL) {
- if ((progress = _zip_progress_new(za, precision, callback, ud_free, ud)) == NULL) {
- return -1;
+ if (za->progress == NULL) {
+ if ((za->progress = _zip_progress_new(za)) == NULL) {
+ return -1;
+ }
}
+
+ _zip_progress_set_progress_callback(za->progress, precision, callback, ud_free, ud);
}
+ else {
+ if (za->progress != NULL) {
+ if (za->progress->callback_cancel == NULL) {
+ _zip_progress_free(za->progress);
+ za->progress = NULL;
+ }
+ else {
+ _zip_progress_free_progress_callback(za->progress);
+ }
+ }
+ }
+
+ return 0;
+}
+
+
+ZIP_EXTERN int
+zip_register_cancel_callback_with_state(zip_t *za, zip_cancel_callback callback, void (*ud_free)(void *), void *ud) {
+ zip_progress_t *progress = NULL;
+
+ if (callback != NULL) {
+ if (za->progress == NULL) {
+ if ((za->progress = _zip_progress_new(za)) == NULL) {
+ return -1;
+ }
+ }
- _zip_progress_free(za->progress);
- za->progress = progress;
+ _zip_progress_set_cancel_callback(za->progress, callback, ud_free, ud);
+ }
+ else {
+ if (za->progress != NULL) {
+ if (za->progress->callback_progress == NULL) {
+ _zip_progress_free(za->progress);
+ za->progress = NULL;
+ }
+ else {
+ _zip_progress_free_cancel_callback(za->progress);
+ }
+ }
+ }
return 0;
}
/*
zip_random_unix.c -- fill the user's buffer with random stuff (Unix version)
- Copyright (C) 2016-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2016-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
#include "zipint.h"
+#ifdef HAVE_CRYPTO
+#include "zip_crypto.h"
+#endif
+
+
+#ifdef HAVE_ARC4RANDOM
+
+#include <stdlib.h>
+
+#ifndef HAVE_SECURE_RANDOM
+ZIP_EXTERN bool
+zip_secure_random(zip_uint8_t *buffer, zip_uint16_t length) {
+ arc4random_buf(buffer, length);
+ return true;
+}
+#endif
+
+#ifndef HAVE_RANDOM_UINT32
+zip_uint32_t
+zip_random_uint32(void) {
+ return arc4random();
+}
+#endif
+
+#else /* HAVE_ARC4RANDOM */
+
+#ifndef HAVE_SECURE_RANDOM
#include <fcntl.h>
#include <unistd.h>
ZIP_EXTERN bool
-zip_random(zip_uint8_t *buffer, zip_uint16_t length) {
+zip_secure_random(zip_uint8_t *buffer, zip_uint16_t length) {
int fd;
if ((fd = open("/dev/urandom", O_RDONLY)) < 0) {
close(fd);
return true;
}
+#endif
+
+#ifndef HAVE_RANDOM_UINT32
+#include <stdlib.h>
+
+zip_uint32_t
+zip_random_uint32(void) {
+ static bool seeded = false;
+
+ zip_uint32_t value;
+
+ if (zip_secure_random((zip_uint8_t *)&value, sizeof(value))) {
+ return value;
+ }
+
+ if (!seeded) {
+ srandom((unsigned int)time(NULL));
+ }
+
+ return (zip_uint32_t)random();
+}
+#endif
+
+#endif /* HAVE_ARC4RANDOM */
/*
zip_random_uwp.c -- fill the user's buffer with random stuff (UWP version)
- Copyright (C) 2017-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2017-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "zipint.h"
+
+#ifdef HAVE_CRYPTO
+#include "zip_crypto.h"
+#endif
+
+#ifndef HAVE_SECURE_RANDOM
+
#include <bcrypt.h>
#include <ntstatus.h>
#include <windows.h>
-#include "zipint.h"
#include "zipwin32.h"
ZIP_EXTERN bool
-zip_random(zip_uint8_t *buffer, zip_uint16_t length) {
+zip_secure_random(zip_uint8_t *buffer, zip_uint16_t length) {
BCRYPT_ALG_HANDLE hAlg = NULL;
NTSTATUS hr = BCryptOpenAlgorithmProvider(&hAlg, BCRYPT_RNG_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
if (hr != STATUS_SUCCESS || hAlg == NULL) {
}
return true;
}
+
+#endif
+
+#ifndef HAVE_RANDOM_UINT32
+#include <stdlib.h>
+
+zip_uint32_t
+zip_random_uint32(void) {
+ static bool seeded = false;
+
+ zip_uint32_t value;
+
+ if (zip_secure_random((zip_uint8_t *)&value, sizeof(value))) {
+ return value;
+ }
+
+ if (!seeded) {
+ srandom((unsigned int)time(NULL));
+ }
+
+ return (zip_uint32_t)random();
+}
+#endif
/*
zip_random_win32.c -- fill the user's buffer with random stuff (Windows version)
- Copyright (C) 2016-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2016-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
#include "zipint.h"
#include "zipwin32.h"
+#ifdef HAVE_CRYPTO
+#include "zip_crypto.h"
+#endif
+
+#ifndef HAVE_SECURE_RANDOM
+
#include <wincrypt.h>
ZIP_EXTERN bool
-zip_random(zip_uint8_t *buffer, zip_uint16_t length) {
+zip_secure_random(zip_uint8_t *buffer, zip_uint16_t length) {
HCRYPTPROV hprov;
if (!CryptAcquireContext(&hprov, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
return false;
}
return true;
}
+#endif
+
+#ifndef HAVE_RANDOM_UINT32
+#include <stdlib.h>
+
+zip_uint32_t
+zip_random_uint32(void) {
+ static bool seeded = false;
+
+ zip_uint32_t value;
+
+ if (zip_secure_random((zip_uint8_t *)&value, sizeof(value))) {
+ return value;
+ }
+
+ if (!seeded) {
+ srandom((unsigned int)time(NULL));
+ }
+
+ return (zip_uint32_t)random();
+}
+#endif
/*
zip_rename.c -- rename file in zip archive
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_replace.c -- replace file via callback function
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_set_archive_comment.c -- set archive comment
- Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_get_archive_flag.c -- set archive global flag
- Copyright (C) 2008-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2008-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_set_default_password.c -- set default password for decryption
- Copyright (C) 2009-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2009-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_set_file_comment.c -- set comment for file in archive
- Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_set_file_compression.c -- set compression for file in archive
- Copyright (C) 2012-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2012-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_set_name.c -- rename helper function
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
--- /dev/null
+/*
+ zip_source_accept_empty.c -- if empty source is a valid archive
+ Copyright (C) 2019 Dieter Baron and Thomas Klausner
+
+ This file is part of libzip, a library to manipulate ZIP archives.
+ The authors can be contacted at <libzip@nih.at>
+
+ 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"
+
+
+bool
+zip_source_accept_empty(zip_source_t *src) {
+ int ret;
+
+ if ((zip_source_supports(src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ACCEPT_EMPTY)) == 0) {
+ if (ZIP_SOURCE_IS_LAYERED(src)) {
+ return zip_source_accept_empty(src->src);
+ }
+ return true;
+ }
+
+ ret = (int)_zip_source_call(src, NULL, 0, ZIP_SOURCE_ACCEPT_EMPTY);
+
+ return ret != 0;
+}
/*
zip_source_begin_write.c -- start a new file for writing
- Copyright (C) 2014-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_begin_write_cloning.c -- clone part of file for writing
- Copyright (C) 2017-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2017-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_buffer.c -- create zip data source from buffer
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
zip_source_buffer_create(const void *data, zip_uint64_t len, int freep, zip_error_t *error) {
zip_buffer_fragment_t fragment;
- if (data == NULL && len > 0) {
- zip_error_set(error, ZIP_ER_INVAL, 0);
- return NULL;
+ if (data == NULL) {
+ if (len > 0) {
+ zip_error_set(error, ZIP_ER_INVAL, 0);
+ return NULL;
+ }
+
+ return zip_source_buffer_fragment_create(NULL, 0, freep, error);
}
fragment.data = (zip_uint8_t *)data;
}
buffer->nfragments = j;
buffer->first_owned_fragment = free_data ? 0 : buffer->nfragments;
- buffer->fragment_offsets[nfragments] = offset;
+ buffer->fragment_offsets[buffer->nfragments] = offset;
buffer->size = offset;
}
/*
zip_source_call.c -- invoke callback command on zip_source
- Copyright (C) 2009-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2009-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_close.c -- close zip_source (stop reading)
- Copyright (C) 2009-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2009-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_commit_write.c -- commit changes to file
- Copyright (C) 2014-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_compress.c -- (de)compression routines
- Copyright (C) 2017-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2017-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
#if defined(HAVE_LIBBZ2)
{ZIP_CM_BZIP2, &zip_algorithm_bzip2_compress, &zip_algorithm_bzip2_decompress},
#endif
+#if defined(HAVE_LIBLZMA)
+/* Disabled - because 7z isn't able to unpack ZIP+LZMA ZIP+LZMA2
+ archives made this way - and vice versa.
+
+ {ZIP_CM_LZMA, &zip_algorithm_xz_compress, &zip_algorithm_xz_decompress},
+ {ZIP_CM_LZMA2, &zip_algorithm_xz_compress, &zip_algorithm_xz_decompress},
+*/
+ {ZIP_CM_XZ, &zip_algorithm_xz_compress, &zip_algorithm_xz_decompress},
+#endif
+
};
static size_t implementations_size = sizeof(implementations) / sizeof(implementations[0]);
/*
zip_source_crc.c -- pass-through source that calculates CRC32 and size
- Copyright (C) 2009-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2009-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_error.c -- get last error from zip_source
- Copyright (C) 2009-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2009-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_file.c -- create data source from file
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CAN_CLONE
#endif
-#ifdef _WIN32
-/* WIN32 needs <fcntl.h> for _O_BINARY */
-#include <fcntl.h>
-#endif
-
-/* Windows sys/types.h does not provide these */
-#ifndef S_ISREG
-#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
-#endif
-#if defined(S_IXUSR) && defined(S_IRWXG) && defined(S_IRWXO)
-#define _SAFE_MASK (S_IXUSR | S_IRWXG | S_IRWXO)
-#elif defined(_S_IWRITE)
-#define _SAFE_MASK (_S_IWRITE)
-#else
-#error do not know safe values for umask, please report this
-#endif
-
-#ifdef _MSC_VER
-/* MSVC doesn't have mode_t */
-typedef int mode_t;
-#endif
-
struct read_file {
zip_error_t error; /* last error information */
zip_int64_t supports;
#ifdef CAN_CLONE
static zip_int64_t create_temp_output_cloning(struct read_file *ctx, zip_uint64_t offset);
#endif
+static FILE *_zip_fopen(const char *name, bool writeable);
static int _zip_fseek_u(FILE *f, zip_uint64_t offset, int whence, zip_error_t *error);
static int _zip_fseek(FILE *f, zip_int64_t offset, int whence, zip_error_t *error);
}
}
+ ctx->supports |= ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ACCEPT_EMPTY);
#ifdef CAN_CLONE
if (ctx->supports & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE)) {
ctx->supports |= ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE_CLONING);
create_temp_output(struct read_file *ctx) {
char *temp;
int tfd;
- mode_t mask;
+ int mode;
FILE *tfp;
+ struct stat st;
if ((temp = (char *)malloc(strlen(ctx->fname) + 8)) == NULL) {
zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0);
return -1;
}
+
+ if (stat(ctx->fname, &st) == 0) {
+ mode = st.st_mode;
+ }
+ else {
+ mode = -1;
+ }
+
sprintf(temp, "%s.XXXXXX", ctx->fname);
- mask = umask(_SAFE_MASK);
- if ((tfd = mkstemp(temp)) == -1) {
+ if ((tfd = _zip_mkstempm(temp, mode)) == -1) {
zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
- umask(mask);
free(temp);
return -1;
}
- umask(mask);
if ((tfp = fdopen(tfd, "r+b")) == NULL) {
zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
return -1;
}
-#ifdef _WIN32
- /*
- According to Pierre Joye, Windows in some environments per
- default creates text files, so force binary mode.
- */
- _setmode(_fileno(tfp), _O_BINARY);
-#endif
-
ctx->fout = tfp;
ctx->tmpname = temp;
free(temp);
return -1;
}
- if ((tfp = fopen(temp, "r+b")) == NULL) {
+ if ((tfp = _zip_fopen(temp, true)) == NULL) {
zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
(void)remove(temp);
free(temp);
buf = (char *)data;
switch (cmd) {
+ case ZIP_SOURCE_ACCEPT_EMPTY:
+ return 0;
+
case ZIP_SOURCE_BEGIN_WRITE:
+#ifdef _WIN32
+ return -1;
+#else
if (ctx->fname == NULL) {
zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
return -1;
}
return create_temp_output(ctx);
+#endif
#ifdef CAN_CLONE
case ZIP_SOURCE_BEGIN_WRITE_CLONING:
return create_temp_output_cloning(ctx, len);
#endif
- case ZIP_SOURCE_COMMIT_WRITE: {
- mode_t mode;
- struct stat st;
+ case ZIP_SOURCE_CLOSE:
+ if (ctx->fname) {
+ fclose(ctx->f);
+ ctx->f = NULL;
+ }
+ return 0;
+ case ZIP_SOURCE_COMMIT_WRITE: {
if (fclose(ctx->fout) < 0) {
ctx->fout = NULL;
zip_error_set(&ctx->error, ZIP_ER_WRITE, errno);
}
ctx->fout = NULL;
- if (stat(ctx->fname, &st) == 0) {
- mode = st.st_mode;
- } else {
- mode_t mask = umask(022);
- umask(mask);
- mode = 0666 & ~mask;
- }
if (rename(ctx->tmpname, ctx->fname) < 0) {
zip_error_set(&ctx->error, ZIP_ER_RENAME, errno);
return -1;
}
- /* not much we can do if chmod fails except make the whole commit fail */
- (void)chmod(ctx->fname, mode);
free(ctx->tmpname);
ctx->tmpname = NULL;
return 0;
}
- case ZIP_SOURCE_CLOSE:
- if (ctx->fname) {
- fclose(ctx->f);
- ctx->f = NULL;
- }
- return 0;
-
case ZIP_SOURCE_ERROR:
return zip_error_to_data(&ctx->error, data, len);
case ZIP_SOURCE_OPEN:
if (ctx->fname) {
- if ((ctx->f = fopen(ctx->fname, "rb")) == NULL) {
+ if ((ctx->f = _zip_fopen(ctx->fname, false)) == NULL) {
zip_error_set(&ctx->error, ZIP_ER_OPEN, errno);
return -1;
}
}
return 0;
}
+
+
+/*
+ * fopen replacement that sets the close-on-exec flag
+ * some implementations support an fopen 'e' flag for that,
+ * but e.g. macOS doesn't.
+ */
+static FILE *
+_zip_fopen(const char *name, bool writeable)
+{
+ int fd;
+ int flags;
+ FILE *fp;
+
+ flags = O_CLOEXEC;
+ if (writeable) {
+ flags |= O_RDWR;
+ }
+ else {
+ flags |= O_RDONLY;
+ }
+
+ /* mode argument needed on Windows */
+ if ((fd = open(name, flags, 0666)) < 0) {
+ return NULL;
+ }
+ if ((fp = fdopen(fd, writeable ? "r+b" : "rb")) == NULL) {
+ return NULL;
+ }
+ return fp;
+}
/*
zip_source_free.c -- free zip data source
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_function.c -- create zip data source from callback function
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_get_compression_flags.c -- get compression flags for entry
- Copyright (C) 2017-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2017-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_is_deleted.c -- was archive was removed?
- Copyright (C) 2014-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_layered.c -- create layered source
- Copyright (C) 2009-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2009-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_open.c -- open zip_source (prepare for reading)
- Copyright (C) 2009-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2009-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_pkware.c -- Traditional PKWARE de/encryption routines
- Copyright (C) 2009-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2009-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_read.c -- read data from zip_source
- Copyright (C) 2009-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2009-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_remove.c -- remove empty archive
- Copyright (C) 2014-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_rollback_write.c -- discard changes
- Copyright (C) 2014-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_seek.c -- seek to offset
- Copyright (C) 2014-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_seek_write.c -- seek to offset for writing
- Copyright (C) 2014-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_stat.c -- get meta information from zip_source
- Copyright (C) 2009-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2009-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_supports.c -- check for supported functions
- Copyright (C) 2014-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_tell.c -- report current offset
- Copyright (C) 2014-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_tell_write.c -- report current offset for writing
- Copyright (C) 2014-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_win32a.c -- create data source from Windows file (ANSI)
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
static int
_win32_rename_temp_a(_zip_source_win32_read_file_t *ctx) {
+ DWORD attributes = GetFileAttributesA(ctx->tmpname);
+ if (INVALID_FILE_ATTRIBUTES == attributes)
+ return -1;
+
+ if (FILE_ATTRIBUTE_TEMPORARY & attributes) {
+ if (!SetFileAttributesA(ctx->tmpname, attributes & ~FILE_ATTRIBUTE_TEMPORARY))
+ return -1;
+ }
+
if (!MoveFileExA(ctx->tmpname, ctx->fname, MOVEFILE_REPLACE_EXISTING))
return -1;
+
return 0;
}
/*
zip_source_win32file.c -- create data source from HANDLE (Win32)
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
ctx->supports = ZIP_SOURCE_SUPPORTS_SEEKABLE;
}
+ ctx->supports |= ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ACCEPT_EMPTY);
+
if ((zs = zip_source_function_create(_win32_read_file, ctx, error)) == NULL) {
free(ctx->fname);
free(ctx);
buf = (char *)data;
switch (cmd) {
+ case ZIP_SOURCE_ACCEPT_EMPTY:
+ return 0;
+
case ZIP_SOURCE_BEGIN_WRITE:
if (ctx->fname == NULL) {
zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
switch (args->whence) {
case SEEK_SET:
- new_current = args->offset;
+ new_current = args->offset + ctx->start;
break;
case SEEK_END:
/*
zip_source_win32utf8.c -- create data source from Windows file (UTF-8)
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_win32w.c -- create data source from Windows file (UTF-16)
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
static int
_win32_rename_temp_w(_zip_source_win32_read_file_t *ctx) {
+ DWORD attributes = GetFileAttributesW(ctx->tmpname);
+ if (INVALID_FILE_ATTRIBUTES == attributes)
+ return -1;
+
+ if (FILE_ATTRIBUTE_TEMPORARY & attributes) {
+ if (!SetFileAttributesW(ctx->tmpname, attributes & ~FILE_ATTRIBUTE_TEMPORARY))
+ return -1;
+ }
+
if (!MoveFileExW(ctx->tmpname, ctx->fname, MOVEFILE_REPLACE_EXISTING))
return -1;
+
return 0;
}
/*
zip_source_window.c -- return part of lower source
- Copyright (C) 2012-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2012-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_winzip_aes_decode.c -- Winzip AES decryption routines
- Copyright (C) 2009-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2009-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
static int
encrypt_header(zip_source_t *src, struct winzip_aes *ctx) {
zip_uint16_t salt_length = SALT_LENGTH(ctx->encryption_method);
- if (!zip_random(ctx->data, salt_length)) {
+ if (!zip_secure_random(ctx->data, salt_length)) {
zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
return -1;
}
/* TODO: return partial read? */
return -1;
}
- buffer_n += _zip_buffer_read(ctx->buffer, data + ret, length - (zip_uint64_t)ret);
+ buffer_n += _zip_buffer_read(ctx->buffer, (zip_uint8_t *)data + ret, length - (zip_uint64_t)ret);
}
return (zip_int64_t)(buffer_n + (zip_uint64_t)ret);
/*
zip_source_write.c -- start a new file for writing
- Copyright (C) 2014-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_zip.c -- create data source from zip file
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_source_zip_new.c -- prepare data structures for zip_fopen/zip_source_zip
- Copyright (C) 2012-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2012-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_stat.c -- get information about file by name
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_stat_index.c -- get information about file by index
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2020 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
if ((flags & ZIP_FL_UNCHANGED) == 0 && ZIP_ENTRY_DATA_CHANGED(za->entry + index)) {
- if (zip_source_stat(za->entry[index].source, st) < 0) {
+ zip_entry_t *entry = za->entry+index;
+
+ if (zip_source_stat(entry->source, st) < 0) {
zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
return -1;
}
+
+ if (entry->changes->changed & ZIP_DIRENT_LAST_MOD) {
+ st->mtime = de->last_mod;
+ st->valid |= ZIP_STAT_MTIME;
+ }
}
else {
zip_stat_init(st);
/*
zip_stat_init.c -- initialize struct zip_stat.
- Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_sterror.c -- get string representation of zip error
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_string.c -- string handling (with encoding)
- Copyright (C) 2012-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2012-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_unchange.c -- undo changes to file in zip archive
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_unchange.c -- undo changes to all files in zip archive
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_unchange_archive.c -- undo global changes to ZIP archive
- Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_unchange_data.c -- undo helper function
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_utf-8.c -- UTF-8 support functions for libzip
- Copyright (C) 2011-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2011-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zip_winzip_aes.c -- Winzip AES de/encryption backend routines
- Copyright (C) 2017-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2017-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zipint.h -- internal declarations.
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2020 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
extern zip_compression_algorithm_t zip_algorithm_bzip2_decompress;
extern zip_compression_algorithm_t zip_algorithm_deflate_compress;
extern zip_compression_algorithm_t zip_algorithm_deflate_decompress;
+extern zip_compression_algorithm_t zip_algorithm_xz_compress;
+extern zip_compression_algorithm_t zip_algorithm_xz_decompress;
+
bool zip_compression_method_supported(zip_int32_t method, bool compress);
bool _zip_cdir_grow(zip_cdir_t *cd, zip_uint64_t additional_entries, zip_error_t *error);
zip_cdir_t *_zip_cdir_new(zip_uint64_t, zip_error_t *);
zip_int64_t _zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivors);
+time_t _zip_d2u_time(zip_uint16_t, zip_uint16_t);
void _zip_deregister_source(zip_t *za, zip_source_t *src);
zip_dirent_t *_zip_dirent_clone(const zip_dirent_t *);
bool _zip_hash_reserve_capacity(zip_hash_t *hash, zip_uint64_t capacity, zip_error_t *error);
bool _zip_hash_revert(zip_hash_t *hash, zip_error_t *error);
+int _zip_mkstempm(char *path, int mode);
+
zip_t *_zip_open(zip_source_t *, unsigned int, zip_error_t *);
void _zip_progress_end(zip_progress_t *progress);
void _zip_progress_free(zip_progress_t *progress);
-zip_progress_t *_zip_progress_new(zip_t *za, double precision, zip_progress_callback callback, void (*ud_free)(void *), void *ud);
-void _zip_progress_start(zip_progress_t *progress);
-void _zip_progress_subrange(zip_progress_t *progress, double start, double end);
-void _zip_progress_update(zip_progress_t *progress, double value);
+int _zip_progress_start(zip_progress_t *progress);
+int _zip_progress_subrange(zip_progress_t *progress, double start, double end);
+int _zip_progress_update(zip_progress_t *progress, double value);
-ZIP_EXTERN bool zip_random(zip_uint8_t *buffer, zip_uint16_t length);
+/* this symbol is extern so it can be overridden for regression testing */
+ZIP_EXTERN bool zip_secure_random(zip_uint8_t *buffer, zip_uint16_t length);
+zip_uint32_t zip_random_uint32(void);
int _zip_read(zip_source_t *src, zip_uint8_t *data, zip_uint64_t length, zip_error_t *error);
int _zip_read_at_offset(zip_source_t *src, zip_uint64_t offset, unsigned char *b, size_t length, zip_error_t *error);
void _zip_set_open_error(int *zep, const zip_error_t *err, int ze);
+bool zip_source_accept_empty(zip_source_t *src);
zip_int64_t _zip_source_call(zip_source_t *src, void *data, zip_uint64_t length, zip_source_cmd_t command);
bool _zip_source_eof(zip_source_t *);
zip_source_t *_zip_source_file_or_p(const char *, FILE *, zip_uint64_t, zip_int64_t, const zip_stat_t *, zip_error_t *error);
/*
zipwin32.h -- internal declarations for Windows.
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
libzip.mdoc -- general overview of available functions
- Copyright (C) 2005-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2005-2020 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<li><a class="Xr" href="zip_file_add.html">zip_file_add(3)</a></li>
<li><a class="Xr" href="zip_file_replace.html">zip_file_replace(3)</a></li>
<li><a class="Xr" href="zip_file_set_comment.html">zip_file_set_comment(3)</a></li>
+ <li><a class="Xr" href="zip_file_set_dostime.html">zip_file_set_dostime(3)</a></li>
<li><a class="Xr" href="zip_file_set_external_attributes.html">zip_file_set_external_attributes(3)</a></li>
<li><a class="Xr" href="zip_file_set_encryption.html">zip_file_set_encryption(3)</a></li>
<li><a class="Xr" href="zip_file_set_mtime.html">zip_file_set_mtime(3)</a></li>
</div>
<table class="foot">
<tr>
- <td class="foot-date">September 29, 2018</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-date">January 7, 2020</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" libzip.mdoc -- general overview of available functions
-.\" Copyright (C) 2005-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2005-2020 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "LIBZIP" "3" "September 29, 2018" "NiH" "Library Functions Manual"
+.TH "LIBZIP" "3" "January 7, 2020" "NiH" "Library Functions Manual"
.nh
.if n .ad l
.SH "NAME"
zip_file_set_comment(3)
.TP 4n
\fB\(bu\fR
+zip_file_set_dostime(3)
+.TP 4n
+\fB\(bu\fR
zip_file_set_external_attributes(3)
.TP 4n
\fB\(bu\fR
.\" libzip.mdoc -- general overview of available functions
-.\" Copyright (C) 2005-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2005-2020 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd September 29, 2018
+.Dd January 7, 2020
.Dt LIBZIP 3
.Os
.Sh NAME
.It
.Xr zip_file_set_comment 3
.It
+.Xr zip_file_set_dostime 3
+.It
.Xr zip_file_set_external_attributes 3
.It
.Xr zip_file_set_encryption 3
zip_file_extra_field_delete zip_file_extra_field_delete_by_id
zip_file_extra_field_get zip_file_extra_field_get_by_id
zip_file_extra_fields_count zip_file_extra_fields_count_by_id
+zip_file_set_mtime zip_file_set_dostime
zip_file_strerror zip_strerror
zip_fopen zip_fopen_index
zip_fopen_encrypted zip_fopen_index_encrypted
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_close.mdoc -- close zip archive
- Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
The <code class="Fn">zip_close</code>() function writes any changes made to
<var class="Ar">archive</var> to disk. If <var class="Ar">archive</var>
contains no files, the file is completely removed (no empty archive is
- written). If successful, <var class="Ar">archive</var> is freed. If writing
- fails, <code class="Fn">zip_close</code>() fails;
+ written). If successful, <var class="Ar">archive</var> is freed. Otherwise
<var class="Ar">archive</var> is left unchanged and must still be freed.
<p class="Pp">To close and free a zip archive without saving changes, use
<a class="Xr" href="zip_discard.html">zip_discard(3)</a>.</p>
</div>
<table class="foot">
<tr>
- <td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-date">September 17, 2019</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_close.mdoc -- close zip archive
-.\" Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "ZIP_CLOSE" "3" "December 18, 2017" "NiH" "Library Functions Manual"
+.TH "ZIP_CLOSE" "3" "September 17, 2019" "NiH" "Library Functions Manual"
.nh
.if n .ad l
.SH "NAME"
If successful,
\fIarchive\fR
is freed.
-If writing fails,
-\fBzip_close\fR()
-fails;
+Otherwise
\fIarchive\fR
is left unchanged and must still be freed.
.PP
.\" zip_close.mdoc -- close zip archive
-.\" Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd December 18, 2017
+.Dd September 17, 2019
.Dt ZIP_CLOSE 3
.Os
.Sh NAME
If successful,
.Ar archive
is freed.
-If writing fails,
-.Fn zip_close
-fails;
+Otherwise
.Ar archive
is left unchanged and must still be freed.
.Pp
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_dir_add.mdoc -- add directory to zip archive
- Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_dir_add.mdoc -- add directory to zip archive
-.\" Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_dir_add.mdoc -- add directory to zip archive
-.\" Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_error_clear.mdoc -- clear error state for archive or file
- Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_error_clear.mdoc -- clear error state for archive or file
-.\" Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_error_clear.mdoc -- clear error state for archive or file
-.\" Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_errors.mdoc -- list of all libzip error codes
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_errors.mdoc -- list of all libzip error codes
-.\" Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_errors.mdoc -- list of all libzip error codes
-.\" Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_fdopen.mdoc -- open zip archive using existing file descriptor
- Copyright (C) 2009-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2009-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_fdopen.mdoc -- open zip archive using existing file descriptor
-.\" Copyright (C) 2009-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2009-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_fdopen.mdoc -- open zip archive using existing file descriptor
-.\" Copyright (C) 2009-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2009-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_file_add.mdoc -- add files to zip archive
- Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_file_add.mdoc -- add files to zip archive
-.\" Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_file_add.mdoc -- add files to zip archive
-.\" Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_file_rename.mdoc -- rename file in zip archive
- Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_file_rename.mdoc -- rename file in zip archive
-.\" Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_file_rename.mdoc -- rename file in zip archive
-.\" Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_file_set_mtime.mdoc -- set mtime for file in zip
- Copyright (C) 2014-2017 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2020 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP files.
The authors can be contacted at <libzip@nih.at>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
-<code class="Nm">zip_file_set_mtime</code> —
+<code class="Nm">zip_file_set_dostime</code>,
+ <code class="Nm">zip_file_set_mtime</code> —
<div class="Nd">set last modification time (mtime) for file in zip</div>
</section>
<section class="Sh">
<code class="In">#include <<a class="In">zip.h</a>></code>
<p class="Pp"><var class="Ft">int</var>
<br/>
+ <code class="Fn">zip_file_set_dostime</code>(<var class="Fa" style="white-space: nowrap;">zip_t
+ *archive</var>, <var class="Fa" style="white-space: nowrap;">zip_uint64_t
+ index</var>, <var class="Fa" style="white-space: nowrap;">zip_uint16_t
+ dostime</var>, <var class="Fa" style="white-space: nowrap;">zip_uint16_t
+ dosdate</var>, <var class="Fa" style="white-space: nowrap;">zip_flags_t
+ flags</var>);</p>
+<p class="Pp"><var class="Ft">int</var>
+ <br/>
<code class="Fn">zip_file_set_mtime</code>(<var class="Fa" style="white-space: nowrap;">zip_t
*archive</var>, <var class="Fa" style="white-space: nowrap;">zip_uint64_t
index</var>, <var class="Fa" style="white-space: nowrap;">time_t
modification time (mtime) for the file at position <var class="Ar">index</var>
in the zip archive to <var class="Ar">mtime</var>. Currently, no support for
any <var class="Ar">flags</var> is implemented.
+<p class="Pp">In the zip archive, the time and date are saved as two 16-bit
+ integers. To set the values directly, call the
+ <code class="Fn">zip_file_set_dostime</code>() function. The values of the
+ time bytes are defined as follows:</p>
+<div class="Bd-indent">
+<dl class="Bl-tag">
+ <dt>0-4</dt>
+ <dd>day of the month (1-31)</dd>
+ <dt>5-8</dt>
+ <dd>month (January = 1, February = 2, ...)</dd>
+ <dt>9-15</dt>
+ <dd>year offset from 1980 (1980 = 0, 1981 = 1, ...)</dd>
+</dl>
+</div>
+<p class="Pp">The values of the date bytes are defined as follows:</p>
+<div class="Bd-indent">
+<dl class="Bl-tag">
+ <dt>0-4</dt>
+ <dd>seconds divided by two (1-2 = 1, 3-4 = 2, ...)</dd>
+ <dt>5-10</dt>
+ <dd>minute (0-59)</dd>
+ <dt>11-15</dt>
+ <dd>hour (0-23)</dd>
+</dl>
+</div>
</section>
<section class="Sh">
<h1 class="Sh" id="RETURN_VALUES"><a class="permalink" href="#RETURN_VALUES">RETURN
</section>
<section class="Sh">
<h1 class="Sh" id="ERRORS"><a class="permalink" href="#ERRORS">ERRORS</a></h1>
-<code class="Fn">zip_file_set_mtime</code>() fails if:
+<code class="Fn">zip_file_set_dostime</code>() and
+ <code class="Fn">zip_file_set_mtime</code>() fail if:
<dl class="Bl-tag">
<dt>[<a class="permalink" href="#ZIP_ER_INVAL"><code class="Er" id="ZIP_ER_INVAL">ZIP_ER_INVAL</code></a>]</dt>
<dd><var class="Ar">index</var> is not a valid file index in
<section class="Sh">
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
<code class="Fn">zip_file_set_mtime</code>() was added in libzip 1.0.
+ <code class="Fn">zip_file_set_dostime</code>() was added in libzip 1.6.
</section>
<section class="Sh">
<h1 class="Sh" id="AUTHORS"><a class="permalink" href="#AUTHORS">AUTHORS</a></h1>
<span class="An">Thomas Klausner</span>
<<a class="Mt" href="mailto:tk@giga.or.at">tk@giga.or.at</a>>
</section>
+<section class="Sh">
+<h1 class="Sh" id="CAVEATS"><a class="permalink" href="#CAVEATS">CAVEATS</a></h1>
+Following historical practice, the <code class="Fn">zip_file_set_mtime</code>()
+ function translates the time from the zip archive into the local time zone. If
+ you want to avoid this, use the <code class="Fn">zip_file_set_dostime</code>()
+ function instead.
+</section>
</div>
<table class="foot">
<tr>
- <td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-date">January 7, 2020</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_file_set_mtime.mdoc -- set mtime for file in zip
-.\" Copyright (C) 2014-2017 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2014-2020 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP files.
.\" The authors can be contacted at <libzip@nih.at>
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "ZIP_FILE_SET_MTIME" "3" "December 18, 2017" "NiH" "Library Functions Manual"
+.TH "ZIP_FILE_SET_MTIME" "3" "January 7, 2020" "NiH" "Library Functions Manual"
.nh
.if n .ad l
.SH "NAME"
+\fBzip_file_set_dostime\fR,
\fBzip_file_set_mtime\fR
\- set last modification time (mtime) for file in zip
.SH "LIBRARY"
.br
.PD 0
.HP 4n
+\fBzip_file_set_dostime\fR(\fIzip_t\ *archive\fR, \fIzip_uint64_t\ index\fR, \fIzip_uint16_t\ dostime\fR, \fIzip_uint16_t\ dosdate\fR, \fIzip_flags_t\ flags\fR);
+.PD
+.PP
+\fIint\fR
+.br
+.PD 0
+.HP 4n
\fBzip_file_set_mtime\fR(\fIzip_t\ *archive\fR, \fIzip_uint64_t\ index\fR, \fItime_t\ mtime\fR, \fIzip_flags_t\ flags\fR);
.PD
.SH "DESCRIPTION"
Currently, no support for any
\fIflags\fR
is implemented.
+.PP
+In the zip archive, the time and date are saved as two 16-bit integers.
+To set the values directly, call the
+\fBzip_file_set_dostime\fR()
+function.
+The values of the time bytes are defined as follows:
+.RS 6n
+.TP 7n
+0-4
+day of the month (1-31)
+.TP 7n
+5-8
+month (January = 1, February = 2, ...)
+.TP 7n
+9-15
+year offset from 1980 (1980 = 0, 1981 = 1, ...)
+.RE
+.PP
+The values of the date bytes are defined as follows:
+.RS 6n
+.TP 7n
+0-4
+seconds divided by two (1-2 = 1, 3-4 = 2, ...)
+.TP 7n
+5-10
+minute (0-59)
+.TP 7n
+11-15
+hour (0-23)
+.RE
.SH "RETURN VALUES"
Upon successful completion 0 is returned.
Otherwise, \-1 is returned and the error information in
\fIarchive\fR
is set to indicate the error.
.SH "ERRORS"
+\fBzip_file_set_dostime\fR()
+and
\fBzip_file_set_mtime\fR()
-fails if:
+fail if:
.TP 19n
[\fRZIP_ER_INVAL\fR]
\fIindex\fR
.SH "HISTORY"
\fBzip_file_set_mtime\fR()
was added in libzip 1.0.
+\fBzip_file_set_dostime\fR()
+was added in libzip 1.6.
.SH "AUTHORS"
Dieter Baron <\fIdillo@nih.at\fR>
and
Thomas Klausner <\fItk@giga.or.at\fR>
+.SH "CAVEATS"
+Following historical practice, the
+\fBzip_file_set_mtime\fR()
+function translates the time from the zip archive into the local time
+zone.
+If you want to avoid this, use the
+\fBzip_file_set_dostime\fR()
+function instead.
.\" zip_file_set_mtime.mdoc -- set mtime for file in zip
-.\" Copyright (C) 2014-2017 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2014-2020 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP files.
.\" The authors can be contacted at <libzip@nih.at>
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd December 18, 2017
+.Dd January 7, 2020
.Dt ZIP_FILE_SET_MTIME 3
.Os
.Sh NAME
+.Nm zip_file_set_dostime ,
.Nm zip_file_set_mtime
.Nd set last modification time (mtime) for file in zip
.Sh LIBRARY
.Sh SYNOPSIS
.In zip.h
.Ft int
+.Fn zip_file_set_dostime "zip_t *archive" "zip_uint64_t index" "zip_uint16_t dostime" "zip_uint16_t dosdate" "zip_flags_t flags"
+.Ft int
.Fn zip_file_set_mtime "zip_t *archive" "zip_uint64_t index" "time_t mtime" "zip_flags_t flags"
.Sh DESCRIPTION
The
Currently, no support for any
.Ar flags
is implemented.
+.Pp
+In the zip archive, the time and date are saved as two 16-bit integers.
+To set the values directly, call the
+.Fn zip_file_set_dostime
+function.
+The values of the time bytes are defined as follows:
+.Bl -tag -width 5n -offset indent
+.It 0-4
+day of the month (1-31)
+.It 5-8
+month (January = 1, February = 2, ...)
+.It 9-15
+year offset from 1980 (1980 = 0, 1981 = 1, ...)
+.El
+.Pp
+The values of the date bytes are defined as follows:
+.Bl -tag -width 5n -offset indent
+.It 0-4
+seconds divided by two (1-2 = 1, 3-4 = 2, ...)
+.It 5-10
+minute (0-59)
+.It 11-15
+hour (0-23)
+.El
.Sh RETURN VALUES
Upon successful completion 0 is returned.
Otherwise, \-1 is returned and the error information in
.Ar archive
is set to indicate the error.
.Sh ERRORS
+.Fn zip_file_set_dostime
+and
.Fn zip_file_set_mtime
-fails if:
+fail if:
.Bl -tag -width Er
.It Bq Er ZIP_ER_INVAL
.Ar index
.Sh HISTORY
.Fn zip_file_set_mtime
was added in libzip 1.0.
+.Fn zip_file_set_dostime
+was added in libzip 1.6.
.Sh AUTHORS
.An -nosplit
.An Dieter Baron Aq Mt dillo@nih.at
and
.An Thomas Klausner Aq Mt tk@giga.or.at
+.Sh CAVEATS
+Following historical practice, the
+.Fn zip_file_set_mtime
+function translates the time from the zip archive into the local time
+zone.
+If you want to avoid this, use the
+.Fn zip_file_set_dostime
+function instead.
<html>
<!-- This is an automatically generated file. Do not edit.
zip_file_strerror.mdoc -- get string representation for a zip error
- Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_file_strerror.mdoc -- get string representation for a zip error
-.\" Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_file_strerror.mdoc -- get string representation for a zip error
-.\" Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">July 22, 2018</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
</tr>
</table>
<div class="manual-text">
-<h1 class="Sh" title="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
-<code class="Nm" title="Nm">zip_libzip_version</code> —
-<div class="Nd" title="Nd">return run-time version of library</div>
-<h1 class="Sh" title="Sh" id="LIBRARY"><a class="permalink" href="#LIBRARY">LIBRARY</a></h1>
+<section class="Sh">
+<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
+<code class="Nm">zip_libzip_version</code> —
+<div class="Nd">return run-time version of library</div>
+</section>
+<section class="Sh">
+<h1 class="Sh" id="LIBRARY"><a class="permalink" href="#LIBRARY">LIBRARY</a></h1>
libzip (-lzip)
-<h1 class="Sh" title="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
-<code class="In" title="In">#include
- <<a class="In" title="In">zip.h</a>></code>
-<div class="Pp"></div>
-<var class="Ft" title="Ft">const char *</var>
-<br/>
-<code class="Fn" title="Fn">zip_libzip_version</code>(<var class="Fa" title="Fa" style="white-space: nowrap;">void</var>);
-<h1 class="Sh" title="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
-<code class="Nm" title="Nm">zip_libzip_version</code> returns the version number
- of the library as string in the format
- “$MAJOR.$MINOR.$MICRO$SUFFIX” where
- <var class="Ar" title="Ar">$MAJOR</var> is the major version,
- <var class="Ar" title="Ar">$MINOR</var> the minor,
- <var class="Ar" title="Ar">$MICRO</var> the micro, and
- <var class="Ar" title="Ar">$SUFFIX</var> a suffix that's only set for
+</section>
+<section class="Sh">
+<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
+<code class="In">#include <<a class="In">zip.h</a>></code>
+<p class="Pp"><var class="Ft">const char *</var>
+ <br/>
+ <code class="Fn">zip_libzip_version</code>(<var class="Fa" style="white-space: nowrap;">void</var>);</p>
+</section>
+<section class="Sh">
+<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
+<code class="Nm">zip_libzip_version</code> returns the version number of the
+ library as string in the format “$MAJOR.$MINOR.$MICRO$SUFFIX”
+ where <var class="Ar">$MAJOR</var> is the major version,
+ <var class="Ar">$MINOR</var> the minor, <var class="Ar">$MICRO</var> the
+ micro, and <var class="Ar">$SUFFIX</var> a suffix that's only set for
development versions.
-<h1 class="Sh" title="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
+</section>
+<section class="Sh">
+<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
ALSO</a></h1>
-<a class="Xr" title="Xr" href="libzip.html">libzip(3)</a>
-<h1 class="Sh" title="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
-<code class="Fn" title="Fn">zip_libzip_version</code>() was added in libzip
- 1.3.1.
-<h1 class="Sh" title="Sh" id="AUTHORS"><a class="permalink" href="#AUTHORS">AUTHORS</a></h1>
-<span class="An" title="An">Dieter Baron</span>
- <<a class="Mt" title="Mt" href="mailto:dillo@nih.at">dillo@nih.at</a>>
- and <span class="An" title="An">Thomas Klausner</span>
- <<a class="Mt" title="Mt" href="mailto:tk@giga.or.at">tk@giga.or.at</a>></div>
+<a class="Xr" href="libzip.html">libzip(3)</a>
+</section>
+<section class="Sh">
+<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
+<code class="Fn">zip_libzip_version</code>() was added in libzip 1.3.1.
+</section>
+<section class="Sh">
+<h1 class="Sh" id="AUTHORS"><a class="permalink" href="#AUTHORS">AUTHORS</a></h1>
+<span class="An">Dieter Baron</span>
+ <<a class="Mt" href="mailto:dillo@nih.at">dillo@nih.at</a>> and
+ <span class="An">Thomas Klausner</span>
+ <<a class="Mt" href="mailto:tk@giga.or.at">tk@giga.or.at</a>>
+</section>
+</div>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.27</td>
+ <td class="foot-os">NetBSD 8.99.35</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_open.mdoc -- open zip archive
- Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_open.mdoc -- open zip archive
-.\" Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_open.mdoc -- open zip archive
-.\" Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
</tr>
</table>
<div class="manual-text">
-<h1 class="Sh" title="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
-<code class="Nm" title="Nm">zip_register_progress_callback_with_state</code>
- —
-<div class="Nd" title="Nd">provide updates during zip_close</div>
-<h1 class="Sh" title="Sh" id="LIBRARY"><a class="permalink" href="#LIBRARY">LIBRARY</a></h1>
+<section class="Sh">
+<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
+<code class="Nm">zip_register_progress_callback_with_state</code> —
+<div class="Nd">provide updates during zip_close</div>
+</section>
+<section class="Sh">
+<h1 class="Sh" id="LIBRARY"><a class="permalink" href="#LIBRARY">LIBRARY</a></h1>
libzip (-lzip)
-<h1 class="Sh" title="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
-<code class="In" title="In">#include
- <<a class="In" title="In">zip.h</a>></code>
-<div class="Pp"></div>
-<var class="Vt" title="Vt">typedef void (*zip_progress_callback)(zip_t *,
- double, void *);</var>
-<div class="Pp"></div>
-<var class="Ft" title="Ft">void</var>
-<br/>
-<code class="Fn" title="Fn">zip_register_progress_callback_with_state</code>(<var class="Fa" title="Fa" style="white-space: nowrap;">zip_t
- *archive</var>, <var class="Fa" title="Fa" style="white-space: nowrap;">double
- precision</var>,
- <var class="Fa" title="Fa" style="white-space: nowrap;">zip_progress_callback
- callback</var>, <var class="Fa" title="Fa" style="white-space: nowrap;">void
- (*ud_free)(void *)</var>,
- <var class="Fa" title="Fa" style="white-space: nowrap;">void *ud</var>);
-<h1 class="Sh" title="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
-The
- <code class="Fn" title="Fn">zip_register_progress_callback_with_state</code>()
- function registers a callback function
- <var class="Ar" title="Ar">callback</var> for the zip archive
- <var class="Ar" title="Ar">archive</var>. The
- <var class="Ar" title="Ar">precision</var> argument is a double in the range
- from 0.00 to 1.0 that defines the smallest change for which the callback
- should be called (to avoid too frequent calls). The
- <var class="Ar" title="Ar">ud_free</var> function is called during cleanup for
- deleting the userdata supplied in <var class="Ar" title="Ar">ud</var>.
-<div class="Pp"></div>
-The callback function is called during
- <a class="Xr" title="Xr" href="zip_close.html">zip_close(3)</a> in regular
- intervals (after every zip archive entry that's completely written to disk,
- and while writing data for entries) with zip archive
- <var class="Ar" title="Ar">archive</var>, the current progression state as a
- <var class="Vt" title="Vt">double</var>, and the user-provided user-data
- <var class="Ar" title="Ar">ud</var> as arguments. The progression state is a
- <var class="Vt" title="Vt">double</var> in the range from 0.0 to 1.0. This can
- be used to provide progress indicators for user interfaces.
-<h1 class="Sh" title="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
+</section>
+<section class="Sh">
+<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
+<code class="In">#include <<a class="In">zip.h</a>></code>
+<p class="Pp"><var class="Vt">typedef void (*zip_progress_callback)(zip_t *,
+ double, void *);</var></p>
+<p class="Pp"><var class="Ft">void</var>
+ <br/>
+ <code class="Fn">zip_register_progress_callback_with_state</code>(<var class="Fa" style="white-space: nowrap;">zip_t
+ *archive</var>, <var class="Fa" style="white-space: nowrap;">double
+ precision</var>,
+ <var class="Fa" style="white-space: nowrap;">zip_progress_callback
+ callback</var>, <var class="Fa" style="white-space: nowrap;">void
+ (*ud_free)(void *)</var>, <var class="Fa" style="white-space: nowrap;">void
+ *ud</var>);</p>
+</section>
+<section class="Sh">
+<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
+The <code class="Fn">zip_register_progress_callback_with_state</code>() function
+ registers a callback function <var class="Ar">callback</var> for the zip
+ archive <var class="Ar">archive</var>. The <var class="Ar">precision</var>
+ argument is a double in the range from 0.00 to 1.0 that defines the smallest
+ change for which the callback should be called (to avoid too frequent calls).
+ The <var class="Ar">ud_free</var> function is called during cleanup for
+ deleting the userdata supplied in <var class="Ar">ud</var>.
+<p class="Pp">The callback function is called during
+ <a class="Xr" href="zip_close.html">zip_close(3)</a> in regular intervals
+ (after every zip archive entry that's completely written to disk, and while
+ writing data for entries) with zip archive <var class="Ar">archive</var>,
+ the current progression state as a <var class="Vt">double</var>, and the
+ user-provided user-data <var class="Ar">ud</var> as arguments. The
+ progression state is a <var class="Vt">double</var> in the range from 0.0 to
+ 1.0. This can be used to provide progress indicators for user
+ interfaces.</p>
+</section>
+<section class="Sh">
+<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
ALSO</a></h1>
-<a class="Xr" title="Xr" href="libzip.html">libzip(3)</a>,
- <a class="Xr" title="Xr" href="zip_close.html">zip_close(3)</a>
-<h1 class="Sh" title="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
-<code class="Fn" title="Fn">zip_register_progress_callback_with_state</code>()
- was added in libzip 1.3.0.
-<h1 class="Sh" title="Sh" id="AUTHORS"><a class="permalink" href="#AUTHORS">AUTHORS</a></h1>
-<span class="An" title="An">Dieter Baron</span>
- <<a class="Mt" title="Mt" href="mailto:dillo@nih.at">dillo@nih.at</a>>
- and <span class="An" title="An">Thomas Klausner</span>
- <<a class="Mt" title="Mt" href="mailto:tk@giga.or.at">tk@giga.or.at</a>></div>
+<a class="Xr" href="libzip.html">libzip(3)</a>,
+ <a class="Xr" href="zip_close.html">zip_close(3)</a>
+</section>
+<section class="Sh">
+<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
+<code class="Fn">zip_register_progress_callback_with_state</code>() was added in
+ libzip 1.3.0.
+</section>
+<section class="Sh">
+<h1 class="Sh" id="AUTHORS"><a class="permalink" href="#AUTHORS">AUTHORS</a></h1>
+<span class="An">Dieter Baron</span>
+ <<a class="Mt" href="mailto:dillo@nih.at">dillo@nih.at</a>> and
+ <span class="An">Thomas Klausner</span>
+ <<a class="Mt" href="mailto:tk@giga.or.at">tk@giga.or.at</a>>
+</section>
+</div>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.27</td>
+ <td class="foot-os">NetBSD 8.99.35</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_set_archive_comment.mdoc -- set zip archive comment
- Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_set_archive_comment.mdoc -- set zip archive comment
-.\" Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_set_archive_comment.mdoc -- set zip archive comment
-.\" Copyright (C) 2006-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2006-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_source.mdoc -- description of zip data source
- Copyright (C) 2014-2017 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_source.mdoc -- description of zip data source
-.\" Copyright (C) 2014-2017 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_source.mdoc -- description of zip data source
-.\" Copyright (C) 2014-2017 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_source_buffer.mdoc -- create zip data source from buffer
- Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_source_buffer.mdoc -- create zip data source from buffer
-.\" Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_source_buffer.mdoc -- create zip data source from buffer
-.\" Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_source_buffer_fragment.mdoc -- create zip data source from multiple buffers
- Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_source_buffer_fragment.mdoc -- create zip data source from multiple buffers
-.\" Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_source_buffer_fragment.mdoc -- create zip data source from multiple buffers
-.\" Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_source_file.mdoc -- create data source from a file
- Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_source_file.mdoc -- create data source from a file
-.\" Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_source_file.mdoc -- create data source from a file
-.\" Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_source_filep.mdoc -- create data source from a file stream
- Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_source_filep.mdoc -- create data source from a file stream
-.\" Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_source_filep.mdoc -- create data source from a file stream
-.\" Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_source_function.mdoc -- create data source from function
- Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<code class="Dv">ZIP_SOURCE_REMOVE</code>.</dd>
</dl>
<section class="Ss">
+<h2 class="Ss"><code class="Dv">ZIP_SOURCE_ACCEPT_EMPTY</code></h2>
+Return 1 if an empty source should be accepted as a valid zip archive. This is
+ the default if this command is not supported by a source. File system backed
+ sources should return 0.
+</section>
+<section class="Ss">
<h2 class="Ss"><code class="Dv">ZIP_SOURCE_BEGIN_WRITE</code></h2>
Prepare the source for writing. Use this to create any temporary file(s).
</section>
</div>
<table class="foot">
<tr>
- <td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-date">September 17, 2019</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_source_function.mdoc -- create data source from function
-.\" Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.TH "ZIP_SOURCE_FUNCTION" "3" "December 18, 2017" "NiH" "Library Functions Manual"
+.TH "ZIP_SOURCE_FUNCTION" "3" "September 17, 2019" "NiH" "Library Functions Manual"
.nh
.if n .ad l
.SH "NAME"
\fRZIP_SOURCE_TELL_WRITE\fR,
and
\fRZIP_SOURCE_REMOVE\fR.
+.SS "\fRZIP_SOURCE_ACCEPT_EMPTY\fR"
+Return 1 if an empty source should be accepted as a valid zip archive.
+This is the default if this command is not supported by a source.
+File system backed sources should return 0.
.SS "\fRZIP_SOURCE_BEGIN_WRITE\fR"
Prepare the source for writing.
Use this to create any temporary file(s).
.\" zip_source_function.mdoc -- create data source from function
-.\" Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd December 18, 2017
+.Dd September 17, 2019
.Dt ZIP_SOURCE_FUNCTION 3
.Os
.Sh NAME
and
.Dv ZIP_SOURCE_REMOVE .
.El
+.Ss Dv ZIP_SOURCE_ACCEPT_EMPTY
+Return 1 if an empty source should be accepted as a valid zip archive.
+This is the default if this command is not supported by a source.
+File system backed sources should return 0.
.Ss Dv ZIP_SOURCE_BEGIN_WRITE
Prepare the source for writing.
Use this to create any temporary file(s).
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_source_stat.mdoc -- get information about zip source
- Copyright (C) 2014-2017 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
defines are in <var class="Ar">valid</var> before accessing the fields:</p>
<div class="Bd-indent">
<dl class="Bl-tag Bl-compact">
- <dt><a class="permalink" href="#ZIP_SOURCE_STAT_NAME"><code class="Dv" id="ZIP_SOURCE_STAT_NAME">ZIP_SOURCE_STAT_NAME</code></a></dt>
+ <dt><a class="permalink" href="#ZIP_STAT_NAME"><code class="Dv" id="ZIP_STAT_NAME">ZIP_STAT_NAME</code></a></dt>
<dd><var class="Ar">name</var></dd>
- <dt><a class="permalink" href="#ZIP_SOURCE_STAT_INDEX"><code class="Dv" id="ZIP_SOURCE_STAT_INDEX">ZIP_SOURCE_STAT_INDEX</code></a></dt>
+ <dt><a class="permalink" href="#ZIP_STAT_INDEX"><code class="Dv" id="ZIP_STAT_INDEX">ZIP_STAT_INDEX</code></a></dt>
<dd><var class="Ar">index</var></dd>
- <dt><a class="permalink" href="#ZIP_SOURCE_STAT_SIZE"><code class="Dv" id="ZIP_SOURCE_STAT_SIZE">ZIP_SOURCE_STAT_SIZE</code></a></dt>
+ <dt><a class="permalink" href="#ZIP_STAT_SIZE"><code class="Dv" id="ZIP_STAT_SIZE">ZIP_STAT_SIZE</code></a></dt>
<dd><var class="Ar">size</var></dd>
- <dt><a class="permalink" href="#ZIP_SOURCE_STAT_COMP_SIZE"><code class="Dv" id="ZIP_SOURCE_STAT_COMP_SIZE">ZIP_SOURCE_STAT_COMP_SIZE</code></a></dt>
+ <dt><a class="permalink" href="#ZIP_STAT_COMP_SIZE"><code class="Dv" id="ZIP_STAT_COMP_SIZE">ZIP_STAT_COMP_SIZE</code></a></dt>
<dd><var class="Ar">comp_size</var></dd>
- <dt><a class="permalink" href="#ZIP_SOURCE_STAT_MTIME"><code class="Dv" id="ZIP_SOURCE_STAT_MTIME">ZIP_SOURCE_STAT_MTIME</code></a></dt>
+ <dt><a class="permalink" href="#ZIP_STAT_MTIME"><code class="Dv" id="ZIP_STAT_MTIME">ZIP_STAT_MTIME</code></a></dt>
<dd><var class="Ar">mtime</var></dd>
- <dt><a class="permalink" href="#ZIP_SOURCE_STAT_CRC"><code class="Dv" id="ZIP_SOURCE_STAT_CRC">ZIP_SOURCE_STAT_CRC</code></a></dt>
+ <dt><a class="permalink" href="#ZIP_STAT_CRC"><code class="Dv" id="ZIP_STAT_CRC">ZIP_STAT_CRC</code></a></dt>
<dd><var class="Ar">crc</var></dd>
- <dt><a class="permalink" href="#ZIP_SOURCE_STAT_COMP_METHOD"><code class="Dv" id="ZIP_SOURCE_STAT_COMP_METHOD">ZIP_SOURCE_STAT_COMP_METHOD</code></a></dt>
+ <dt><a class="permalink" href="#ZIP_STAT_COMP_METHOD"><code class="Dv" id="ZIP_STAT_COMP_METHOD">ZIP_STAT_COMP_METHOD</code></a></dt>
<dd><var class="Ar">comp_method</var></dd>
- <dt><a class="permalink" href="#ZIP_SOURCE_STAT_ENCRYPTION_METHOD"><code class="Dv" id="ZIP_SOURCE_STAT_ENCRYPTION_METHOD">ZIP_SOURCE_STAT_ENCRYPTION_METHOD</code></a></dt>
+ <dt><a class="permalink" href="#ZIP_STAT_ENCRYPTION_METHOD"><code class="Dv" id="ZIP_STAT_ENCRYPTION_METHOD">ZIP_STAT_ENCRYPTION_METHOD</code></a></dt>
<dd><var class="Ar">encryption_method</var></dd>
- <dt><a class="permalink" href="#ZIP_SOURCE_STAT_FLAGS"><code class="Dv" id="ZIP_SOURCE_STAT_FLAGS">ZIP_SOURCE_STAT_FLAGS</code></a></dt>
+ <dt><a class="permalink" href="#ZIP_STAT_FLAGS"><code class="Dv" id="ZIP_STAT_FLAGS">ZIP_STAT_FLAGS</code></a></dt>
<dd><var class="Ar">flags</var></dd>
</dl>
</div>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_source_stat.mdoc -- get information about zip source
-.\" Copyright (C) 2014-2017 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
before accessing the fields:
.RS 6n
.PD 0
-.TP 37n
-\fRZIP_SOURCE_STAT_NAME\fR
+.TP 30n
+\fRZIP_STAT_NAME\fR
\fIname\fR
-.TP 37n
-\fRZIP_SOURCE_STAT_INDEX\fR
+.TP 30n
+\fRZIP_STAT_INDEX\fR
\fIindex\fR
-.TP 37n
-\fRZIP_SOURCE_STAT_SIZE\fR
+.TP 30n
+\fRZIP_STAT_SIZE\fR
\fIsize\fR
-.TP 37n
-\fRZIP_SOURCE_STAT_COMP_SIZE\fR
+.TP 30n
+\fRZIP_STAT_COMP_SIZE\fR
\fIcomp_size\fR
-.TP 37n
-\fRZIP_SOURCE_STAT_MTIME\fR
+.TP 30n
+\fRZIP_STAT_MTIME\fR
\fImtime\fR
-.TP 37n
-\fRZIP_SOURCE_STAT_CRC\fR
+.TP 30n
+\fRZIP_STAT_CRC\fR
\fIcrc\fR
-.TP 37n
-\fRZIP_SOURCE_STAT_COMP_METHOD\fR
+.TP 30n
+\fRZIP_STAT_COMP_METHOD\fR
\fIcomp_method\fR
-.TP 37n
-\fRZIP_SOURCE_STAT_ENCRYPTION_METHOD\fR
+.TP 30n
+\fRZIP_STAT_ENCRYPTION_METHOD\fR
\fIencryption_method\fR
-.TP 37n
-\fRZIP_SOURCE_STAT_FLAGS\fR
+.TP 30n
+\fRZIP_STAT_FLAGS\fR
\fIflags\fR
.RE
.PD
.\" zip_source_stat.mdoc -- get information about zip source
-.\" Copyright (C) 2014-2017 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
Check if the flag defined by the following defines are in
.Ar valid
before accessing the fields:
-.Bl -tag -width ZIP_SOURCE_STAT_ENCRYPTION_METHODXX -compact -offset indent
-.It Dv ZIP_SOURCE_STAT_NAME
+.Bl -tag -width ZIP_STAT_ENCRYPTION_METHODXX -compact -offset indent
+.It Dv ZIP_STAT_NAME
.Ar name
-.It Dv ZIP_SOURCE_STAT_INDEX
+.It Dv ZIP_STAT_INDEX
.Ar index
-.It Dv ZIP_SOURCE_STAT_SIZE
+.It Dv ZIP_STAT_SIZE
.Ar size
-.It Dv ZIP_SOURCE_STAT_COMP_SIZE
+.It Dv ZIP_STAT_COMP_SIZE
.Ar comp_size
-.It Dv ZIP_SOURCE_STAT_MTIME
+.It Dv ZIP_STAT_MTIME
.Ar mtime
-.It Dv ZIP_SOURCE_STAT_CRC
+.It Dv ZIP_STAT_CRC
.Ar crc
-.It Dv ZIP_SOURCE_STAT_COMP_METHOD
+.It Dv ZIP_STAT_COMP_METHOD
.Ar comp_method
-.It Dv ZIP_SOURCE_STAT_ENCRYPTION_METHOD
+.It Dv ZIP_STAT_ENCRYPTION_METHOD
.Ar encryption_method
-.It Dv ZIP_SOURCE_STAT_FLAGS
+.It Dv ZIP_STAT_FLAGS
.Ar flags
.El
.Pp
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_source_win32a.mdoc -- create data source using a win32 ANSI name
- Copyright (C) 2015-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2015-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_source_win32a.mdoc -- create data source using a win32 ANSI name
-.\" Copyright (C) 2015-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2015-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_source_win32a.mdoc -- create data source using a win32 ANSI name
-.\" Copyright (C) 2015-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2015-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_source_handle.mdoc -- create data source from a Windows file handle
- Copyright (C) 2015-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2015-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_source_handle.mdoc -- create data source from a Windows file handle
-.\" Copyright (C) 2015-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2015-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_source_handle.mdoc -- create data source from a Windows file handle
-.\" Copyright (C) 2015-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2015-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_source_win32w.mdoc -- create data source using a win32 Unicode name
- Copyright (C) 2015-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2015-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">June 22, 2018</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_source_win32w.mdoc -- create data source using a win32 Unicode name
-.\" Copyright (C) 2015-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2015-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_source_win32w.mdoc -- create data source using a win32 Unicode name
-.\" Copyright (C) 2015-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2015-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zip_source_zip.mdoc -- create data source from zip file
- Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zip_source_zip.mdoc -- create data source from zip file
-.\" Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zip_source_zip.mdoc -- create data source from zip file
-.\" Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
<html>
<!-- This is an automatically generated file. Do not edit.
zipcmp.mdoc -- compare zip archives
- Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zipcmp.mdoc -- compare zip archives
-.\" Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zipcmp.mdoc -- compare zip archives
-.\" Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<html>
<!-- This is an automatically generated file. Do not edit.
zipmerge.mdoc -- merge zip archives
- Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
.\" Automatically generated from an mdoc input file. Do not edit.
.\" zipmerge.mdoc -- merge zip archives
-.\" Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
.\" zipmerge.mdoc -- merge zip archives
-.\" Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
.\"
.\" This file is part of libzip, a library to manipulate ZIP archives.
.\" The authors can be contacted at <libzip@nih.at>
<table class="foot">
<tr>
<td class="foot-date">December 18, 2017</td>
- <td class="foot-os">NetBSD 8.99.35</td>
+ <td class="foot-os">NetBSD 9.99.41</td>
</tr>
</table>
</body>
add_stored_in_memory.test
buffer-fragment-read.test
buffer-fragment-write.test
- clone-buffer-add.test
- clone-buffer-delete.test
- clone-buffer-replace.test
- clone-fs-add.test
- clone-fs-delete.test
- clone-fs-replace.test
+ cancel_45.test
+ cancel_90.test
+ clone-buffer-add.test
+ clone-buffer-delete.test
+ clone-buffer-replace.test
+ clone-fs-add.test
+ clone-fs-delete.test
+ clone-fs-replace.test
cm-default.test
count_entries.test
decrypt-correct-password-aes128.test
set_compression_store_to_bzip2.test
set_compression_store_to_deflate.test
set_compression_store_to_store.test
+ set_compression_store_to_xz.test
set_compression_unknown.test
+ set_compression_xz_to_store.test
+ set_file_dostime.test
stat_index_cp437_guess.test
stat_index_cp437_raw.test
stat_index_cp437_strict.test
zip64_stored_creation.test
)
+
+set(path "$<TARGET_FILE_DIR:zip>;$ENV{PATH}")
+if (TARGET zlib)
+ set(path "$<TARGET_FILE_DIR:zlib>;${path}")
+endif()
+string(REPLACE ";" "\\;" path "${path}")
+
FOREACH(CASE ${EXTRA_TESTS})
- ADD_TEST(${CASE} perl ${CMAKE_BINARY_DIR}/regress/runtest ${CMAKE_CURRENT_SOURCE_DIR}/${CASE})
+ ADD_TEST(NAME ${CASE} COMMAND perl ${CMAKE_CURRENT_BINARY_DIR}/runtest --bin-sub-directory $<CONFIG> ${CMAKE_CURRENT_SOURCE_DIR}/${CASE})
SET_TESTS_PROPERTIES(${CASE} PROPERTIES SKIP_RETURN_CODE 77)
+ SET_TESTS_PROPERTIES(${CASE} PROPERTIES ENVIRONMENT "PATH=${path}")
ENDFOREACH()
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/../lib ${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_BINARY_DIR}/..)
ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
+
+ADD_EXECUTABLE(fuzz_main fuzz_main.c)
+TARGET_LINK_LIBRARIES(fuzz_main zip)
use File::Path qw(mkpath remove_tree);
use Getopt::Long qw(:config posix_default bundling no_ignore_case);
use IPC::Open3;
+#use IPC::Cmd qw(run);
use Storable qw(dclone);
use Symbol 'gensym';
use UNIVERSAL;
@ARGV = @argv;
my $ok = GetOptions(
'help|h' => \my $help,
+ 'bin-sub-directory=s' => \$self->{bin_sub_directory},
'keep-broken|k' => \$self->{keep_broken},
'no-cleanup' => \$self->{no_cleanup},
# 'run-gdb' => \$self->{run_gdb},
@ARGV = @save_argv;
if (!$ok || scalar(@argv) != 1 || $help) {
- print STDERR "Usage: $0 [-hv] [--keep-broken] [--no-cleanup] [--setup-only] testcase\n";
+ print STDERR "Usage: $0 [-hv] [--bin-sub-directory DIR] [--keep-broken] [--no-cleanup] [--setup-only] testcase\n";
exit(1);
}
$self->run_precheck() if ($self->{test}->{precheck});
$self->end_test('SKIP') if ($self->{test}->{preload} && $^O eq 'darwin');
+ $self->end_test('SKIP') if (($self->{test}->{pipein} || $self->{test}->{pipefile}) && $^O eq 'MSWin32');
}
sub comparator_zip {
my ($self, $got, $expected) = @_;
- my @args = ($self->{zipcmp}, $self->{verbose} ? '-v' : '-q');
+ my $zipcmp = (-f $self->{zipcmp}) ? $self->{zipcmp} : $self->find_program('zipcmp');
+ my @args = ($zipcmp, $self->{verbose} ? '-v' : '-q');
push @args, $self->{zipcmp_flags} if ($self->{zipcmp_flags});
push @args, ($expected, $got);
while (scalar(@dirs) > 0) {
my $dir = shift @dirs;
-
+
opendir($ls, $dir);
unless ($ls) {
# TODO: handle error
if ($dir eq '.') {
$file = $entry;
}
-
+
if (-f $file) {
push @files, "$file";
}
for my $dir (('', "$self->{srcdir}/")) {
my $f = "$dir$fname";
- $f = "../$f" if ($self->{in_sandbox} && $dir !~ m,^/,);
+ $f = "../$f" if ($self->{in_sandbox} && $dir !~ m,^(\w:)?/,);
return $f if (-f $f);
}
my %test = ();
while (my $line = <TST>) {
- chomp $line;
+ $line =~ s/(\n|\r)//g;
next if ($line =~ m/^\#/);
return $ok;
}
-sub args_decode {
+sub args_decode {
my ($str, $srcdir) = @_;
if ($str =~ m/\\/) {
}
+sub find_program() {
+ my ($self, $pname) = @_;
+
+ my @directories = (".");
+ if ($self->{bin_sub_directory}) {
+ push @directories, $self->{bin_sub_directory};
+ }
+
+ for my $up (('.', '..', '../..', '../../..')) {
+ for my $sub (('.', 'src')) {
+ for my $dir (@directories) {
+ for my $ext (('', '.exe')) {
+ my $f = "$up/$sub/$dir/$pname$ext";
+ return $f if (-f $f);
+ }
+ }
+ }
+ }
+
+ return undef;
+}
+
+
sub run_program {
my ($self) = @_;
- goto &pipein_win32 if $^O eq 'MSWin32' && $self->{test}->{pipein};
+ goto &pipein_win32 if (($^O eq 'MSWin32') or ($^O eq 'msys')) && $self->{test}->{pipein};
my ($stdin, $stdout, $stderr);
$stderr = gensym;
- my @cmd = ('../' . $self->{test}->{program}, map ({ args_decode($_, $self->{srcdir}); } @{$self->{test}->{args}}));
+ my @cmd = ($self->find_program($self->{test}->{program}), map ({ args_decode($_, $self->{srcdir}); } @{$self->{test}->{args}}));
### TODO: catch errors?
}
while (my $line = <$stdout>) {
- if ($^O eq 'MSWin32') {
- $line =~ s/[\r\n]+$//;
- }
- else {
- chomp $line;
- }
+ $line =~ s/(\n|\r)//g;
push @{$self->{stdout}}, $line;
}
my $prg = $self->{test}->{program};
$prg =~ s,.*/,,;
while (my $line = <$stderr>) {
- if ($^O eq 'MSWin32') {
- $line =~ s/[\r\n]+$//;
- }
- else {
- chomp $line;
- }
-
- $line =~ s/^[^: ]*$prg: //;
+ $line =~ s/(\n|\r)//g;
+ $line =~ s/^[^: ]*$prg(\.exe)?: //;
if (defined($self->{test}->{'stderr-replace'})) {
$line = $self->stderr_rewrite($self->{test}->{'stderr-replace'}, $line);
}
sub pipein_win32() {
my ($self) = @_;
- my $cmd = "$self->{test}->{pipein}| ..\\$self->{test}->{program} " . join(' ', map ({ args_decode($_, $self->{srcdir}); } @{$self->{test}->{args}}));
+ # TODO this is currently broken, IPC::Cmd::run fails to load
+ my $program = $self->find_program($self->{test}->{program});
+ my $cmd = "$self->{test}->{pipein} | $program " . join(' ', map ({ args_decode($_, $self->{srcdir}); } @{$self->{test}->{args}}));
my ($success, $error_message, $full_buf, $stdout_buf, $stderr_buf) = IPC::Cmd::run(command => $cmd);
if (!$success) {
### TODO: catch errors?
foreach my $line (@$stderr_buf) {
$line =~ s/[\r\n]+$//;
- $line =~ s/^[^: ]*$prg: //;
+ $line =~ s/^[^: ]*$prg(\.exe)?: //;
if (defined($self->{test}->{'stderr-replace'})) {
$line = $self->stderr_rewrite($self->{test}->{'stderr-replace'}, $line);
}
sub sandbox_remove {
my ($self) = @_;
- my $ok = 1;
remove_tree($self->{sandbox_dir});
- return $ok;
+ return 1;
}
/*
add_from_filep.c -- test case for adding file to archive
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
can_clone_file.c -- does the current filesystem support cloning
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
--- /dev/null
+# test default compression stores if smaller; test cancel after 45%
+return 1
+args -n test.zip cancel 45 add compressable aaaaaaaaaaaaaa add uncompressable uncompressable add_nul large-compressable 8200 add_file large-uncompressable large-uncompressable 0 -1
+file large-uncompressable large-uncompressable large-uncompressable
+stdout 0.0% done
+stdout 25.0% done
+stdout 50.0% done
+stderr can't close zip archive 'test.zip': Operation cancelled
--- /dev/null
+# test default compression stores if smaller; test cancel after 90%
+return 1
+args -n test.zip cancel 90 add compressable aaaaaaaaaaaaaa add uncompressable uncompressable add_nul large-compressable 8200 add_file large-uncompressable large-uncompressable 0 -1
+file large-uncompressable large-uncompressable large-uncompressable
+stdout 0.0% done
+stdout 25.0% done
+stdout 50.0% done
+stdout 75.0% done
+stdout 100.0% done
+stderr can't close zip archive 'test.zip': Operation cancelled
/*
fopen_unchanged.c -- test case for adding file and reading from unchanged
- Copyright (C) 2012-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2012-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
fread.c -- test cases for reading from zip archives
- Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
fail += do_read(z, "storedcrcerror", 0, WHEN_READ, ZIP_ER_CRC, 0);
fail += do_read(z, "deflatecrcerror", 0, WHEN_READ, ZIP_ER_CRC, 0);
fail += do_read(z, "deflatezliberror", 0, WHEN_READ, ZIP_ER_ZLIB, -3);
+#ifndef __clang_analyzer__ /* This test intentionally violates nullability. */
fail += do_read(z, NULL, 0, WHEN_OPEN, ZIP_ER_INVAL, 0);
+#endif
fail += do_read(z, "nosuchfile", 0, WHEN_OPEN, ZIP_ER_NOENT, 0);
fail += do_read(z, "deflatezliberror", ZIP_FL_COMPRESSED, WHEN_NEVER, 0, 0);
fail += do_read(z, "deflatecrcerror", ZIP_FL_COMPRESSED, WHEN_NEVER, 0, 0);
/*
fseek.c -- test tool for seeking in zip archives
- Copyright (C) 2016-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2016-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
if (zip_fseek(zf, offset, SEEK_SET) < 0) {
fprintf(stderr, "%s: zip_fseek failed: %s\n", progname, zip_error_strerror(zip_file_get_error(zf)));
+ zip_fclose(zf);
zip_close(z);
return 1;
}
}
if (n < 0) {
fprintf(stderr, "%s: zip_fread failed: %s\n", progname, zip_error_strerror(zip_file_get_error(zf)));
+ zip_fclose(zf);
zip_close(z);
return 1;
}
+ if (zip_fclose(zf) == -1) {
+ fprintf(stderr, "%s: can't close zip archive entry %" PRIu64 " in '%s': %s\n", progname, index, archive, zip_strerror(z));
+ return 1;
+ }
+
if (zip_close(z) == -1) {
fprintf(stderr, "%s: can't close zip archive '%s': %s\n", progname, archive, zip_strerror(z));
return 1;
--- /dev/null
+#include "zip_read_fuzzer.cc"
+#include <stdio.h>
+#include <stdlib.h>
+
+/* fuzz target entry point, works without libFuzzer */
+
+int main(int argc, char **argv)
+{
+ FILE *f;
+ char *buf = NULL;
+ long siz_buf;
+
+ if (argc < 2) {
+ fprintf(stderr, "no input file\n");
+ goto err;
+ }
+
+ f = fopen(argv[1], "rb");
+ if (f == NULL) {
+ fprintf(stderr, "error opening input file %s\n", argv[1]);
+ goto err;
+ }
+
+ fseek(f, 0, SEEK_END);
+
+ siz_buf = ftell(f);
+ rewind(f);
+
+ if (siz_buf < 1) {
+ goto err;
+ }
+
+ buf = (char*)malloc(siz_buf);
+ if (buf == NULL) {
+ fprintf(stderr, "malloc() failed\n");
+ goto err;
+ }
+
+ if (fread(buf, siz_buf, 1, f) != 1) {
+ fprintf(stderr, "fread() failed\n");
+ goto err;
+ }
+
+ (void)LLVMFuzzerTestOneInput((uint8_t*)buf, siz_buf);
+
+err:
+ free(buf);
+
+ return 0;
+}
/*
hole.c -- convert huge files with mostly NULs to/from source_hole
- Copyright (C) 2014-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
malloc.c -- override *alloc() to allow testing special cases
- Copyright (C) 2015-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2015-2019 Dieter Baron and Thomas Klausner
This file is part of ckmame, a program to check rom sets for MAME.
The authors can be contacted at <ckmame@nih.at>
/*
- nonrandomopen.c -- override zip_random
+ nonrandomopen.c -- override zip_secure_random
- Copyright (C) 2017-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2017-2019 Dieter Baron and Thomas Klausner
This file is part of ckmame, a program to check rom sets for MAME.
The authors can be contacted at <ckmame@nih.at>
#include "zipint.h"
bool
-zip_random(zip_uint8_t *buffer, zip_uint16_t length) {
+zip_secure_random(zip_uint8_t *buffer, zip_uint16_t length) {
memset(buffer, 0, length);
return true;
/*
nonrandomopentest.c -- test nonrandomopen.so
- Copyright (C) 2017-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2017-2019 Dieter Baron and Thomas Klausner
This file is part of ckmame, a program to check rom sets for MAME.
The authors can be contacted at <ckmame@nih.at>
int i;
#ifdef HAVE_CRYPTO
- if (!zip_random(buf, sizeof(buf))) {
- fprintf(stderr, "zip_random returned false\n");
+ if (!zip_secure_random(buf, sizeof(buf))) {
+ fprintf(stderr, "zip_secure_random returned false\n");
exit(1);
}
for (i = 0; i < sizeof(buf); i++) {
program tryopen
file testfile.txt testfile.txt testfile.txt
args testfile.txt
-return 0
-stdout opening 'testfile.txt' succeeded, 0 entries
+return 1
+stdout opening 'testfile.txt' returned error 19
+stderr 1 errors
return 1
stdout opening 'incons-file-count-high.zzip' returned error 21
stdout opening 'incons-file-count-low.zzip' returned error 21
-stdout opening 'incons-file-count-overflow.zzip' returned error 14
+stdout opening 'incons-file-count-overflow.zzip' returned error 21
stderr 3 errors
stdout opening 'incons-eocd-magic-bad.zzip' returned error 19
stdout opening 'incons-file-count-high.zzip' returned error 21
stdout opening 'incons-file-count-low.zzip' returned error 21
-stdout opening 'incons-file-count-overflow.zzip' returned error 14
+stdout opening 'incons-file-count-overflow.zzip' returned error 21
stdout opening 'incons-local-compression-method.zzip' returned error 21
stdout opening 'incons-local-compsize-larger.zzip' returned error 21
stdout opening 'incons-local-compsize-smaller.zzip' returned error 21
--- /dev/null
+#!/bin/bash -eu
+# Copyright 2019 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################
+
+# This script is meant to be run by
+# https://github.com/google/oss-fuzz/blob/master/projects/libzip/Dockerfile
+
+mkdir build
+cd build
+cmake -DBUILD_SHARED_LIBS=OFF -DENABLE_GNUTLS=OFF -DENABLE_MBEDTLS=OFF -DENABLE_OPENSSL=OFF -DBUILD_TOOLS=OFF -DENABLE_LZMA=OFF ..
+make -j$(nproc)
+
+$CXX $CXXFLAGS -std=c++11 -I. -I../lib \
+ $SRC/libzip/regress/zip_read_fuzzer.cc \
+ -o $OUT/zip_read_fuzzer \
+ $LIB_FUZZING_ENGINE $SRC/libzip/build/lib/libzip.a -lz
+
+find $SRC/libzip/regress -name "*.zip" | \
+ xargs zip $OUT/zip_read_fuzzer_seed_corpus.zip
+
+cp $SRC/libzip/regress/zip_read_fuzzer.dict $OUT/
+
--- /dev/null
+# change method from stored to xz-compressed
+features LIBLZMA
+return 0
+args test.zip set_file_compression 0 xz 0
+file test.zip testfile-stored-dos.zip testfile-xz.zip
--- /dev/null
+# change method from xz-compressed to stored
+features LIBLZMA
+return 0
+args test.zip set_file_compression 0 store 0
+file test.zip testfile-xz.zip testfile-stored-dos.zip
--- /dev/null
+# change dostime in a zip archive (use torrentzip default time)
+return 0
+args testfile set_file_dostime 0 48128 8600
+file testfile testfile.zip testfile0.zip
/*
source_hole.c -- source for handling huge files that are mostly NULs
- Copyright (C) 2014-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
tryopen.c -- tool for tests that try opening zip archives
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
#include "compat.h"
#include "zip.h"
-
-const char *usage = "usage: %s [-cent] file\n\n"
- "\t-c\tcheck consistency\n"
- "\t-e\texclusively open archive\n"
- "\t-n\tcreate new file\n"
- "\t-t\ttruncate file to size 0\n";
+#define TRYOPEN_USAGE "usage: %s [-cent] file\n\n" \
+ "\t-c\tcheck consistency\n" \
+ "\t-e\texclusively open archive\n" \
+ "\t-n\tcreate new file\n" \
+ "\t-t\ttruncate file to size 0\n"
int
break;
default:
- fprintf(stderr, usage, argv[0]);
+ fprintf(stderr, TRYOPEN_USAGE, argv[0]);
return 1;
}
}
--- /dev/null
+#include <zip.h>
+
+#ifdef __cplusplus
+extern "C"
+#endif
+int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ zip_source_t *src;
+ zip_t *za;
+ zip_error_t error;
+ char buf[32768];
+ zip_int64_t i, n;
+ zip_file_t *f;
+
+ zip_error_init(&error);
+
+ if ((src = zip_source_buffer_create(data, size, 0, &error)) == NULL) {
+ zip_error_fini(&error);
+ return 0;
+ }
+
+ if ((za = zip_open_from_source(src, 0, &error)) == NULL) {
+ zip_source_free(src);
+ zip_error_fini(&error);
+ return 0;
+ }
+
+ zip_error_fini(&error);
+
+ n = zip_get_num_entries(za, 0);
+
+ for (i = 0; i < n; i++) {
+ f = zip_fopen_index(za, i, 0);
+ if (f == NULL) {
+ continue;
+ }
+
+ while (zip_fread(f, buf, sizeof(buf)) > 0) {
+ ;
+ }
+
+ zip_fclose(f);
+ }
+
+ zip_close(za);
+
+ return 0;
+}
--- /dev/null
+header_lfh="\x50\x4b\x03\x04"
+header_cd="\x50\x4b\x01\x02"
+header_eocd="\x50\x4b\x05\x06"
zip_uint64_t fragment_size = 0;
static int add_nul(int argc, char *argv[]);
+static int cancel(int argc, char *argv[]);
static int unchange_all(int argc, char *argv[]);
static int zin_close(int argc, char *argv[]);
break;
#define DISPATCH_REGRESS \
- {"add_nul", 2, "name length", "add NUL bytes", add_nul}, {"unchange_all", 0, "", "revert all changes", unchange_all}, { "zin_close", 1, "index", "close input zip_source (for internal tests)", zin_close }
+ {"add_nul", 2, "name length", "add NUL bytes", add_nul}, \
+ {"cancel", 1, "limit", "cancel writing archive when limit% have been written (calls print_progress)", cancel}, \
+ {"unchange_all", 0, "", "revert all changes", unchange_all}, \
+ { "zin_close", 1, "index", "close input zip_source (for internal tests)", zin_close }
zip_t *ziptool_open(const char *archive, int flags, zip_error_t *error, zip_uint64_t offset, zip_uint64_t len);
}
static int
+cancel_callback(zip_t *archive, void *ud) {
+ if (progress_userdata.percentage >= progress_userdata.limit) {
+ return -1;
+ }
+ return 0;
+}
+
+static int
+cancel(int argc, char *argv[]) {
+ zip_int64_t percent;
+ percent = strtoll(argv[0], NULL, 10);
+ if (percent > 100 || percent < 0) {
+ fprintf(stderr, "invalid percentage '%" PRId64 "' for cancel (valid: 0 <= x <= 100)\n", percent);
+ return -1;
+ }
+ progress_userdata.limit = ((double)percent)/100;
+
+ zip_register_cancel_callback_with_state(za, cancel_callback, NULL, NULL);
+
+ /* needs the percentage updates from print_progress */
+ print_progress(argc, argv);
+ return 0;
+}
+
+static int
zin_close(int argc, char *argv[]) {
zip_uint64_t idx;
ENDIF(NOT HAVE_GETOPT)
ADD_EXECUTABLE(zipcmp zipcmp.c ${SRC_EXTRA_FILES})
-TARGET_LINK_LIBRARIES(zipcmp zip)
+TARGET_LINK_LIBRARIES(zipcmp zip ${FTS_LIB} ${ZLIB_LIBRARIES})
INSTALL(TARGETS zipcmp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
ADD_EXECUTABLE(zipmerge zipmerge.c ${SRC_EXTRA_FILES})
/*
getopt.h -- header for getopt() replacement function
- Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
/*
zipcmp.c -- compare zip files
- Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
Report bugs to <libzip@nih.at>.\n";
char version_string[] = PROGRAM " (" PACKAGE " " VERSION ")\n\
-Copyright (C) 2003-2018 Dieter Baron and Thomas Klausner\n\
+Copyright (C) 2003-2019 Dieter Baron and Thomas Klausner\n\
" PACKAGE " comes with ABSOLUTELY NO WARRANTY, to the extent permitted by law.\n";
#define OPTIONS "hVipqtv"
if (paranoid) {
if (comment_compare(a[0].comment, a[0].comment_length, a[1].comment, a[1].comment_length) != 0) {
if (verbose) {
- printf("--- archive comment (%ld)\n", a[0].comment_length);
- printf("+++ archive comment (%ld)\n", a[1].comment_length);
+ printf("--- archive comment (%zd)\n", a[0].comment_length);
+ printf("+++ archive comment (%zd)\n", a[1].comment_length);
}
res = 1;
}
}
- for (i = 0; i < 2; i++)
- if (a[i].za)
+ for (i = 0; i < 2; i++) {
+ zip_uint64_t j;
+
+ if (a[i].za) {
zip_close(a[i].za);
+ }
+ for (j = 0; j < a[i].nentry; j++) {
+ free(a[i].entry[j].name);
+ free(a[i].entry[j].extra_fields);
+ }
+ free(a[i].entry);
+ }
switch (res) {
case 0:
/*
zipmerge.c -- merge zip archives
- Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner
+ Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
Report bugs to <libzip@nih.at>.\n";
char version_string[] = PROGRAM " (" PACKAGE " " VERSION ")\n\
-Copyright (C) 2004-2018 Dieter Baron and Thomas Klausner\n\
+Copyright (C) 2004-2019 Dieter Baron and Thomas Klausner\n\
" PACKAGE " comes with ABSOLUTELY NO WARRANTY, to the extent permitted by law.\n";
#define OPTIONS "hVDiIsS"
/*
ziptool.c -- tool for modifying zip archive in multiple ways
- Copyright (C) 2012-2019 Dieter Baron and Thomas Klausner
+ Copyright (C) 2012-2020 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include <time.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
return 0;
}
+struct progress_userdata_s {
+ double percentage;
+ double limit;
+};
+
+struct progress_userdata_s progress_userdata;
+
static void
progress_callback(zip_t *archive, double percentage, void *ud) {
printf("%.1lf%% done\n", percentage * 100);
+ progress_userdata.percentage = percentage;
}
static int
}
static int
+set_file_dostime(int argc, char *argv[]) {
+ /* set file last modification time (mtime) directly */
+ time_t mtime;
+ zip_uint16_t dostime, dosdate;
+ zip_uint64_t idx;
+ idx = strtoull(argv[0], NULL, 10);
+ dostime = (time_t)strtoull(argv[1], NULL, 10);
+ dosdate = (time_t)strtoull(argv[2], NULL, 10);
+ if (zip_file_set_dostime(za, idx, dostime, dosdate, 0) < 0) {
+ fprintf(stderr, "can't set file dostime at index '%" PRIu64 "' to '%d'/'%d': %s\n", idx, (int)dostime, (int)dosdate, zip_strerror(za));
+ return -1;
+ }
+ return 0;
+}
+
+static int
set_file_mtime(int argc, char *argv[]) {
/* set file last modification time (mtime) */
time_t mtime;
idx = strtoull(argv[0], NULL, 10);
mtime = (time_t)strtoull(argv[1], NULL, 10);
if (zip_file_set_mtime(za, idx, mtime, 0) < 0) {
- fprintf(stderr, "can't set file mtime at index '%" PRIu64 "' to '%ld': %s\n", idx, mtime, zip_strerror(za));
+ fprintf(stderr, "can't set file mtime at index '%" PRIu64 "' to '%lld': %s\n", idx, (long long)mtime, zip_strerror(za));
return -1;
}
return 0;
}
for (idx = 0; idx < (zip_uint64_t)num_entries; idx++) {
if (zip_file_set_mtime(za, idx, mtime, 0) < 0) {
- fprintf(stderr, "can't set file mtime at index '%" PRIu64 "' to '%ld': %s\n", idx, mtime, zip_strerror(za));
+ fprintf(stderr, "can't set file mtime at index '%" PRIu64 "' to '%lld': %s\n", idx, (long long)mtime, zip_strerror(za));
return -1;
}
}
printf("compressed size: '%" PRIu64 "'\n", sb.comp_size);
if (sb.valid & ZIP_STAT_MTIME) {
struct tm *tpm;
+#ifdef HAVE_LOCALTIME_R
+ struct tm tm;
+ tpm = localtime_r(&sb.mtime, &tm);
+#else
tpm = localtime(&sb.mtime);
+#endif
if (tpm == NULL) {
printf("mtime: <not valid>\n");
} else {
else if (strcmp(arg, "bzip2") == 0)
return ZIP_CM_BZIP2;
#endif
+#if defined(HAVE_LIBLZMA)
+/* Disabled - because 7z isn't able to unpack ZIP+LZMA ZIP+LZMA2
+ archives made this way - and vice versa.
+
+ else if (strcmp(arg, "lzma") == 0)
+ return ZIP_CM_LZMA;
+ else if (strcmp(arg, "lzma2") == 0)
+ return ZIP_CM_LZMA2;
+*/
+ else if (strcmp(arg, "xz") == 0)
+ return ZIP_CM_XZ;
+
+#endif
else if (strcmp(arg, "unknown") == 0)
return 100;
return 0; /* TODO: error handling */
{"set_extra", 5, "index extra_id extra_index flags value", "set extra field", set_extra},
{"set_file_comment", 2, "index comment", "set file comment", set_file_comment},
{"set_file_compression", 3, "index method compression_flags", "set file compression method", set_file_compression},
+ {"set_file_dostime", 3, "index time date", "set file modification time and date (DOS format)", set_file_dostime},
{"set_file_encryption", 3, "index method password", "set file encryption method", set_file_encryption},
{"set_file_mtime", 2, "index timestamp", "set file modification time", set_file_mtime},
{"set_file_mtime_all", 1, "timestamp", "set file modification time for all files", set_file_mtime_all},