diff options
135 files changed, 1809 insertions, 1312 deletions
diff --git a/.gitlab/os-windows.yml b/.gitlab/os-windows.yml index 90ff0a8..8037b33 100644 --- a/.gitlab/os-windows.yml +++ b/.gitlab/os-windows.yml @@ -38,7 +38,7 @@ CMAKE_CONFIGURATION: windows_vs2019_x64_ninja VCVARSALL: "${VS160COMNTOOLS}\\..\\..\\VC\\Auxiliary\\Build\\vcvarsall.bat" VCVARSPLATFORM: "x64" - VCVARSVERSION: "14.29.30037" + VCVARSVERSION: "14.29.30133" ### External testing @@ -49,7 +49,7 @@ CMAKE_CONFIGURATION: windows_vs2019_x64 CMAKE_GENERATOR: "Visual Studio 16 2019" CMAKE_GENERATOR_PLATFORM: "x64" - CMAKE_GENERATOR_TOOLSET: "v142,version=14.29.30037" + CMAKE_GENERATOR_TOOLSET: "v142,version=14.29.30133" CMAKE_CI_NIGHTLY_IGNORE_DEPS: "true" ## Tags @@ -60,7 +60,7 @@ - windows - shell - vs2019 - - msvc-19.29-16.10 + - msvc-19.29-16.11 - nonconcurrent .windows_builder_ext_tags: @@ -69,7 +69,7 @@ - windows - shell - vs2019 - - msvc-19.29-16.10 + - msvc-19.29-16.11 - concurrent ## Windows-specific scripts diff --git a/Help/command/if.rst b/Help/command/if.rst index fbf3e36..6ff8852 100644 --- a/Help/command/if.rst +++ b/Help/command/if.rst @@ -171,7 +171,7 @@ Comparisons ``if(<variable|string> MATCHES regex)`` True if the given string or variable's value matches the given regular - condition. See :ref:`Regex Specification` for regex format. + expression. See :ref:`Regex Specification` for regex format. .. versionadded:: 3.9 ``()`` groups are captured in :variable:`CMAKE_MATCH_<n>` variables. diff --git a/Help/manual/cmake-packages.7.rst b/Help/manual/cmake-packages.7.rst index 5262105..5c109ff 100644 --- a/Help/manual/cmake-packages.7.rst +++ b/Help/manual/cmake-packages.7.rst @@ -449,7 +449,7 @@ be true. This can be tested with logic in the package configuration file: set(_supported_components Plot Table) foreach(_comp ${ClimbingStats_FIND_COMPONENTS}) - if (NOT ";${_supported_components};" MATCHES _comp) + if (NOT ";${_supported_components};" MATCHES ";${_comp};") set(ClimbingStats_FOUND False) set(ClimbingStats_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}") endif() diff --git a/Help/prop_tgt/AUTOMOC.rst b/Help/prop_tgt/AUTOMOC.rst index 52d96e0..ed8b262 100644 --- a/Help/prop_tgt/AUTOMOC.rst +++ b/Help/prop_tgt/AUTOMOC.rst @@ -4,9 +4,9 @@ AUTOMOC Should the target be processed with auto-moc (for Qt projects). :prop_tgt:`AUTOMOC` is a boolean specifying whether CMake will handle the Qt -``moc`` preprocessor automatically, i.e. without having to use the -:module:`QT4_WRAP_CPP() <FindQt4>` or ``QT5_WRAP_CPP()`` macro. -Currently Qt4 and Qt5 are supported. +``moc`` preprocessor automatically, i.e. without having to use commands like +:module:`QT4_WRAP_CPP() <FindQt4>`, ``QT5_WRAP_CPP()``, etc. +Currently, Qt versions 4 to 6 are supported. This property is initialized by the value of the :variable:`CMAKE_AUTOMOC` variable if it is set when a target is created. @@ -148,10 +148,13 @@ Qt version detection :prop_tgt:`AUTOMOC` enabled targets need to know the Qt major and minor version they're working with. The major version usually is provided by the -``INTERFACE_QT_MAJOR_VERSION`` property of the ``Qt[45]Core`` library, +``INTERFACE_QT_MAJOR_VERSION`` property of the ``Qt[456]Core`` library, that the target links to. To find the minor version, CMake builds a list of available Qt versions from +- ``Qt6Core_VERSION_MAJOR`` and ``Qt6Core_VERSION_MINOR`` variables + (usually set by ``find_package(Qt6...)``) +- ``Qt6Core_VERSION_MAJOR`` and ``Qt6Core_VERSION_MINOR`` directory properties - ``Qt5Core_VERSION_MAJOR`` and ``Qt5Core_VERSION_MINOR`` variables (usually set by ``find_package(Qt5...)``) - ``Qt5Core_VERSION_MAJOR`` and ``Qt5Core_VERSION_MINOR`` directory properties @@ -167,13 +170,13 @@ version was found, an error is generated. If ``INTERFACE_QT_MAJOR_VERSION`` is not a valid number, the first entry in the list is taken. -A ``find_package(Qt[45]...)`` call sets the ``QT/Qt5Core_VERSION_MAJOR/MINOR`` +A ``find_package(Qt[456]...)`` call sets the ``QT/Qt[56]Core_VERSION_MAJOR/MINOR`` variables. If the call is in a different context than the :command:`add_executable` or :command:`add_library` call, e.g. in a function, then the version variables might not be available to the :prop_tgt:`AUTOMOC` enabled target. In that case the version variables can be forwarded from the -``find_package(Qt[45]...)`` calling context to the :command:`add_executable` +``find_package(Qt[456]...)`` calling context to the :command:`add_executable` or :command:`add_library` calling context as directory properties. The following Qt5 example demonstrates the procedure. diff --git a/Help/prop_tgt/AUTORCC.rst b/Help/prop_tgt/AUTORCC.rst index 9a98f44..0a0c2a1 100644 --- a/Help/prop_tgt/AUTORCC.rst +++ b/Help/prop_tgt/AUTORCC.rst @@ -5,8 +5,8 @@ Should the target be processed with auto-rcc (for Qt projects). :prop_tgt:`AUTORCC` is a boolean specifying whether CMake will handle the Qt ``rcc`` code generator automatically, i.e. without having to use -the :module:`QT4_ADD_RESOURCES() <FindQt4>` or ``QT5_ADD_RESOURCES()`` -macro. Currently Qt4 and Qt5 are supported. +commands like :module:`QT4_ADD_RESOURCES() <FindQt4>`, ``QT5_ADD_RESOURCES()``, +etc. Currently, Qt versions 4 to 6 are supported. When this property is ``ON``, CMake will handle ``.qrc`` files added as target sources at build time and invoke ``rcc`` accordingly. diff --git a/Help/prop_tgt/AUTOUIC.rst b/Help/prop_tgt/AUTOUIC.rst index cd24f5e..e0cea97 100644 --- a/Help/prop_tgt/AUTOUIC.rst +++ b/Help/prop_tgt/AUTOUIC.rst @@ -5,8 +5,8 @@ Should the target be processed with auto-uic (for Qt projects). :prop_tgt:`AUTOUIC` is a boolean specifying whether CMake will handle the Qt ``uic`` code generator automatically, i.e. without having to use -the :module:`QT4_WRAP_UI() <FindQt4>` or ``QT5_WRAP_UI()`` macro. Currently -Qt4 and Qt5 are supported. +commands like :module:`QT4_WRAP_UI() <FindQt4>`, ``QT5_WRAP_UI()``, etc. +Currently, Qt versions 4 to 6 are supported. This property is initialized by the value of the :variable:`CMAKE_AUTOUIC` variable if it is set when a target is created. diff --git a/Help/variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES.rst b/Help/variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES.rst index e9e04be..081c4da 100644 --- a/Help/variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES.rst +++ b/Help/variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES.rst @@ -6,8 +6,20 @@ Implicit linker search path detected for language ``<LANG>``. Compilers typically pass directories containing language runtime libraries and default library search paths when they invoke a linker. These paths are implicit linker search directories for the compiler's -language. CMake automatically detects these directories for each -language and reports the results in this variable. +language. For each language enabled by the :command:`project` or +:command:`enable_language` command, CMake automatically detects these +directories and reports the results in this variable. + +When linking to a static library, CMake adds the implicit link directories +from this variable for each language used in the static library (except +the language whose compiler is used to drive linking). In the case of an +imported static library, the :prop_tgt:`IMPORTED_LINK_INTERFACE_LANGUAGES` +target property lists the languages whose implicit link information is +needed. If any of the languages is not enabled, its value for the +``CMAKE_<LANG>_IMPLICIT_LINK_DIRECTORIES`` variable may instead be provided +by the project. Or, a :variable:`toolchain file <CMAKE_TOOLCHAIN_FILE>` +may set the variable to a value known for the specified toolchain. It will +either be overridden when the language is enabled, or used as a fallback. Some toolchains read implicit directories from an environment variable such as ``LIBRARY_PATH``. If using such an environment variable, keep its value @@ -18,3 +30,5 @@ If policy :policy:`CMP0060` is not set to ``NEW``, then when a library in one of these directories is given by full path to :command:`target_link_libraries` CMake will generate the ``-l<name>`` form on link lines for historical purposes. + +See also the :variable:`CMAKE_<LANG>_IMPLICIT_LINK_LIBRARIES` variable. diff --git a/Help/variable/CMAKE_LANG_IMPLICIT_LINK_LIBRARIES.rst b/Help/variable/CMAKE_LANG_IMPLICIT_LINK_LIBRARIES.rst index ec16477..0c25489 100644 --- a/Help/variable/CMAKE_LANG_IMPLICIT_LINK_LIBRARIES.rst +++ b/Help/variable/CMAKE_LANG_IMPLICIT_LINK_LIBRARIES.rst @@ -5,6 +5,20 @@ Implicit link libraries and flags detected for language ``<LANG>``. Compilers typically pass language runtime library names and other flags when they invoke a linker. These flags are implicit link -options for the compiler's language. CMake automatically detects -these libraries and flags for each language and reports the results in -this variable. +options for the compiler's language. For each language enabled +by the :command:`project` or :command:`enable_language` command, +CMake automatically detects these libraries and flags and reports +the results in this variable. + +When linking to a static library, CMake adds the implicit link libraries and +flags from this variable for each language used in the static library (except +the language whose compiler is used to drive linking). In the case of an +imported static library, the :prop_tgt:`IMPORTED_LINK_INTERFACE_LANGUAGES` +target property lists the languages whose implicit link information is +needed. If any of the languages is not enabled, its value for the +``CMAKE_<LANG>_IMPLICIT_LINK_LIBRARIES`` variable may instead be provided +by the project. Or, a :variable:`toolchain file <CMAKE_TOOLCHAIN_FILE>` +may set the variable to a value known for the specified toolchain. It will +either be overridden when the language is enabled, or used as a fallback. + +See also the :variable:`CMAKE_<LANG>_IMPLICIT_LINK_DIRECTORIES` variable. diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake index f7605c4..38faca2 100644 --- a/Modules/FindBoost.cmake +++ b/Modules/FindBoost.cmake @@ -1335,7 +1335,7 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret) set(_Boost_TIMER_DEPENDENCIES chrono) set(_Boost_WAVE_DEPENDENCIES filesystem serialization thread chrono date_time atomic) set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - else() + elseif(Boost_VERSION_STRING VERSION_LESS 1.77.0) set(_Boost_CONTRACT_DEPENDENCIES thread chrono date_time) set(_Boost_COROUTINE_DEPENDENCIES context) set(_Boost_FIBER_DEPENDENCIES context) @@ -1350,7 +1350,22 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret) set(_Boost_TIMER_DEPENDENCIES chrono) set(_Boost_WAVE_DEPENDENCIES filesystem serialization thread chrono date_time atomic) set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - if(Boost_VERSION_STRING VERSION_GREATER_EQUAL 1.77.0 AND NOT Boost_NO_WARN_NEW_VERSIONS) + else() + set(_Boost_CONTRACT_DEPENDENCIES thread chrono) + set(_Boost_COROUTINE_DEPENDENCIES context) + set(_Boost_FIBER_DEPENDENCIES context) + set(_Boost_IOSTREAMS_DEPENDENCIES regex) + set(_Boost_JSON_DEPENDENCIES container) + set(_Boost_LOG_DEPENDENCIES date_time log_setup filesystem thread regex chrono atomic) + set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l) + set(_Boost_MPI_DEPENDENCIES serialization) + set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization) + set(_Boost_NUMPY_DEPENDENCIES python${component_python_version}) + set(_Boost_THREAD_DEPENDENCIES chrono atomic) + set(_Boost_TIMER_DEPENDENCIES chrono) + set(_Boost_WAVE_DEPENDENCIES filesystem serialization thread chrono atomic) + set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) + if(Boost_VERSION_STRING VERSION_GREATER_EQUAL 1.78.0 AND NOT Boost_NO_WARN_NEW_VERSIONS) message(WARNING "New Boost version may have incorrect or missing dependencies and imported targets") endif() endif() @@ -1623,7 +1638,7 @@ else() # _Boost_COMPONENT_HEADERS. See the instructions at the top of # _Boost_COMPONENT_DEPENDENCIES. set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS} - "1.76.0" "1.76" "1.75.0" "1.75" "1.74.0" "1.74" + "1.77.0" "1.77" "1.76.0" "1.76" "1.75.0" "1.75" "1.74.0" "1.74" "1.73.0" "1.73" "1.72.0" "1.72" "1.71.0" "1.71" "1.70.0" "1.70" "1.69.0" "1.69" "1.68.0" "1.68" "1.67.0" "1.67" "1.66.0" "1.66" "1.65.1" "1.65.0" "1.65" "1.64.0" "1.64" "1.63.0" "1.63" "1.62.0" "1.62" "1.61.0" "1.61" "1.60.0" "1.60" diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index 8e70e11..ce25cfc 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -98,6 +98,7 @@ macro (_PYTHON_FIND_FRAMEWORKS) ${_pff_CMAKE_FRAMEWORK_PATH} ~/Library/Frameworks /usr/local/Frameworks + /opt/homebrew/Frameworks ${CMAKE_SYSTEM_FRAMEWORK_PATH}) list (REMOVE_DUPLICATES _pff_frameworks) foreach (_pff_implementation IN LISTS _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS) diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake index c6a3451..e4d6cf3 100644 --- a/Modules/FindThreads.cmake +++ b/Modules/FindThreads.cmake @@ -106,7 +106,7 @@ endmacro() # Do NOT even think about using it outside of this file! macro(_check_pthreads_flag) if(NOT Threads_FOUND) - # If we did not found -lpthread, -lpthread, or -lthread, look for -pthread + # If we did not find -lpthreads, -lpthread, or -lthread, look for -pthread if(NOT DEFINED THREADS_HAVE_PTHREAD_ARG) message(CHECK_START "Check if compiler accepts -pthread") if(CMAKE_C_COMPILER_LOADED) diff --git a/Modules/InstallRequiredSystemLibraries.cmake b/Modules/InstallRequiredSystemLibraries.cmake index b2af6c9..4d3bfe2 100644 --- a/Modules/InstallRequiredSystemLibraries.cmake +++ b/Modules/InstallRequiredSystemLibraries.cmake @@ -237,8 +237,12 @@ if(MSVC) set(_MSVC_IDE_VERSION "") if(MSVC_VERSION GREATER_EQUAL 2000) message(WARNING "MSVC ${MSVC_VERSION} not yet supported.") - elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 143) + elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 144) message(WARNING "MSVC toolset v${MSVC_TOOLSET_VERSION} not yet supported.") + elseif(MSVC_TOOLSET_VERSION EQUAL 143) + set(MSVC_REDIST_NAME VC142) + set(_MSVC_DLL_VERSION 140) + set(_MSVC_IDE_VERSION 17) elseif(MSVC_TOOLSET_VERSION EQUAL 142) set(MSVC_REDIST_NAME VC142) set(_MSVC_DLL_VERSION 140) @@ -279,7 +283,7 @@ if(MSVC) if(NOT vs VERSION_LESS 15) set(_vs_redist_paths "") # The toolset and its redistributables may come with any VS version 15 or newer. - set(_MSVC_IDE_VERSIONS 16 15) + set(_MSVC_IDE_VERSIONS 17 16 15) foreach(_vs_ver ${_MSVC_IDE_VERSIONS}) set(_vs_glob_redist_paths "") cmake_host_system_information(RESULT _vs_dir QUERY VS_${_vs_ver}_DIR) # undocumented query diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake index 4223bde..7d602c3 100644 --- a/Modules/Platform/Windows-MSVC.cmake +++ b/Modules/Platform/Windows-MSVC.cmake @@ -67,7 +67,10 @@ if(NOT MSVC_VERSION) message(FATAL_ERROR "MSVC compiler version not detected properly: ${_compiler_version}") endif() - if(MSVC_VERSION GREATER_EQUAL 1920) + if(MSVC_VERSION GREATER_EQUAL 1930) + # VS 2022 or greater + set(MSVC_TOOLSET_VERSION 143) + elseif(MSVC_VERSION GREATER_EQUAL 1920) # VS 2019 or greater set(MSVC_TOOLSET_VERSION 142) elseif(MSVC_VERSION GREATER_EQUAL 1910) diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index a195611..6e3cf1f 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,7 +1,7 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 21) -set(CMake_VERSION_PATCH 20210828) +set(CMake_VERSION_PATCH 20210910) #set(CMake_VERSION_RC 0) set(CMake_VERSION_IS_DIRTY 0) diff --git a/Source/cmAddTestCommand.cxx b/Source/cmAddTestCommand.cxx index 205c1c7..a0d5732 100644 --- a/Source/cmAddTestCommand.cxx +++ b/Source/cmAddTestCommand.cxx @@ -140,7 +140,7 @@ bool cmAddTestCommandHandleNameMode(std::vector<std::string> const& args, test->SetOldStyle(false); test->SetCommand(command); if (!working_directory.empty()) { - test->SetProperty("WORKING_DIRECTORY", working_directory.c_str()); + test->SetProperty("WORKING_DIRECTORY", working_directory); } test->SetCommandExpandLists(command_expand_lists); mf.AddTestGenerator(cm::make_unique<cmTestGenerator>(test, configurations)); diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index c192e2a..a1830f9 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -60,6 +60,10 @@ class cmListFileBacktrace; using cmBacktraceRange = cmRange<std::vector<cmListFileBacktrace>::const_iterator>; +template <typename T> +class BT; +using cmBTStringRange = cmRange<std::vector<BT<std::string>>::const_iterator>; + template <typename Range> typename Range::const_iterator cmRemoveN(Range& r, size_t n) { @@ -133,7 +137,13 @@ ForwardIterator cmRemoveDuplicates(ForwardIterator first, ForwardIterator last) } template <typename Range> -typename Range::const_iterator cmRemoveDuplicates(Range& r) +typename Range::iterator cmRemoveDuplicates(Range& r) +{ + return cmRemoveDuplicates(r.begin(), r.end()); +} + +template <typename Range> +typename Range::const_iterator cmRemoveDuplicates(Range const& r) { return cmRemoveDuplicates(r.begin(), r.end()); } diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index ace7382..e922ee5 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -173,7 +173,7 @@ void CCONV cmAddLinkDirectoryForTarget(void* arg, const char* tgt, std::string(tgt) + " for directory " + std::string(d)); return; } - t->InsertLinkDirectory(d, mf->GetBacktrace()); + t->InsertLinkDirectory(BT<std::string>(d, mf->GetBacktrace())); } void CCONV cmAddExecutable(void* arg, const char* exename, int numSrcs, diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index 0b27e34..15a12ba 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -607,7 +607,7 @@ cmLinkItem cmComputeLinkDepends::ResolveLinkItem(int depender_index, from = depender; } } - return from->ResolveLinkItem(name, cmListFileBacktrace()); + return from->ResolveLinkItem(BT<std::string>(name)); } void cmComputeLinkDepends::InferDependencies() diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx index 76712f4..5d3e04f 100644 --- a/Source/cmComputeTargetDepends.cxx +++ b/Source/cmComputeTargetDepends.cxx @@ -323,7 +323,7 @@ void cmComputeTargetDepends::AddObjectDepends(int depender_index, } cmGeneratorTarget const* depender = this->Targets[depender_index]; cmLinkItem const& objItem = - depender->ResolveLinkItem(objLib, cmListFileBacktrace()); + depender->ResolveLinkItem(BT<std::string>(objLib)); if (emitted.insert(objItem).second) { if (depender->GetType() != cmStateEnums::EXECUTABLE && depender->GetType() != cmStateEnums::STATIC_LIBRARY && diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 3201ae3..648708a 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -145,12 +145,10 @@ private: class TargetPropertyEntryString : public cmGeneratorTarget::TargetPropertyEntry { public: - TargetPropertyEntryString(std::string propertyValue, - cmListFileBacktrace backtrace, + TargetPropertyEntryString(BT<std::string> propertyValue, cmLinkImplItem const& item = NoLinkImplItem) : cmGeneratorTarget::TargetPropertyEntry(item) , PropertyValue(std::move(propertyValue)) - , Backtrace(std::move(backtrace)) { } @@ -159,46 +157,46 @@ public: cmGeneratorExpressionDAGChecker*, std::string const&) const override { - return this->PropertyValue; + return this->PropertyValue.Value; } - cmListFileBacktrace GetBacktrace() const override { return this->Backtrace; } - std::string const& GetInput() const override { return this->PropertyValue; } + cmListFileBacktrace GetBacktrace() const override + { + return this->PropertyValue.Backtrace; + } + std::string const& GetInput() const override + { + return this->PropertyValue.Value; + } private: - std::string PropertyValue; - cmListFileBacktrace Backtrace; + BT<std::string> PropertyValue; }; std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry> -CreateTargetPropertyEntry( - const std::string& propertyValue, - cmListFileBacktrace backtrace = cmListFileBacktrace(), - bool evaluateForBuildsystem = false) +CreateTargetPropertyEntry(const BT<std::string>& propertyValue, + bool evaluateForBuildsystem = false) { - if (cmGeneratorExpression::Find(propertyValue) != std::string::npos) { - cmGeneratorExpression ge(std::move(backtrace)); + if (cmGeneratorExpression::Find(propertyValue.Value) != std::string::npos) { + cmGeneratorExpression ge(propertyValue.Backtrace); std::unique_ptr<cmCompiledGeneratorExpression> cge = - ge.Parse(propertyValue); + ge.Parse(propertyValue.Value); cge->SetEvaluateForBuildsystem(evaluateForBuildsystem); return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>( cm::make_unique<TargetPropertyEntryGenex>(std::move(cge))); } return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>( - cm::make_unique<TargetPropertyEntryString>(propertyValue, - std::move(backtrace))); + cm::make_unique<TargetPropertyEntryString>(propertyValue)); } void CreatePropertyGeneratorExpressions( - cmStringRange entries, cmBacktraceRange backtraces, + cmBTStringRange entries, std::vector<std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>>& items, bool evaluateForBuildsystem = false) { - auto btIt = backtraces.begin(); - for (auto it = entries.begin(); it != entries.end(); ++it, ++btIt) { - items.push_back( - CreateTargetPropertyEntry(*it, *btIt, evaluateForBuildsystem)); + for (auto const& entry : entries) { + items.push_back(CreateTargetPropertyEntry(entry, evaluateForBuildsystem)); } } @@ -289,35 +287,27 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) this->GlobalGenerator->ComputeTargetObjectDirectory(this); CreatePropertyGeneratorExpressions(t->GetIncludeDirectoriesEntries(), - t->GetIncludeDirectoriesBacktraces(), this->IncludeDirectoriesEntries); CreatePropertyGeneratorExpressions(t->GetCompileOptionsEntries(), - t->GetCompileOptionsBacktraces(), this->CompileOptionsEntries); CreatePropertyGeneratorExpressions(t->GetCompileFeaturesEntries(), - t->GetCompileFeaturesBacktraces(), this->CompileFeaturesEntries); CreatePropertyGeneratorExpressions(t->GetCompileDefinitionsEntries(), - t->GetCompileDefinitionsBacktraces(), this->CompileDefinitionsEntries); CreatePropertyGeneratorExpressions(t->GetLinkOptionsEntries(), - t->GetLinkOptionsBacktraces(), this->LinkOptionsEntries); CreatePropertyGeneratorExpressions(t->GetLinkDirectoriesEntries(), - t->GetLinkDirectoriesBacktraces(), this->LinkDirectoriesEntries); CreatePropertyGeneratorExpressions(t->GetPrecompileHeadersEntries(), - t->GetPrecompileHeadersBacktraces(), this->PrecompileHeadersEntries); CreatePropertyGeneratorExpressions(t->GetSourceEntries(), - t->GetSourceBacktraces(), this->SourceEntries, true); this->PolicyMap = t->GetPolicyMap(); @@ -698,7 +688,8 @@ void cmGeneratorTarget::AddSourceCommon(const std::string& src, bool before) { this->SourceEntries.insert( before ? this->SourceEntries.begin() : this->SourceEntries.end(), - CreateTargetPropertyEntry(src, this->Makefile->GetBacktrace(), true)); + CreateTargetPropertyEntry( + BT<std::string>(src, this->Makefile->GetBacktrace()), true)); this->ClearSourcesCache(); } @@ -719,11 +710,13 @@ void cmGeneratorTarget::AddTracedSources(std::vector<std::string> const& srcs) void cmGeneratorTarget::AddIncludeDirectory(const std::string& src, bool before) { - this->Target->InsertInclude(src, this->Makefile->GetBacktrace(), before); + this->Target->InsertInclude( + BT<std::string>(src, this->Makefile->GetBacktrace()), before); this->IncludeDirectoriesEntries.insert( before ? this->IncludeDirectoriesEntries.begin() : this->IncludeDirectoriesEntries.end(), - CreateTargetPropertyEntry(src, this->Makefile->GetBacktrace(), true)); + CreateTargetPropertyEntry( + BT<std::string>(src, this->Makefile->GetBacktrace()), true)); } std::vector<cmSourceFile*> const* cmGeneratorTarget::GetSourceDepends( @@ -1675,9 +1668,9 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths( // for TARGET_OBJECTS instead for backwards compatibility with OLD // behavior of CMP0024 and CMP0026 only. - cmStringRange sourceEntries = this->Target->GetSourceEntries(); - for (std::string const& entry : sourceEntries) { - std::vector<std::string> items = cmExpandedList(entry); + cmBTStringRange sourceEntries = this->Target->GetSourceEntries(); + for (auto const& entry : sourceEntries) { + std::vector<std::string> items = cmExpandedList(entry.Value); for (std::string const& item : items) { if (cmHasLiteralPrefix(item, "$<TARGET_OBJECTS:") && item.back() == '>') { @@ -6364,7 +6357,7 @@ cm::optional<cmLinkItem> cmGeneratorTarget::LookupLinkItem( if (name == this->GetName() || name.empty()) { return maybeItem; } - maybeItem = this->ResolveLinkItem(name, bt, scope->LG); + maybeItem = this->ResolveLinkItem(BT<std::string>(name, bt), scope->LG); return maybeItem; } @@ -7377,9 +7370,9 @@ void cmGeneratorTarget::GetObjectLibrariesCMP0026( // there is no cmGeneratorTarget at configure-time, so search the SOURCES // for TARGET_OBJECTS instead for backwards compatibility with OLD // behavior of CMP0024 and CMP0026 only. - cmStringRange rng = this->Target->GetSourceEntries(); - for (std::string const& entry : rng) { - std::vector<std::string> files = cmExpandedList(entry); + cmBTStringRange rng = this->Target->GetSourceEntries(); + for (auto const& entry : rng) { + std::vector<std::string> files = cmExpandedList(entry.Value); for (std::string const& li : files) { if (cmHasLiteralPrefix(li, "$<TARGET_OBJECTS:") && li.back() == '>') { std::string objLibName = li.substr(17, li.size() - 18); @@ -7607,24 +7600,21 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( { cmLocalGenerator const* lg = this->LocalGenerator; cmMakefile const* mf = lg->GetMakefile(); - cmStringRange entryRange = this->Target->GetLinkImplementationEntries(); - cmBacktraceRange btRange = this->Target->GetLinkImplementationBacktraces(); - cmBacktraceRange::const_iterator btIt = btRange.begin(); + cmBTStringRange entryRange = this->Target->GetLinkImplementationEntries(); // Collect libraries directly linked in this configuration. - for (cmStringRange::const_iterator le = entryRange.begin(), - end = entryRange.end(); - le != end; ++le, ++btIt) { + for (auto const& entry : entryRange) { std::vector<std::string> llibs; // Keep this logic in sync with ExpandLinkItems. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_LIBRARIES", nullptr, nullptr); - cmGeneratorExpression ge(*btIt); - std::unique_ptr<cmCompiledGeneratorExpression> const cge = ge.Parse(*le); + cmGeneratorExpression ge(entry.Backtrace); + std::unique_ptr<cmCompiledGeneratorExpression> const cge = + ge.Parse(entry.Value); cge->SetEvaluateForBuildsystem(true); std::string const& evaluated = cge->Evaluate(this->LocalGenerator, config, head, &dagChecker, nullptr, this->LinkerLanguage); - bool const fromGenex = evaluated != *le; + bool const fromGenex = evaluated != entry.Value; cmExpandList(evaluated, llibs); if (cge->GetHadHeadSensitiveCondition()) { impl.HadHeadSensitiveCondition = true; @@ -7682,7 +7672,8 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( } // The entry is meant for this configuration. - cmLinkItem item = this->ResolveLinkItem(name, *btIt, lg); + cmLinkItem item = + this->ResolveLinkItem(BT<std::string>(name, entry.Backtrace), lg); if (!item.Target) { // Report explicitly linked object files separately. std::string const& maybeObj = item.AsStr(); @@ -7724,7 +7715,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( } // Support OLD behavior for CMP0003. impl.WrongConfigLibraries.push_back( - this->ResolveLinkItem(name, cmListFileBacktrace())); + this->ResolveLinkItem(BT<std::string>(name))); } } } @@ -7750,16 +7741,16 @@ cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference( } cmLinkItem cmGeneratorTarget::ResolveLinkItem( - std::string const& name, cmListFileBacktrace const& bt) const + BT<std::string> const& name) const { - return this->ResolveLinkItem(name, bt, this->LocalGenerator); + return this->ResolveLinkItem(name, this->LocalGenerator); } -cmLinkItem cmGeneratorTarget::ResolveLinkItem(std::string const& name, - cmListFileBacktrace const& bt, +cmLinkItem cmGeneratorTarget::ResolveLinkItem(BT<std::string> const& name, cmLocalGenerator const* lg) const { - TargetOrString resolved = this->ResolveTargetReference(name, lg); + auto bt = name.Backtrace; + TargetOrString resolved = this->ResolveTargetReference(name.Value, lg); if (!resolved.Target) { return cmLinkItem(resolved.String, false, bt); diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index bb46211..0076085 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -409,10 +409,8 @@ public: TargetOrString ResolveTargetReference(std::string const& name, cmLocalGenerator const* lg) const; - cmLinkItem ResolveLinkItem(std::string const& name, - cmListFileBacktrace const& bt) const; - cmLinkItem ResolveLinkItem(std::string const& name, - cmListFileBacktrace const& bt, + cmLinkItem ResolveLinkItem(BT<std::string> const& name) const; + cmLinkItem ResolveLinkItem(BT<std::string> const& name, cmLocalGenerator const* lg) const; // Compute the set of languages compiled by the target. This is diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 3561deb..17cd95e 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1718,10 +1718,8 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo() // Construct per-target generator information. for (const auto& mf : this->Makefiles) { - const cmStringRange noconfig_compile_definitions = + const cmBTStringRange noconfig_compile_definitions = mf->GetCompileDefinitionsEntries(); - const cmBacktraceRange noconfig_compile_definitions_bts = - mf->GetCompileDefinitionsBacktraces(); for (auto& target : mf->GetTargets()) { cmTarget* t = &target.second; @@ -1735,12 +1733,8 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo() continue; } - { - auto btIt = noconfig_compile_definitions_bts.begin(); - auto it = noconfig_compile_definitions.begin(); - for (; it != noconfig_compile_definitions.end(); ++it, ++btIt) { - t->InsertCompileDefinition(*it, *btIt); - } + for (auto const& def : noconfig_compile_definitions) { + t->InsertCompileDefinition(def); } cmPolicies::PolicyStatus polSt = diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 47a931d..c6f82f9 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -945,6 +945,8 @@ void cmGlobalNinjaGenerator::EnableLanguage( (mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "GNU") || (mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") == "Clang") || (mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "Clang") || + (mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") == "ARMClang") || + (mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "ARMClang") || (mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") == "QCC") || (mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "QCC")))) { this->UsingGCCOnWindows = true; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 3994816..763f12a 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1667,7 +1667,7 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmGeneratorTarget* gtgt) fout << "\n"; } if (cmSourceFile* sf = mf->GetOrCreateSource(fname)) { - sf->SetProperty("LANGUAGE", llang.c_str()); + sf->SetProperty("LANGUAGE", llang); gtgt->AddSource(fname); } } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 74130dd..5fe5c75 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2553,10 +2553,10 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target) continue; } - const std::string pchExtension = - this->Makefile->GetSafeDefinition("CMAKE_PCH_EXTENSION"); + cmProp pchExtension = + this->Makefile->GetDefinition("CMAKE_PCH_EXTENSION"); - if (pchExtension.empty()) { + if (pchExtension.IsEmpty()) { continue; } @@ -2647,7 +2647,7 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target) } } } else { - pch_sf->SetProperty("PCH_EXTENSION", pchExtension.c_str()); + pch_sf->SetProperty("PCH_EXTENSION", pchExtension); } // Add pchHeader to source files, which will @@ -2788,7 +2788,7 @@ inline void RegisterUnitySources(cmGeneratorTarget* target, cmSourceFile* sf, std::string const& filename) { target->AddSourceFileToUnityBatch(sf->ResolveFullPath()); - sf->SetProperty("UNITY_SOURCE_FILE", filename.c_str()); + sf->SetProperty("UNITY_SOURCE_FILE", filename); } } @@ -2986,7 +2986,7 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target) auto* unity = this->GetMakefile()->GetOrCreateSource(file); target->AddSource(file, true); unity->SetProperty("SKIP_UNITY_BUILD_INCLUSION", "ON"); - unity->SetProperty("UNITY_SOURCE_FILE", file.c_str()); + unity->SetProperty("UNITY_SOURCE_FILE", file); } } } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 0b8778f..9e7816f 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -212,59 +212,31 @@ void cmMakefile::MaybeWarnCMP0074(std::string const& pkg) } } -cmStringRange cmMakefile::GetIncludeDirectoriesEntries() const +cmBTStringRange cmMakefile::GetIncludeDirectoriesEntries() const { return this->StateSnapshot.GetDirectory().GetIncludeDirectoriesEntries(); } -cmBacktraceRange cmMakefile::GetIncludeDirectoriesBacktraces() const -{ - return this->StateSnapshot.GetDirectory() - .GetIncludeDirectoriesEntryBacktraces(); -} - -cmStringRange cmMakefile::GetCompileOptionsEntries() const +cmBTStringRange cmMakefile::GetCompileOptionsEntries() const { return this->StateSnapshot.GetDirectory().GetCompileOptionsEntries(); } -cmBacktraceRange cmMakefile::GetCompileOptionsBacktraces() const -{ - return this->StateSnapshot.GetDirectory().GetCompileOptionsEntryBacktraces(); -} - -cmStringRange cmMakefile::GetCompileDefinitionsEntries() const +cmBTStringRange cmMakefile::GetCompileDefinitionsEntries() const { return this->StateSnapshot.GetDirectory().GetCompileDefinitionsEntries(); } -cmBacktraceRange cmMakefile::GetCompileDefinitionsBacktraces() const -{ - return this->StateSnapshot.GetDirectory() - .GetCompileDefinitionsEntryBacktraces(); -} - -cmStringRange cmMakefile::GetLinkOptionsEntries() const +cmBTStringRange cmMakefile::GetLinkOptionsEntries() const { return this->StateSnapshot.GetDirectory().GetLinkOptionsEntries(); } -cmBacktraceRange cmMakefile::GetLinkOptionsBacktraces() const -{ - return this->StateSnapshot.GetDirectory().GetLinkOptionsEntryBacktraces(); -} - -cmStringRange cmMakefile::GetLinkDirectoriesEntries() const +cmBTStringRange cmMakefile::GetLinkDirectoriesEntries() const { return this->StateSnapshot.GetDirectory().GetLinkDirectoriesEntries(); } -cmBacktraceRange cmMakefile::GetLinkDirectoriesBacktraces() const -{ - return this->StateSnapshot.GetDirectory() - .GetLinkDirectoriesEntryBacktraces(); -} - cmListFileBacktrace cmMakefile::GetBacktrace() const { return this->Backtrace; @@ -1386,10 +1358,10 @@ void cmMakefile::AddLinkDirectory(std::string const& directory, bool before) { if (before) { this->StateSnapshot.GetDirectory().PrependLinkDirectoriesEntry( - directory, this->Backtrace); + BT<std::string>(directory, this->Backtrace)); } else { this->StateSnapshot.GetDirectory().AppendLinkDirectoriesEntry( - directory, this->Backtrace); + BT<std::string>(directory, this->Backtrace)); } } @@ -1444,7 +1416,7 @@ bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove) std::string ndefs = cmJoin(cmMakeRange(defBegin, defEnd), ";"); // Store the new list. - this->SetProperty("COMPILE_DEFINITIONS", ndefs.c_str()); + this->SetProperty("COMPILE_DEFINITIONS", ndefs); } } else { // Append the definition to the directory property. @@ -1465,30 +1437,29 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent) // Include transform property. There is no per-config version. { const char* prop = "IMPLICIT_DEPENDS_INCLUDE_TRANSFORM"; - this->SetProperty(prop, cmToCStr(parent->GetProperty(prop))); + this->SetProperty(prop, parent->GetProperty(prop)); } // compile definitions property and per-config versions cmPolicies::PolicyStatus polSt = this->GetPolicyStatus(cmPolicies::CMP0043); if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD) { this->SetProperty("COMPILE_DEFINITIONS", - cmToCStr(parent->GetProperty("COMPILE_DEFINITIONS"))); + parent->GetProperty("COMPILE_DEFINITIONS")); std::vector<std::string> configs = this->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); for (std::string const& config : configs) { std::string defPropName = cmStrCat("COMPILE_DEFINITIONS_", cmSystemTools::UpperCase(config)); cmProp prop = parent->GetProperty(defPropName); - this->SetProperty(defPropName, cmToCStr(prop)); + this->SetProperty(defPropName, prop); } } // labels - this->SetProperty("LABELS", cmToCStr(parent->GetProperty("LABELS"))); + this->SetProperty("LABELS", parent->GetProperty("LABELS")); // link libraries - this->SetProperty("LINK_LIBRARIES", - cmToCStr(parent->GetProperty("LINK_LIBRARIES"))); + this->SetProperty("LINK_LIBRARIES", parent->GetProperty("LINK_LIBRARIES")); // the initial project name this->StateSnapshot.SetProjectName(parent->StateSnapshot.GetProjectName()); @@ -1877,16 +1848,16 @@ void cmMakefile::AddIncludeDirectories(const std::vector<std::string>& incs, std::string entryString = cmJoin(incs, ";"); if (before) { this->StateSnapshot.GetDirectory().PrependIncludeDirectoriesEntry( - entryString, this->Backtrace); + BT<std::string>(entryString, this->Backtrace)); } else { this->StateSnapshot.GetDirectory().AppendIncludeDirectoriesEntry( - entryString, this->Backtrace); + BT<std::string>(entryString, this->Backtrace)); } // Property on each target: for (auto& target : this->Targets) { cmTarget& t = target.second; - t.InsertInclude(entryString, this->Backtrace, before); + t.InsertInclude(BT<std::string>(entryString, this->Backtrace), before); } } @@ -2308,7 +2279,7 @@ void cmMakefile::ExpandVariablesCMP0019() << " " << dirs << "\n"; /* clang-format on */ } - this->SetProperty("INCLUDE_DIRECTORIES", dirs.c_str()); + this->SetProperty("INCLUDE_DIRECTORIES", dirs); } // Also for each target's INCLUDE_DIRECTORIES property: @@ -3986,6 +3957,10 @@ void cmMakefile::SetProperty(const std::string& prop, const char* value) { this->StateSnapshot.GetDirectory().SetProperty(prop, value, this->Backtrace); } +void cmMakefile::SetProperty(const std::string& prop, cmProp value) +{ + this->StateSnapshot.GetDirectory().SetProperty(prop, value, this->Backtrace); +} void cmMakefile::AppendProperty(const std::string& prop, const std::string& value, bool asString) diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index a3d2a81..bdcab3b 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -33,7 +33,6 @@ #include "cmSourceFileLocationKind.h" #include "cmStateSnapshot.h" #include "cmStateTypes.h" -#include "cmStringAlgorithms.h" // IWYU does not see that 'std::unordered_map<std::string, cmTarget>' // will not compile without the complete type. @@ -769,6 +768,11 @@ public: //! Set/Get a property of this directory void SetProperty(const std::string& prop, const char* value); + void SetProperty(const std::string& prop, cmProp value); + void SetProperty(const std::string& prop, const std::string& value) + { + this->SetProperty(prop, cmProp(value)); + } void AppendProperty(const std::string& prop, const std::string& value, bool asString = false); cmProp GetProperty(const std::string& prop) const; @@ -874,16 +878,11 @@ public: bool CheckCMP0037(std::string const& targetName, cmStateEnums::TargetType targetType) const; - cmStringRange GetIncludeDirectoriesEntries() const; - cmBacktraceRange GetIncludeDirectoriesBacktraces() const; - cmStringRange GetCompileOptionsEntries() const; - cmBacktraceRange GetCompileOptionsBacktraces() const; - cmStringRange GetCompileDefinitionsEntries() const; - cmBacktraceRange GetCompileDefinitionsBacktraces() const; - cmStringRange GetLinkOptionsEntries() const; - cmBacktraceRange GetLinkOptionsBacktraces() const; - cmStringRange GetLinkDirectoriesEntries() const; - cmBacktraceRange GetLinkDirectoriesBacktraces() const; + cmBTStringRange GetIncludeDirectoriesEntries() const; + cmBTStringRange GetCompileOptionsEntries() const; + cmBTStringRange GetCompileDefinitionsEntries() const; + cmBTStringRange GetLinkOptionsEntries() const; + cmBTStringRange GetLinkDirectoriesEntries() const; std::set<std::string> const& GetSystemIncludeDirectories() const { diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 1b6b834..be8bb08 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -774,8 +774,11 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang, cmProp d = mf->GetDefinition("CMAKE_C_COMPILER"); const std::string cl = d ? *d : mf->GetSafeDefinition("CMAKE_CXX_COMPILER"); - cldeps = cmStrCat('"', cmSystemTools::GetCMClDepsCommand(), "\" ", lang, - ' ', vars.Source, " $DEP_FILE $out \"", + std::string cmcldepsPath; + cmSystemTools::GetShortPath(cmSystemTools::GetCMClDepsCommand(), + cmcldepsPath); + cldeps = cmStrCat(cmcldepsPath, ' ', lang, ' ', vars.Source, + " $DEP_FILE $out \"", mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX"), "\" \"", cl, "\" "); } diff --git a/Source/cmPropertyMap.cxx b/Source/cmPropertyMap.cxx index 3e3a44b..8ad3c6f 100644 --- a/Source/cmPropertyMap.cxx +++ b/Source/cmPropertyMap.cxx @@ -19,6 +19,15 @@ void cmPropertyMap::SetProperty(const std::string& name, const char* value) this->Map_[name] = value; } +void cmPropertyMap::SetProperty(const std::string& name, cmProp value) +{ + if (!value) { + this->Map_.erase(name); + return; + } + + this->Map_[name] = *value; +} void cmPropertyMap::AppendProperty(const std::string& name, const std::string& value, bool asString) diff --git a/Source/cmPropertyMap.h b/Source/cmPropertyMap.h index cda585a..b28d3c9 100644 --- a/Source/cmPropertyMap.h +++ b/Source/cmPropertyMap.h @@ -26,6 +26,11 @@ public: //! Set the property value void SetProperty(const std::string& name, const char* value); + void SetProperty(const std::string& name, cmProp value); + void SetProperty(const std::string& name, const std::string& value) + { + this->SetProperty(name, cmProp(value)); + } //! Append to the property value void AppendProperty(const std::string& name, const std::string& value, diff --git a/Source/cmQTWrapCPPCommand.cxx b/Source/cmQTWrapCPPCommand.cxx index e9670f9..ca0b259 100644 --- a/Source/cmQTWrapCPPCommand.cxx +++ b/Source/cmQTWrapCPPCommand.cxx @@ -6,7 +6,6 @@ #include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmPolicies.h" -#include "cmProperty.h" #include "cmRange.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" @@ -41,7 +40,7 @@ bool cmQTWrapCPPCommand(std::vector<std::string> const& args, cmStrCat(mf.GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx"); cmSourceFile* sf = mf.GetOrCreateSource(newName, true); if (curr) { - sf->SetProperty("ABSTRACT", cmToCStr(curr->GetProperty("ABSTRACT"))); + sf->SetProperty("ABSTRACT", curr->GetProperty("ABSTRACT")); } // Compute the name of the header from which to generate the file. diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index 77fe87e..f3ad565 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -186,7 +186,7 @@ void cmQtAutoGenGlobalInitializer::GetOrCreateGlobalTarget( cmProp folder = makefile->GetState()->GetGlobalProperty("AUTOGEN_TARGETS_FOLDER"); if (folder) { - target->SetProperty("FOLDER", *folder); + target->SetProperty("FOLDER", folder); } } } diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 4dd78e5..fe038c7 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -24,6 +24,7 @@ #include "cmsys/SystemInformation.hxx" +#include "cmAlgorithms.h" #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmGeneratedFileStream.h" @@ -522,6 +523,8 @@ bool cmQtAutoGenInitializer::InitCustomTargets() // Filters cmExpandList(this->GenTarget->GetSafeProperty("AUTOMOC_MACRO_NAMES"), this->Moc.MacroNames); + this->Moc.MacroNames.erase(cmRemoveDuplicates(this->Moc.MacroNames), + this->Moc.MacroNames.end()); { auto filterList = cmExpandedList( this->GenTarget->GetSafeProperty("AUTOMOC_DEPEND_FILTERS")); diff --git a/Source/cmSetDirectoryPropertiesCommand.cxx b/Source/cmSetDirectoryPropertiesCommand.cxx index 07ad246..9adf537 100644 --- a/Source/cmSetDirectoryPropertiesCommand.cxx +++ b/Source/cmSetDirectoryPropertiesCommand.cxx @@ -32,7 +32,7 @@ bool cmSetDirectoryPropertiesCommand(std::vector<std::string> const& args, "Commands and macros cannot be set using SET_CMAKE_PROPERTIES"); return false; } - status.GetMakefile().SetProperty(prop, (iter + 1)->c_str()); + status.GetMakefile().SetProperty(prop, *(iter + 1)); } return true; diff --git a/Source/cmSetPropertyCommand.cxx b/Source/cmSetPropertyCommand.cxx index c899053..59b4402 100644 --- a/Source/cmSetPropertyCommand.cxx +++ b/Source/cmSetPropertyCommand.cxx @@ -294,7 +294,7 @@ bool HandleAndValidateSourceFilePropertyGENERATED( sf->SetProperty("GENERATED", nullptr); break; case PropertyOp::Set: - sf->SetProperty("GENERATED", propertyValue.c_str()); + sf->SetProperty("GENERATED", propertyValue); break; } } else { @@ -474,7 +474,7 @@ bool HandleGlobalMode(cmExecutionStatus& status, if (remove) { cm->SetProperty(propertyName, nullptr); } else { - cm->SetProperty(propertyName, propertyValue.c_str()); + cm->SetProperty(propertyName, propertyValue); } } @@ -520,7 +520,7 @@ bool HandleDirectoryMode(cmExecutionStatus& status, if (remove) { mf->SetProperty(propertyName, nullptr); } else { - mf->SetProperty(propertyName, propertyValue.c_str()); + mf->SetProperty(propertyName, propertyValue); } } @@ -631,7 +631,7 @@ bool HandleSource(cmSourceFile* sf, const std::string& propertyName, if (remove) { sf->SetProperty(propertyName, nullptr); } else { - sf->SetProperty(propertyName, propertyValue.c_str()); + sf->SetProperty(propertyName, propertyValue); } } return true; @@ -681,7 +681,7 @@ bool HandleTest(cmTest* test, const std::string& propertyName, if (remove) { test->SetProperty(propertyName, nullptr); } else { - test->SetProperty(propertyName, propertyValue.c_str()); + test->SetProperty(propertyName, propertyValue); } } diff --git a/Source/cmSetSourceFilesPropertiesCommand.cxx b/Source/cmSetSourceFilesPropertiesCommand.cxx index 237b67f..ab93ddb 100644 --- a/Source/cmSetSourceFilesPropertiesCommand.cxx +++ b/Source/cmSetSourceFilesPropertiesCommand.cxx @@ -173,7 +173,7 @@ static bool RunCommandForScope( SetPropertyCommand::HandleAndValidateSourceFilePropertyGENERATED( sf, *(k + 1)); } else { - sf->SetProperty(*k, (k + 1)->c_str()); + sf->SetProperty(*k, *(k + 1)); } } } diff --git a/Source/cmSetTestsPropertiesCommand.cxx b/Source/cmSetTestsPropertiesCommand.cxx index c4bff76..a17c964 100644 --- a/Source/cmSetTestsPropertiesCommand.cxx +++ b/Source/cmSetTestsPropertiesCommand.cxx @@ -37,7 +37,7 @@ bool cmSetTestsPropertiesCommand(std::vector<std::string> const& args, // loop through all the props and set them for (auto k = propsIter + 1; k != args.end(); k += 2) { if (!k->empty()) { - test->SetProperty(*k, (k + 1)->c_str()); + test->SetProperty(*k, *(k + 1)); } } } else { diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index f2b5cc4..6caae3a 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -269,7 +269,8 @@ bool cmSourceFile::Matches(cmSourceFileLocation const& loc) return this->Location.Matches(loc); } -void cmSourceFile::SetProperty(const std::string& prop, const char* value) +template <typename ValueType> +void cmSourceFile::StoreProperty(const std::string& prop, ValueType value) { if (prop == propINCLUDE_DIRECTORIES) { this->IncludeDirectories.clear(); @@ -294,6 +295,15 @@ void cmSourceFile::SetProperty(const std::string& prop, const char* value) } } +void cmSourceFile::SetProperty(const std::string& prop, const char* value) +{ + this->StoreProperty(prop, value); +} +void cmSourceFile::SetProperty(const std::string& prop, cmProp value) +{ + this->StoreProperty(prop, value); +} + void cmSourceFile::AppendProperty(const std::string& prop, const std::string& value, bool asString) { diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index 32ed687..78e0d27 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -42,6 +42,11 @@ public: //! Set/Get a property of this source file void SetProperty(const std::string& prop, const char* value); + void SetProperty(const std::string& prop, cmProp value); + void SetProperty(const std::string& prop, const std::string& value) + { + this->SetProperty(prop, cmProp(value)); + } void AppendProperty(const std::string& prop, const std::string& value, bool asString = false); //! Might return a nullptr if the property is not set or invalid @@ -145,6 +150,9 @@ public: std::string GetObjectLibrary() const; private: + template <typename ValueType> + void StoreProperty(const std::string& prop, ValueType value); + cmSourceFileLocation Location; cmPropertyMap Properties; std::unique_ptr<cmCustomCommand> CustomCommand; diff --git a/Source/cmState.cxx b/Source/cmState.cxx index bde3e2e..cfd9ad0 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -277,15 +277,10 @@ cmStateSnapshot cmState::Reset() cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator it = this->BuildsystemDirectory.Truncate(); it->IncludeDirectories.clear(); - it->IncludeDirectoryBacktraces.clear(); it->CompileDefinitions.clear(); - it->CompileDefinitionsBacktraces.clear(); it->CompileOptions.clear(); - it->CompileOptionsBacktraces.clear(); it->LinkOptions.clear(); - it->LinkOptionsBacktraces.clear(); it->LinkDirectories.clear(); - it->LinkDirectoriesBacktraces.clear(); it->DirectoryEnd = pos; it->NormalTargetNames.clear(); it->ImportedTargetNames.clear(); @@ -569,6 +564,10 @@ void cmState::SetGlobalProperty(const std::string& prop, const char* value) { this->GlobalProperties.SetProperty(prop, value); } +void cmState::SetGlobalProperty(const std::string& prop, cmProp value) +{ + this->GlobalProperties.SetProperty(prop, value); +} void cmState::AppendGlobalProperty(const std::string& prop, const std::string& value, bool asString) diff --git a/Source/cmState.h b/Source/cmState.h index 8561fc0..0fd28d0 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -178,6 +178,7 @@ public: std::vector<std::string> GetCommandNames() const; void SetGlobalProperty(const std::string& prop, const char* value); + void SetGlobalProperty(const std::string& prop, cmProp value); void AppendGlobalProperty(const std::string& prop, const std::string& value, bool asString = false); cmProp GetGlobalProperty(const std::string& prop); diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx index b90cf7e..8f83b02 100644 --- a/Source/cmStateDirectory.cxx +++ b/Source/cmStateDirectory.cxx @@ -19,6 +19,7 @@ #include "cmState.h" #include "cmStatePrivate.h" #include "cmStateTypes.h" +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" static std::string const kBINARY_DIR = "BINARY_DIR"; @@ -63,7 +64,7 @@ cmStateDirectory::cmStateDirectory( } template <typename T, typename U> -cmStringRange GetPropertyContent(T const& content, U contentEndPosition) +cmBTStringRange GetPropertyContent(T const& content, U contentEndPosition) { auto end = content.begin() + contentEndPosition; @@ -73,88 +74,59 @@ cmStringRange GetPropertyContent(T const& content, U contentEndPosition) return cmMakeRange(rbegin.base(), end); } -template <typename T, typename U, typename V> -cmBacktraceRange GetPropertyBacktraces(T const& content, U const& backtraces, - V contentEndPosition) -{ - auto entryEnd = content.begin() + contentEndPosition; - - auto rbegin = cm::make_reverse_iterator(entryEnd); - rbegin = std::find(rbegin, content.rend(), cmPropertySentinal); - - auto it = backtraces.begin() + std::distance(content.begin(), rbegin.base()); - - auto end = backtraces.end(); - return cmMakeRange(it, end); -} - -template <typename T, typename U, typename V> -void AppendEntry(T& content, U& backtraces, V& endContentPosition, - const std::string& value, const cmListFileBacktrace& lfbt) +template <typename T, typename U> +void AppendEntry(T& content, U& endContentPosition, + const BT<std::string>& value) { - if (value.empty()) { + if (value.Value.empty()) { return; } assert(endContentPosition == content.size()); content.push_back(value); - backtraces.push_back(lfbt); endContentPosition = content.size(); } -template <typename T, typename U, typename V> -void SetContent(T& content, U& backtraces, V& endContentPosition, - const std::string& vec, const cmListFileBacktrace& lfbt) +template <typename T, typename U> +void SetContent(T& content, U& endContentPosition, const BT<std::string>& vec) { assert(endContentPosition == content.size()); content.resize(content.size() + 2); - backtraces.resize(backtraces.size() + 2); content.back() = vec; - backtraces.back() = lfbt; endContentPosition = content.size(); } -template <typename T, typename U, typename V> -void ClearContent(T& content, U& backtraces, V& endContentPosition) +template <typename T, typename U> +void ClearContent(T& content, U& endContentPosition) { assert(endContentPosition == content.size()); content.resize(content.size() + 1); - backtraces.resize(backtraces.size() + 1); endContentPosition = content.size(); } -cmStringRange cmStateDirectory::GetIncludeDirectoriesEntries() const +cmBTStringRange cmStateDirectory::GetIncludeDirectoriesEntries() const { return GetPropertyContent( this->DirectoryState->IncludeDirectories, this->Snapshot_.Position->IncludeDirectoryPosition); } -cmBacktraceRange cmStateDirectory::GetIncludeDirectoriesEntryBacktraces() const -{ - return GetPropertyBacktraces( - this->DirectoryState->IncludeDirectories, - this->DirectoryState->IncludeDirectoryBacktraces, - this->Snapshot_.Position->IncludeDirectoryPosition); -} - void cmStateDirectory::AppendIncludeDirectoriesEntry( - const std::string& vec, const cmListFileBacktrace& lfbt) + const BT<std::string>& vec) { AppendEntry(this->DirectoryState->IncludeDirectories, - this->DirectoryState->IncludeDirectoryBacktraces, - this->Snapshot_.Position->IncludeDirectoryPosition, vec, lfbt); + this->Snapshot_.Position->IncludeDirectoryPosition, vec); } void cmStateDirectory::PrependIncludeDirectoriesEntry( - const std::string& vec, const cmListFileBacktrace& lfbt) + const BT<std::string>& vec) { auto entryEnd = this->DirectoryState->IncludeDirectories.begin() + this->Snapshot_.Position->IncludeDirectoryPosition; @@ -164,167 +136,111 @@ void cmStateDirectory::PrependIncludeDirectoriesEntry( rbegin = std::find(rbegin, rend, cmPropertySentinal); auto entryIt = rbegin.base(); - auto entryBegin = this->DirectoryState->IncludeDirectories.begin(); - - auto btIt = this->DirectoryState->IncludeDirectoryBacktraces.begin() + - std::distance(entryBegin, entryIt); this->DirectoryState->IncludeDirectories.insert(entryIt, vec); - this->DirectoryState->IncludeDirectoryBacktraces.insert(btIt, lfbt); this->Snapshot_.Position->IncludeDirectoryPosition = this->DirectoryState->IncludeDirectories.size(); } -void cmStateDirectory::SetIncludeDirectories(const std::string& vec, - const cmListFileBacktrace& lfbt) +void cmStateDirectory::SetIncludeDirectories(const BT<std::string>& vec) { SetContent(this->DirectoryState->IncludeDirectories, - this->DirectoryState->IncludeDirectoryBacktraces, - this->Snapshot_.Position->IncludeDirectoryPosition, vec, lfbt); + this->Snapshot_.Position->IncludeDirectoryPosition, vec); } void cmStateDirectory::ClearIncludeDirectories() { ClearContent(this->DirectoryState->IncludeDirectories, - this->DirectoryState->IncludeDirectoryBacktraces, this->Snapshot_.Position->IncludeDirectoryPosition); } -cmStringRange cmStateDirectory::GetCompileDefinitionsEntries() const +cmBTStringRange cmStateDirectory::GetCompileDefinitionsEntries() const { return GetPropertyContent( this->DirectoryState->CompileDefinitions, this->Snapshot_.Position->CompileDefinitionsPosition); } -cmBacktraceRange cmStateDirectory::GetCompileDefinitionsEntryBacktraces() const -{ - return GetPropertyBacktraces( - this->DirectoryState->CompileDefinitions, - this->DirectoryState->CompileDefinitionsBacktraces, - this->Snapshot_.Position->CompileDefinitionsPosition); -} - void cmStateDirectory::AppendCompileDefinitionsEntry( - const std::string& vec, const cmListFileBacktrace& lfbt) + const BT<std::string>& vec) { AppendEntry(this->DirectoryState->CompileDefinitions, - this->DirectoryState->CompileDefinitionsBacktraces, - this->Snapshot_.Position->CompileDefinitionsPosition, vec, lfbt); + this->Snapshot_.Position->CompileDefinitionsPosition, vec); } -void cmStateDirectory::SetCompileDefinitions(const std::string& vec, - const cmListFileBacktrace& lfbt) +void cmStateDirectory::SetCompileDefinitions(const BT<std::string>& vec) { SetContent(this->DirectoryState->CompileDefinitions, - this->DirectoryState->CompileDefinitionsBacktraces, - this->Snapshot_.Position->CompileDefinitionsPosition, vec, lfbt); + this->Snapshot_.Position->CompileDefinitionsPosition, vec); } void cmStateDirectory::ClearCompileDefinitions() { ClearContent(this->DirectoryState->CompileDefinitions, - this->DirectoryState->CompileDefinitionsBacktraces, this->Snapshot_.Position->CompileDefinitionsPosition); } -cmStringRange cmStateDirectory::GetCompileOptionsEntries() const +cmBTStringRange cmStateDirectory::GetCompileOptionsEntries() const { return GetPropertyContent(this->DirectoryState->CompileOptions, this->Snapshot_.Position->CompileOptionsPosition); } -cmBacktraceRange cmStateDirectory::GetCompileOptionsEntryBacktraces() const -{ - return GetPropertyBacktraces( - this->DirectoryState->CompileOptions, - this->DirectoryState->CompileOptionsBacktraces, - this->Snapshot_.Position->CompileOptionsPosition); -} - -void cmStateDirectory::AppendCompileOptionsEntry( - const std::string& vec, const cmListFileBacktrace& lfbt) +void cmStateDirectory::AppendCompileOptionsEntry(const BT<std::string>& vec) { AppendEntry(this->DirectoryState->CompileOptions, - this->DirectoryState->CompileOptionsBacktraces, - this->Snapshot_.Position->CompileOptionsPosition, vec, lfbt); + this->Snapshot_.Position->CompileOptionsPosition, vec); } -void cmStateDirectory::SetCompileOptions(const std::string& vec, - const cmListFileBacktrace& lfbt) +void cmStateDirectory::SetCompileOptions(const BT<std::string>& vec) { SetContent(this->DirectoryState->CompileOptions, - this->DirectoryState->CompileOptionsBacktraces, - this->Snapshot_.Position->CompileOptionsPosition, vec, lfbt); + this->Snapshot_.Position->CompileOptionsPosition, vec); } void cmStateDirectory::ClearCompileOptions() { ClearContent(this->DirectoryState->CompileOptions, - this->DirectoryState->CompileOptionsBacktraces, this->Snapshot_.Position->CompileOptionsPosition); } -cmStringRange cmStateDirectory::GetLinkOptionsEntries() const +cmBTStringRange cmStateDirectory::GetLinkOptionsEntries() const { return GetPropertyContent(this->DirectoryState->LinkOptions, this->Snapshot_.Position->LinkOptionsPosition); } -cmBacktraceRange cmStateDirectory::GetLinkOptionsEntryBacktraces() const -{ - return GetPropertyBacktraces(this->DirectoryState->LinkOptions, - this->DirectoryState->LinkOptionsBacktraces, - this->Snapshot_.Position->LinkOptionsPosition); -} - -void cmStateDirectory::AppendLinkOptionsEntry(const std::string& vec, - const cmListFileBacktrace& lfbt) +void cmStateDirectory::AppendLinkOptionsEntry(const BT<std::string>& vec) { AppendEntry(this->DirectoryState->LinkOptions, - this->DirectoryState->LinkOptionsBacktraces, - this->Snapshot_.Position->LinkOptionsPosition, vec, lfbt); + this->Snapshot_.Position->LinkOptionsPosition, vec); } -void cmStateDirectory::SetLinkOptions(const std::string& vec, - const cmListFileBacktrace& lfbt) +void cmStateDirectory::SetLinkOptions(const BT<std::string>& vec) { SetContent(this->DirectoryState->LinkOptions, - this->DirectoryState->LinkOptionsBacktraces, - this->Snapshot_.Position->LinkOptionsPosition, vec, lfbt); + this->Snapshot_.Position->LinkOptionsPosition, vec); } void cmStateDirectory::ClearLinkOptions() { ClearContent(this->DirectoryState->LinkOptions, - this->DirectoryState->LinkOptionsBacktraces, this->Snapshot_.Position->LinkOptionsPosition); } -cmStringRange cmStateDirectory::GetLinkDirectoriesEntries() const +cmBTStringRange cmStateDirectory::GetLinkDirectoriesEntries() const { return GetPropertyContent(this->DirectoryState->LinkDirectories, this->Snapshot_.Position->LinkDirectoriesPosition); } -cmBacktraceRange cmStateDirectory::GetLinkDirectoriesEntryBacktraces() const -{ - return GetPropertyBacktraces( - this->DirectoryState->LinkDirectories, - this->DirectoryState->LinkDirectoriesBacktraces, - this->Snapshot_.Position->LinkDirectoriesPosition); -} - -void cmStateDirectory::AppendLinkDirectoriesEntry( - const std::string& vec, const cmListFileBacktrace& lfbt) +void cmStateDirectory::AppendLinkDirectoriesEntry(const BT<std::string>& vec) { AppendEntry(this->DirectoryState->LinkDirectories, - this->DirectoryState->LinkDirectoriesBacktraces, - this->Snapshot_.Position->LinkDirectoriesPosition, vec, lfbt); + this->Snapshot_.Position->LinkDirectoriesPosition, vec); } -void cmStateDirectory::PrependLinkDirectoriesEntry( - const std::string& vec, const cmListFileBacktrace& lfbt) +void cmStateDirectory::PrependLinkDirectoriesEntry(const BT<std::string>& vec) { auto entryEnd = this->DirectoryState->LinkDirectories.begin() + this->Snapshot_.Position->LinkDirectoriesPosition; @@ -334,42 +250,35 @@ void cmStateDirectory::PrependLinkDirectoriesEntry( rbegin = std::find(rbegin, rend, cmPropertySentinal); auto entryIt = rbegin.base(); - auto entryBegin = this->DirectoryState->LinkDirectories.begin(); - - auto btIt = this->DirectoryState->LinkDirectoriesBacktraces.begin() + - std::distance(entryBegin, entryIt); this->DirectoryState->LinkDirectories.insert(entryIt, vec); - this->DirectoryState->LinkDirectoriesBacktraces.insert(btIt, lfbt); this->Snapshot_.Position->LinkDirectoriesPosition = this->DirectoryState->LinkDirectories.size(); } -void cmStateDirectory::SetLinkDirectories(const std::string& vec, - const cmListFileBacktrace& lfbt) +void cmStateDirectory::SetLinkDirectories(const BT<std::string>& vec) { SetContent(this->DirectoryState->LinkDirectories, - this->DirectoryState->LinkDirectoriesBacktraces, - this->Snapshot_.Position->LinkDirectoriesPosition, vec, lfbt); + this->Snapshot_.Position->LinkDirectoriesPosition, vec); } void cmStateDirectory::ClearLinkDirectories() { ClearContent(this->DirectoryState->LinkDirectories, - this->DirectoryState->LinkDirectoriesBacktraces, this->Snapshot_.Position->LinkDirectoriesPosition); } -void cmStateDirectory::SetProperty(const std::string& prop, const char* value, - cmListFileBacktrace const& lfbt) +template <typename ValueType> +void cmStateDirectory::StoreProperty(const std::string& prop, ValueType value, + cmListFileBacktrace const& lfbt) { if (prop == "INCLUDE_DIRECTORIES") { if (!value) { this->ClearIncludeDirectories(); return; } - this->SetIncludeDirectories(value, lfbt); + this->SetIncludeDirectories(BT<std::string>(value, lfbt)); return; } if (prop == "COMPILE_OPTIONS") { @@ -377,7 +286,7 @@ void cmStateDirectory::SetProperty(const std::string& prop, const char* value, this->ClearCompileOptions(); return; } - this->SetCompileOptions(value, lfbt); + this->SetCompileOptions(BT<std::string>(value, lfbt)); return; } if (prop == "COMPILE_DEFINITIONS") { @@ -385,7 +294,7 @@ void cmStateDirectory::SetProperty(const std::string& prop, const char* value, this->ClearCompileDefinitions(); return; } - this->SetCompileDefinitions(value, lfbt); + this->SetCompileDefinitions(BT<std::string>(value, lfbt)); return; } if (prop == "LINK_OPTIONS") { @@ -393,7 +302,7 @@ void cmStateDirectory::SetProperty(const std::string& prop, const char* value, this->ClearLinkOptions(); return; } - this->SetLinkOptions(value, lfbt); + this->SetLinkOptions(BT<std::string>(value, lfbt)); return; } if (prop == "LINK_DIRECTORIES") { @@ -401,35 +310,46 @@ void cmStateDirectory::SetProperty(const std::string& prop, const char* value, this->ClearLinkDirectories(); return; } - this->SetLinkDirectories(value, lfbt); + this->SetLinkDirectories(BT<std::string>(value, lfbt)); return; } this->DirectoryState->Properties.SetProperty(prop, value); } +void cmStateDirectory::SetProperty(const std::string& prop, const char* value, + cmListFileBacktrace const& lfbt) +{ + this->StoreProperty(prop, value, lfbt); +} +void cmStateDirectory::SetProperty(const std::string& prop, cmProp value, + cmListFileBacktrace const& lfbt) +{ + this->StoreProperty(prop, value, lfbt); +} + void cmStateDirectory::AppendProperty(const std::string& prop, const std::string& value, bool asString, cmListFileBacktrace const& lfbt) { if (prop == "INCLUDE_DIRECTORIES") { - this->AppendIncludeDirectoriesEntry(value, lfbt); + this->AppendIncludeDirectoriesEntry(BT<std::string>(value, lfbt)); return; } if (prop == "COMPILE_OPTIONS") { - this->AppendCompileOptionsEntry(value, lfbt); + this->AppendCompileOptionsEntry(BT<std::string>(value, lfbt)); return; } if (prop == "COMPILE_DEFINITIONS") { - this->AppendCompileDefinitionsEntry(value, lfbt); + this->AppendCompileDefinitionsEntry(BT<std::string>(value, lfbt)); return; } if (prop == "LINK_OPTIONS") { - this->AppendLinkOptionsEntry(value, lfbt); + this->AppendLinkOptionsEntry(BT<std::string>(value, lfbt)); return; } if (prop == "LINK_DIRECTORIES") { - this->AppendLinkDirectoriesEntry(value, lfbt); + this->AppendLinkDirectoriesEntry(BT<std::string>(value, lfbt)); return; } diff --git a/Source/cmStateDirectory.h b/Source/cmStateDirectory.h index b8abccb..fac5d58c 100644 --- a/Source/cmStateDirectory.h +++ b/Source/cmStateDirectory.h @@ -14,7 +14,6 @@ #include "cmProperty.h" #include "cmStatePrivate.h" #include "cmStateSnapshot.h" -#include "cmStringAlgorithms.h" class cmStateDirectory { @@ -28,51 +27,37 @@ public: std::string const& GetCurrentBinary() const; void SetCurrentBinary(std::string const& dir); - cmStringRange GetIncludeDirectoriesEntries() const; - cmBacktraceRange GetIncludeDirectoriesEntryBacktraces() const; - void AppendIncludeDirectoriesEntry(std::string const& vec, - cmListFileBacktrace const& lfbt); - void PrependIncludeDirectoriesEntry(std::string const& vec, - cmListFileBacktrace const& lfbt); - void SetIncludeDirectories(std::string const& vec, - cmListFileBacktrace const& lfbt); + cmBTStringRange GetIncludeDirectoriesEntries() const; + void AppendIncludeDirectoriesEntry(BT<std::string> const& vec); + void PrependIncludeDirectoriesEntry(BT<std::string> const& vec); + void SetIncludeDirectories(BT<std::string> const& vec); void ClearIncludeDirectories(); - cmStringRange GetCompileDefinitionsEntries() const; - cmBacktraceRange GetCompileDefinitionsEntryBacktraces() const; - void AppendCompileDefinitionsEntry(std::string const& vec, - cmListFileBacktrace const& lfbt); - void SetCompileDefinitions(std::string const& vec, - cmListFileBacktrace const& lfbt); + cmBTStringRange GetCompileDefinitionsEntries() const; + void AppendCompileDefinitionsEntry(BT<std::string> const& vec); + void SetCompileDefinitions(BT<std::string> const& vec); void ClearCompileDefinitions(); - cmStringRange GetCompileOptionsEntries() const; - cmBacktraceRange GetCompileOptionsEntryBacktraces() const; - void AppendCompileOptionsEntry(std::string const& vec, - cmListFileBacktrace const& lfbt); - void SetCompileOptions(std::string const& vec, - cmListFileBacktrace const& lfbt); + cmBTStringRange GetCompileOptionsEntries() const; + void AppendCompileOptionsEntry(BT<std::string> const& vec); + void SetCompileOptions(BT<std::string> const& vec); void ClearCompileOptions(); - cmStringRange GetLinkOptionsEntries() const; - cmBacktraceRange GetLinkOptionsEntryBacktraces() const; - void AppendLinkOptionsEntry(std::string const& vec, - cmListFileBacktrace const& lfbt); - void PrependLinkDirectoriesEntry(std::string const& vec, - cmListFileBacktrace const& lfbt); - void SetLinkOptions(std::string const& vec, cmListFileBacktrace const& lfbt); + cmBTStringRange GetLinkOptionsEntries() const; + void AppendLinkOptionsEntry(BT<std::string> const& vec); + void PrependLinkDirectoriesEntry(BT<std::string> const& vec); + void SetLinkOptions(BT<std::string> const& vec); void ClearLinkOptions(); - cmStringRange GetLinkDirectoriesEntries() const; - cmBacktraceRange GetLinkDirectoriesEntryBacktraces() const; - void AppendLinkDirectoriesEntry(std::string const& vec, - cmListFileBacktrace const& lfbt); - void SetLinkDirectories(std::string const& vec, - cmListFileBacktrace const& lfbt); + cmBTStringRange GetLinkDirectoriesEntries() const; + void AppendLinkDirectoriesEntry(BT<std::string> const& vec); + void SetLinkDirectories(BT<std::string> const& vecs); void ClearLinkDirectories(); void SetProperty(const std::string& prop, const char* value, cmListFileBacktrace const& lfbt); + void SetProperty(const std::string& prop, cmProp value, + cmListFileBacktrace const& lfbt); void AppendProperty(const std::string& prop, const std::string& value, bool asString, cmListFileBacktrace const& lfbt); cmProp GetProperty(const std::string& prop) const; @@ -84,6 +69,10 @@ public: void AddImportedTargetName(std::string const& name); private: + template <typename ValueType> + void StoreProperty(const std::string& prop, ValueType value, + cmListFileBacktrace const& lfbt); + cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator DirectoryState; cmStateSnapshot Snapshot_; diff --git a/Source/cmStatePrivate.h b/Source/cmStatePrivate.h index 6f475f2..fd46eed 100644 --- a/Source/cmStatePrivate.h +++ b/Source/cmStatePrivate.h @@ -67,20 +67,15 @@ struct cmStateDetail::BuildsystemDirectoryStateType std::string Location; std::string OutputLocation; - std::vector<std::string> IncludeDirectories; - std::vector<cmListFileBacktrace> IncludeDirectoryBacktraces; + std::vector<BT<std::string>> IncludeDirectories; - std::vector<std::string> CompileDefinitions; - std::vector<cmListFileBacktrace> CompileDefinitionsBacktraces; + std::vector<BT<std::string>> CompileDefinitions; - std::vector<std::string> CompileOptions; - std::vector<cmListFileBacktrace> CompileOptionsBacktraces; + std::vector<BT<std::string>> CompileOptions; - std::vector<std::string> LinkOptions; - std::vector<cmListFileBacktrace> LinkOptionsBacktraces; + std::vector<BT<std::string>> LinkOptions; - std::vector<std::string> LinkDirectories; - std::vector<cmListFileBacktrace> LinkDirectoriesBacktraces; + std::vector<BT<std::string>> LinkDirectories; std::vector<std::string> NormalTargetNames; std::vector<std::string> ImportedTargetNames; diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx index 6f13d89..bd7db85 100644 --- a/Source/cmStateSnapshot.cxx +++ b/Source/cmStateSnapshot.cxx @@ -19,6 +19,10 @@ #include "cmSystemTools.h" #include "cmVersion.h" +#if defined(__CYGWIN__) +# include "cmStringAlgorithms.h" +#endif + cmStateSnapshot::cmStateSnapshot(cmState* state) : State(state) { @@ -259,12 +263,10 @@ bool cmStateSnapshot::RaiseScope(std::string const& var, const char* varDef) return true; } -template <typename T, typename U, typename V> +template <typename T, typename U> void InitializeContentFromParent(T& parentContent, T& thisContent, - U& parentBacktraces, U& thisBacktraces, - V& contentEndPosition) + U& contentEndPosition) { - auto parentBegin = parentContent.begin(); auto parentEnd = parentContent.end(); auto parentRbegin = cm::make_reverse_iterator(parentEnd); @@ -272,12 +274,7 @@ void InitializeContentFromParent(T& parentContent, T& thisContent, parentRbegin = std::find(parentRbegin, parentRend, cmPropertySentinal); auto parentIt = parentRbegin.base(); - thisContent = std::vector<std::string>(parentIt, parentEnd); - - auto btIt = parentBacktraces.begin() + std::distance(parentBegin, parentIt); - auto btEnd = parentBacktraces.end(); - - thisBacktraces = std::vector<cmListFileBacktrace>(btIt, btEnd); + thisContent = std::vector<BT<std::string>>(parentIt, parentEnd); contentEndPosition = thisContent.size(); } @@ -359,43 +356,33 @@ void cmStateSnapshot::InitializeFromParent() InitializeContentFromParent( parent->BuildSystemDirectory->IncludeDirectories, this->Position->BuildSystemDirectory->IncludeDirectories, - parent->BuildSystemDirectory->IncludeDirectoryBacktraces, - this->Position->BuildSystemDirectory->IncludeDirectoryBacktraces, this->Position->IncludeDirectoryPosition); InitializeContentFromParent( parent->BuildSystemDirectory->CompileDefinitions, this->Position->BuildSystemDirectory->CompileDefinitions, - parent->BuildSystemDirectory->CompileDefinitionsBacktraces, - this->Position->BuildSystemDirectory->CompileDefinitionsBacktraces, this->Position->CompileDefinitionsPosition); InitializeContentFromParent( parent->BuildSystemDirectory->CompileOptions, this->Position->BuildSystemDirectory->CompileOptions, - parent->BuildSystemDirectory->CompileOptionsBacktraces, - this->Position->BuildSystemDirectory->CompileOptionsBacktraces, this->Position->CompileOptionsPosition); InitializeContentFromParent( parent->BuildSystemDirectory->LinkOptions, this->Position->BuildSystemDirectory->LinkOptions, - parent->BuildSystemDirectory->LinkOptionsBacktraces, - this->Position->BuildSystemDirectory->LinkOptionsBacktraces, this->Position->LinkOptionsPosition); InitializeContentFromParent( parent->BuildSystemDirectory->LinkDirectories, this->Position->BuildSystemDirectory->LinkDirectories, - parent->BuildSystemDirectory->LinkDirectoriesBacktraces, - this->Position->BuildSystemDirectory->LinkDirectoriesBacktraces, this->Position->LinkDirectoriesPosition); cmProp include_regex = parent->BuildSystemDirectory->Properties.GetPropertyValue( "INCLUDE_REGULAR_EXPRESSION"); this->Position->BuildSystemDirectory->Properties.SetProperty( - "INCLUDE_REGULAR_EXPRESSION", cmToCStr(include_regex)); + "INCLUDE_REGULAR_EXPRESSION", include_regex); } cmState* cmStateSnapshot::GetState() const diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 656afc6..af64dce 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -83,15 +83,15 @@ cmProp cmTargetPropertyComputer::GetSources<cmTarget>( cmTarget const* tgt, cmMessenger* messenger, cmListFileBacktrace const& context) { - cmStringRange entries = tgt->GetSourceEntries(); + cmBTStringRange entries = tgt->GetSourceEntries(); if (entries.empty()) { return nullptr; } std::ostringstream ss; const char* sep = ""; - for (std::string const& entry : entries) { - std::vector<std::string> files = cmExpandedList(entry); + for (auto const& entry : entries) { + std::vector<std::string> files = cmExpandedList(entry.Value); for (std::string const& file : files) { if (cmHasLiteralPrefix(file, "$<TARGET_OBJECTS:") && file.back() == '>') { @@ -187,25 +187,16 @@ public: std::set<std::string> SystemIncludeDirectories; cmTarget::LinkLibraryVectorType OriginalLinkLibraries; std::map<std::string, BTs<std::string>> LanguageStandardProperties; - std::vector<std::string> IncludeDirectoriesEntries; - std::vector<cmListFileBacktrace> IncludeDirectoriesBacktraces; + std::vector<BT<std::string>> IncludeDirectoriesEntries; std::vector<std::string> InstallIncludeDirectoriesEntries; - std::vector<std::string> CompileOptionsEntries; - std::vector<cmListFileBacktrace> CompileOptionsBacktraces; - std::vector<std::string> CompileFeaturesEntries; - std::vector<cmListFileBacktrace> CompileFeaturesBacktraces; - std::vector<std::string> CompileDefinitionsEntries; - std::vector<cmListFileBacktrace> CompileDefinitionsBacktraces; - std::vector<std::string> PrecompileHeadersEntries; - std::vector<cmListFileBacktrace> PrecompileHeadersBacktraces; - std::vector<std::string> SourceEntries; - std::vector<cmListFileBacktrace> SourceBacktraces; - std::vector<std::string> LinkOptionsEntries; - std::vector<cmListFileBacktrace> LinkOptionsBacktraces; - std::vector<std::string> LinkDirectoriesEntries; - std::vector<cmListFileBacktrace> LinkDirectoriesBacktraces; - std::vector<std::string> LinkImplementationPropertyEntries; - std::vector<cmListFileBacktrace> LinkImplementationPropertyBacktraces; + std::vector<BT<std::string>> CompileOptionsEntries; + std::vector<BT<std::string>> CompileFeaturesEntries; + std::vector<BT<std::string>> CompileDefinitionsEntries; + std::vector<BT<std::string>> PrecompileHeadersEntries; + std::vector<BT<std::string>> SourceEntries; + std::vector<BT<std::string>> LinkOptionsEntries; + std::vector<BT<std::string>> LinkDirectoriesEntries; + std::vector<BT<std::string>> LinkImplementationPropertyEntries; std::vector<std::pair<cmTarget::TLLSignature, cmListFileContext>> TLLCommands; cmListFileBacktrace Backtrace; @@ -267,7 +258,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, // Replace everything after "CMAKE_" defKey.replace(defKey.begin() + 6, defKey.end(), property); if (cmProp value = mf->GetDefinition(defKey)) { - this->SetProperty(property, *value); + this->SetProperty(property, value); } }; auto initPropValue = [this, mf, &defKey](const std::string& property, @@ -275,7 +266,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, // Replace everything after "CMAKE_" defKey.replace(defKey.begin() + 6, defKey.end(), property); if (cmProp value = mf->GetDefinition(defKey)) { - this->SetProperty(property, *value); + this->SetProperty(property, value); } else if (default_value) { this->SetProperty(property, default_value); } @@ -482,8 +473,6 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, // of the same directory property: cm::append(this->impl->IncludeDirectoriesEntries, this->impl->Makefile->GetIncludeDirectoriesEntries()); - cm::append(this->impl->IncludeDirectoriesBacktraces, - this->impl->Makefile->GetIncludeDirectoriesBacktraces()); { auto const& sysInc = this->impl->Makefile->GetSystemIncludeDirectories(); @@ -493,18 +482,12 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, cm::append(this->impl->CompileOptionsEntries, this->impl->Makefile->GetCompileOptionsEntries()); - cm::append(this->impl->CompileOptionsBacktraces, - this->impl->Makefile->GetCompileOptionsBacktraces()); cm::append(this->impl->LinkOptionsEntries, this->impl->Makefile->GetLinkOptionsEntries()); - cm::append(this->impl->LinkOptionsBacktraces, - this->impl->Makefile->GetLinkOptionsBacktraces()); cm::append(this->impl->LinkDirectoriesEntries, this->impl->Makefile->GetLinkDirectoriesEntries()); - cm::append(this->impl->LinkDirectoriesBacktraces, - this->impl->Makefile->GetLinkDirectoriesBacktraces()); } if (this->impl->TargetType == cmStateEnums::EXECUTABLE) { @@ -613,11 +596,9 @@ void cmTarget::SetLanguageStandardProperty(std::string const& lang, const std::string& feature) { cmListFileBacktrace featureBacktrace; - for (size_t i = 0; i < this->impl->CompileFeaturesEntries.size(); i++) { - if (this->impl->CompileFeaturesEntries[i] == feature) { - if (i < this->impl->CompileFeaturesBacktraces.size()) { - featureBacktrace = this->impl->CompileFeaturesBacktraces[i]; - } + for (auto const& entry : this->impl->CompileFeaturesEntries) { + if (entry.Value == feature) { + featureBacktrace = entry.Backtrace; break; } } @@ -729,8 +710,7 @@ void cmTarget::AddTracedSources(std::vector<std::string> const& srcs) { if (!srcs.empty()) { cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->SourceEntries.push_back(cmJoin(srcs, ";")); - this->impl->SourceBacktraces.push_back(lfbt); + this->impl->SourceEntries.emplace_back(cmJoin(srcs, ";"), lfbt); } } @@ -754,8 +734,7 @@ void cmTarget::AddSources(std::vector<std::string> const& srcs) } if (!srcFiles.empty()) { cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->SourceEntries.push_back(std::move(srcFiles)); - this->impl->SourceBacktraces.push_back(lfbt); + this->impl->SourceEntries.emplace_back(std::move(srcFiles), lfbt); } } @@ -843,9 +822,9 @@ public: { } - bool operator()(std::string const& entry) + bool operator()(BT<std::string> const& entry) { - std::vector<std::string> files = cmExpandedList(entry); + std::vector<std::string> files = cmExpandedList(entry.Value); std::vector<cmSourceFileLocation> locations; locations.reserve(files.size()); std::transform(files.begin(), files.end(), std::back_inserter(locations), @@ -866,11 +845,7 @@ cmSourceFile* cmTarget::AddSource(const std::string& src, bool before) cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); this->impl->SourceEntries.insert(before ? this->impl->SourceEntries.begin() : this->impl->SourceEntries.end(), - src); - this->impl->SourceBacktraces.insert( - before ? this->impl->SourceBacktraces.begin() - : this->impl->SourceBacktraces.end(), - lfbt); + BT<std::string>(src, lfbt)); } if (cmGeneratorExpression::Find(src) != std::string::npos) { return nullptr; @@ -1087,122 +1062,104 @@ cmStringRange cmTarget::GetInstallIncludeDirectoriesEntries() const return cmMakeRange(this->impl->InstallIncludeDirectoriesEntries); } -cmStringRange cmTarget::GetIncludeDirectoriesEntries() const +cmBTStringRange cmTarget::GetIncludeDirectoriesEntries() const { return cmMakeRange(this->impl->IncludeDirectoriesEntries); } -cmBacktraceRange cmTarget::GetIncludeDirectoriesBacktraces() const -{ - return cmMakeRange(this->impl->IncludeDirectoriesBacktraces); -} - -cmStringRange cmTarget::GetCompileOptionsEntries() const +cmBTStringRange cmTarget::GetCompileOptionsEntries() const { return cmMakeRange(this->impl->CompileOptionsEntries); } -cmBacktraceRange cmTarget::GetCompileOptionsBacktraces() const -{ - return cmMakeRange(this->impl->CompileOptionsBacktraces); -} - -cmStringRange cmTarget::GetCompileFeaturesEntries() const +cmBTStringRange cmTarget::GetCompileFeaturesEntries() const { return cmMakeRange(this->impl->CompileFeaturesEntries); } -cmBacktraceRange cmTarget::GetCompileFeaturesBacktraces() const -{ - return cmMakeRange(this->impl->CompileFeaturesBacktraces); -} - -cmStringRange cmTarget::GetCompileDefinitionsEntries() const +cmBTStringRange cmTarget::GetCompileDefinitionsEntries() const { return cmMakeRange(this->impl->CompileDefinitionsEntries); } -cmBacktraceRange cmTarget::GetCompileDefinitionsBacktraces() const -{ - return cmMakeRange(this->impl->CompileDefinitionsBacktraces); -} - -cmStringRange cmTarget::GetPrecompileHeadersEntries() const +cmBTStringRange cmTarget::GetPrecompileHeadersEntries() const { return cmMakeRange(this->impl->PrecompileHeadersEntries); } -cmBacktraceRange cmTarget::GetPrecompileHeadersBacktraces() const -{ - return cmMakeRange(this->impl->PrecompileHeadersBacktraces); -} - -cmStringRange cmTarget::GetSourceEntries() const +cmBTStringRange cmTarget::GetSourceEntries() const { return cmMakeRange(this->impl->SourceEntries); } -cmBacktraceRange cmTarget::GetSourceBacktraces() const -{ - return cmMakeRange(this->impl->SourceBacktraces); -} - -cmStringRange cmTarget::GetLinkOptionsEntries() const +cmBTStringRange cmTarget::GetLinkOptionsEntries() const { return cmMakeRange(this->impl->LinkOptionsEntries); } -cmBacktraceRange cmTarget::GetLinkOptionsBacktraces() const +cmBTStringRange cmTarget::GetLinkDirectoriesEntries() const { - return cmMakeRange(this->impl->LinkOptionsBacktraces); + return cmMakeRange(this->impl->LinkDirectoriesEntries); } -cmStringRange cmTarget::GetLinkDirectoriesEntries() const +cmBTStringRange cmTarget::GetLinkImplementationEntries() const { - return cmMakeRange(this->impl->LinkDirectoriesEntries); + return cmMakeRange(this->impl->LinkImplementationPropertyEntries); } -cmBacktraceRange cmTarget::GetLinkDirectoriesBacktraces() const -{ - return cmMakeRange(this->impl->LinkDirectoriesBacktraces); +namespace { +#define MAKE_PROP(PROP) const std::string prop##PROP = #PROP +MAKE_PROP(C_STANDARD); +MAKE_PROP(CXX_STANDARD); +MAKE_PROP(CUDA_STANDARD); +MAKE_PROP(HIP_STANDARD); +MAKE_PROP(OBJC_STANDARD); +MAKE_PROP(OBJCXX_STANDARD); +MAKE_PROP(COMPILE_DEFINITIONS); +MAKE_PROP(COMPILE_FEATURES); +MAKE_PROP(COMPILE_OPTIONS); +MAKE_PROP(PRECOMPILE_HEADERS); +MAKE_PROP(PRECOMPILE_HEADERS_REUSE_FROM); +MAKE_PROP(CUDA_PTX_COMPILATION); +MAKE_PROP(EXPORT_NAME); +MAKE_PROP(IMPORTED); +MAKE_PROP(IMPORTED_GLOBAL); +MAKE_PROP(INCLUDE_DIRECTORIES); +MAKE_PROP(LINK_OPTIONS); +MAKE_PROP(LINK_DIRECTORIES); +MAKE_PROP(LINK_LIBRARIES); +MAKE_PROP(MANUALLY_ADDED_DEPENDENCIES); +MAKE_PROP(NAME); +MAKE_PROP(SOURCES); +MAKE_PROP(TYPE); +MAKE_PROP(BINARY_DIR); +MAKE_PROP(SOURCE_DIR); +MAKE_PROP(FALSE); +MAKE_PROP(TRUE); +#undef MAKE_PROP } -cmStringRange cmTarget::GetLinkImplementationEntries() const +namespace { +// to workaround bug on GCC/AIX +// Define a template to force conversion to std::string +template <typename ValueType> +std::string ConvertToString(ValueType value); + +template <> +std::string ConvertToString<const char*>(const char* value) { - return cmMakeRange(this->impl->LinkImplementationPropertyEntries); + return std::string(value); } - -cmBacktraceRange cmTarget::GetLinkImplementationBacktraces() const +template <> +std::string ConvertToString<cmProp>(cmProp value) { - return cmMakeRange(this->impl->LinkImplementationPropertyBacktraces); + return std::string(*value); +} } -void cmTarget::SetProperty(const std::string& prop, const char* value) +template <typename ValueType> +void cmTarget::StoreProperty(const std::string& prop, ValueType value) { -#define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP - MAKE_STATIC_PROP(C_STANDARD); - MAKE_STATIC_PROP(CXX_STANDARD); - MAKE_STATIC_PROP(CUDA_STANDARD); - MAKE_STATIC_PROP(HIP_STANDARD); - MAKE_STATIC_PROP(OBJC_STANDARD); - MAKE_STATIC_PROP(OBJCXX_STANDARD); - MAKE_STATIC_PROP(COMPILE_DEFINITIONS); - MAKE_STATIC_PROP(COMPILE_FEATURES); - MAKE_STATIC_PROP(COMPILE_OPTIONS); - MAKE_STATIC_PROP(PRECOMPILE_HEADERS); - MAKE_STATIC_PROP(PRECOMPILE_HEADERS_REUSE_FROM); - MAKE_STATIC_PROP(CUDA_PTX_COMPILATION); - MAKE_STATIC_PROP(EXPORT_NAME); - MAKE_STATIC_PROP(IMPORTED_GLOBAL); - MAKE_STATIC_PROP(INCLUDE_DIRECTORIES); - MAKE_STATIC_PROP(LINK_OPTIONS); - MAKE_STATIC_PROP(LINK_DIRECTORIES); - MAKE_STATIC_PROP(LINK_LIBRARIES); - MAKE_STATIC_PROP(MANUALLY_ADDED_DEPENDENCIES); - MAKE_STATIC_PROP(NAME); - MAKE_STATIC_PROP(SOURCES); - MAKE_STATIC_PROP(TYPE); -#undef MAKE_STATIC_PROP if (prop == propMANUALLY_ADDED_DEPENDENCIES) { this->impl->Makefile->IssueMessage( MessageType::FATAL_ERROR, @@ -1243,75 +1200,57 @@ void cmTarget::SetProperty(const std::string& prop, const char* value) if (prop == propINCLUDE_DIRECTORIES) { this->impl->IncludeDirectoriesEntries.clear(); - this->impl->IncludeDirectoriesBacktraces.clear(); if (value) { - this->impl->IncludeDirectoriesEntries.emplace_back(value); cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->IncludeDirectoriesBacktraces.push_back(lfbt); + this->impl->IncludeDirectoriesEntries.emplace_back(value, lfbt); } } else if (prop == propCOMPILE_OPTIONS) { this->impl->CompileOptionsEntries.clear(); - this->impl->CompileOptionsBacktraces.clear(); if (value) { - this->impl->CompileOptionsEntries.emplace_back(value); cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->CompileOptionsBacktraces.push_back(lfbt); + this->impl->CompileOptionsEntries.emplace_back(value, lfbt); } } else if (prop == propCOMPILE_FEATURES) { this->impl->CompileFeaturesEntries.clear(); - this->impl->CompileFeaturesBacktraces.clear(); if (value) { - this->impl->CompileFeaturesEntries.emplace_back(value); cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->CompileFeaturesBacktraces.push_back(lfbt); + this->impl->CompileFeaturesEntries.emplace_back(value, lfbt); } } else if (prop == propCOMPILE_DEFINITIONS) { this->impl->CompileDefinitionsEntries.clear(); - this->impl->CompileDefinitionsBacktraces.clear(); if (value) { - this->impl->CompileDefinitionsEntries.emplace_back(value); cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->CompileDefinitionsBacktraces.push_back(lfbt); + this->impl->CompileDefinitionsEntries.emplace_back(value, lfbt); } } else if (prop == propLINK_OPTIONS) { this->impl->LinkOptionsEntries.clear(); - this->impl->LinkOptionsBacktraces.clear(); if (value) { - this->impl->LinkOptionsEntries.emplace_back(value); cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->LinkOptionsBacktraces.push_back(lfbt); + this->impl->LinkOptionsEntries.emplace_back(value, lfbt); } } else if (prop == propLINK_DIRECTORIES) { this->impl->LinkDirectoriesEntries.clear(); - this->impl->LinkDirectoriesBacktraces.clear(); if (value) { - this->impl->LinkDirectoriesEntries.emplace_back(value); cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->LinkDirectoriesBacktraces.push_back(lfbt); + this->impl->LinkDirectoriesEntries.emplace_back(value, lfbt); } } else if (prop == propPRECOMPILE_HEADERS) { this->impl->PrecompileHeadersEntries.clear(); - this->impl->PrecompileHeadersBacktraces.clear(); if (value) { - this->impl->PrecompileHeadersEntries.emplace_back(value); cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->PrecompileHeadersBacktraces.push_back(lfbt); + this->impl->PrecompileHeadersEntries.emplace_back(value, lfbt); } } else if (prop == propLINK_LIBRARIES) { this->impl->LinkImplementationPropertyEntries.clear(); - this->impl->LinkImplementationPropertyBacktraces.clear(); if (value) { cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->LinkImplementationPropertyEntries.emplace_back(value); - this->impl->LinkImplementationPropertyBacktraces.push_back(lfbt); + this->impl->LinkImplementationPropertyEntries.emplace_back(value, lfbt); } } else if (prop == propSOURCES) { this->impl->SourceEntries.clear(); - this->impl->SourceBacktraces.clear(); if (value) { cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->SourceEntries.emplace_back(value); - this->impl->SourceBacktraces.push_back(lfbt); + this->impl->SourceEntries.emplace_back(value, lfbt); } } else if (prop == propIMPORTED_GLOBAL) { if (!cmIsOn(value)) { @@ -1327,7 +1266,8 @@ void cmTarget::SetProperty(const std::string& prop, const char* value) this->GetGlobalGenerator()->IndexTarget(this); } } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME") && - !this->impl->CheckImportedLibName(prop, value ? value : "")) { + !this->impl->CheckImportedLibName( + prop, value ? value : std::string{})) { /* error was reported by check method */ } else if (prop == propCUDA_PTX_COMPILATION && this->GetType() != cmStateEnums::OBJECT_LIBRARY) { @@ -1357,17 +1297,17 @@ void cmTarget::SetProperty(const std::string& prop, const char* value) std::string reusedFrom = reusedTarget->GetSafeProperty(prop); if (reusedFrom.empty()) { - reusedFrom = value; + reusedFrom = ConvertToString(value); } - this->impl->Properties.SetProperty(prop, reusedFrom.c_str()); + this->impl->Properties.SetProperty(prop, reusedFrom); reusedTarget->SetProperty("COMPILE_PDB_NAME", reusedFrom); reusedTarget->SetProperty("COMPILE_PDB_OUTPUT_DIRECTORY", cmStrCat(reusedFrom, ".dir/")); cmProp tmp = reusedTarget->GetProperty("COMPILE_PDB_NAME"); - this->SetProperty("COMPILE_PDB_NAME", cmToCStr(tmp)); + this->SetProperty("COMPILE_PDB_NAME", tmp); this->AddUtility(reusedFrom, false, this->impl->Makefile); } else if (prop == propC_STANDARD || prop == propCXX_STANDARD || prop == propCUDA_STANDARD || prop == propHIP_STANDARD || @@ -1415,39 +1355,33 @@ void cmTarget::AppendProperty(const std::string& prop, } if (prop == "INCLUDE_DIRECTORIES") { if (!value.empty()) { - this->impl->IncludeDirectoriesEntries.emplace_back(value); cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->IncludeDirectoriesBacktraces.push_back(lfbt); + this->impl->IncludeDirectoriesEntries.emplace_back(value, lfbt); } } else if (prop == "COMPILE_OPTIONS") { if (!value.empty()) { - this->impl->CompileOptionsEntries.emplace_back(value); cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->CompileOptionsBacktraces.push_back(lfbt); + this->impl->CompileOptionsEntries.emplace_back(value, lfbt); } } else if (prop == "COMPILE_FEATURES") { if (!value.empty()) { - this->impl->CompileFeaturesEntries.emplace_back(value); cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->CompileFeaturesBacktraces.push_back(lfbt); + this->impl->CompileFeaturesEntries.emplace_back(value, lfbt); } } else if (prop == "COMPILE_DEFINITIONS") { if (!value.empty()) { - this->impl->CompileDefinitionsEntries.emplace_back(value); cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->CompileDefinitionsBacktraces.push_back(lfbt); + this->impl->CompileDefinitionsEntries.emplace_back(value, lfbt); } } else if (prop == "LINK_OPTIONS") { if (!value.empty()) { - this->impl->LinkOptionsEntries.emplace_back(value); cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->LinkOptionsBacktraces.push_back(lfbt); + this->impl->LinkOptionsEntries.emplace_back(value, lfbt); } } else if (prop == "LINK_DIRECTORIES") { if (!value.empty()) { - this->impl->LinkDirectoriesEntries.emplace_back(value); cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->LinkDirectoriesBacktraces.push_back(lfbt); + this->impl->LinkDirectoriesEntries.emplace_back(value, lfbt); } } else if (prop == "PRECOMPILE_HEADERS") { if (this->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM")) { @@ -1459,20 +1393,17 @@ void cmTarget::AppendProperty(const std::string& prop, return; } if (!value.empty()) { - this->impl->PrecompileHeadersEntries.emplace_back(value); cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->PrecompileHeadersBacktraces.push_back(lfbt); + this->impl->PrecompileHeadersEntries.emplace_back(value, lfbt); } } else if (prop == "LINK_LIBRARIES") { if (!value.empty()) { cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->LinkImplementationPropertyEntries.emplace_back(value); - this->impl->LinkImplementationPropertyBacktraces.push_back(lfbt); + this->impl->LinkImplementationPropertyEntries.emplace_back(value, lfbt); } } else if (prop == "SOURCES") { cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->SourceEntries.emplace_back(value); - this->impl->SourceBacktraces.push_back(lfbt); + this->impl->SourceEntries.emplace_back(value, lfbt); } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME")) { this->impl->Makefile->IssueMessage( MessageType::FATAL_ERROR, prop + " property may not be APPENDed."); @@ -1486,6 +1417,15 @@ void cmTarget::AppendProperty(const std::string& prop, } } +void cmTarget::SetProperty(const std::string& prop, const char* value) +{ + this->StoreProperty(prop, value); +} +void cmTarget::SetProperty(const std::string& prop, cmProp value) +{ + this->StoreProperty(prop, value); +} + void cmTarget::AppendBuildInterfaceIncludes() { if (this->GetType() != cmStateEnums::SHARED_LIBRARY && @@ -1513,70 +1453,46 @@ void cmTarget::AppendBuildInterfaceIncludes() } } -void cmTarget::InsertInclude(std::string const& entry, - cmListFileBacktrace const& bt, bool before) +void cmTarget::InsertInclude(BT<std::string> const& entry, bool before) { auto position = before ? this->impl->IncludeDirectoriesEntries.begin() : this->impl->IncludeDirectoriesEntries.end(); - auto btPosition = before ? this->impl->IncludeDirectoriesBacktraces.begin() - : this->impl->IncludeDirectoriesBacktraces.end(); - this->impl->IncludeDirectoriesEntries.insert(position, entry); - this->impl->IncludeDirectoriesBacktraces.insert(btPosition, bt); } -void cmTarget::InsertCompileOption(std::string const& entry, - cmListFileBacktrace const& bt, bool before) +void cmTarget::InsertCompileOption(BT<std::string> const& entry, bool before) { auto position = before ? this->impl->CompileOptionsEntries.begin() : this->impl->CompileOptionsEntries.end(); - auto btPosition = before ? this->impl->CompileOptionsBacktraces.begin() - : this->impl->CompileOptionsBacktraces.end(); - this->impl->CompileOptionsEntries.insert(position, entry); - this->impl->CompileOptionsBacktraces.insert(btPosition, bt); } -void cmTarget::InsertCompileDefinition(std::string const& entry, - cmListFileBacktrace const& bt) +void cmTarget::InsertCompileDefinition(BT<std::string> const& entry) { this->impl->CompileDefinitionsEntries.push_back(entry); - this->impl->CompileDefinitionsBacktraces.push_back(bt); } -void cmTarget::InsertLinkOption(std::string const& entry, - cmListFileBacktrace const& bt, bool before) +void cmTarget::InsertLinkOption(BT<std::string> const& entry, bool before) { auto position = before ? this->impl->LinkOptionsEntries.begin() : this->impl->LinkOptionsEntries.end(); - auto btPosition = before ? this->impl->LinkOptionsBacktraces.begin() - : this->impl->LinkOptionsBacktraces.end(); - this->impl->LinkOptionsEntries.insert(position, entry); - this->impl->LinkOptionsBacktraces.insert(btPosition, bt); } -void cmTarget::InsertLinkDirectory(std::string const& entry, - cmListFileBacktrace const& bt, bool before) +void cmTarget::InsertLinkDirectory(BT<std::string> const& entry, bool before) { auto position = before ? this->impl->LinkDirectoriesEntries.begin() : this->impl->LinkDirectoriesEntries.end(); - auto btPosition = before ? this->impl->LinkDirectoriesBacktraces.begin() - : this->impl->LinkDirectoriesBacktraces.end(); - this->impl->LinkDirectoriesEntries.insert(position, entry); - this->impl->LinkDirectoriesBacktraces.insert(btPosition, bt); } -void cmTarget::InsertPrecompileHeader(std::string const& entry, - cmListFileBacktrace const& bt) +void cmTarget::InsertPrecompileHeader(BT<std::string> const& entry) { this->impl->PrecompileHeadersEntries.push_back(entry); - this->impl->PrecompileHeadersBacktraces.push_back(bt); } static void cmTargetCheckLINK_INTERFACE_LIBRARIES(const std::string& prop, @@ -1693,31 +1609,6 @@ cmProp cmTarget::GetComputedProperty(const std::string& prop, cmProp cmTarget::GetProperty(const std::string& prop) const { -#define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP - MAKE_STATIC_PROP(C_STANDARD); - MAKE_STATIC_PROP(CXX_STANDARD); - MAKE_STATIC_PROP(CUDA_STANDARD); - MAKE_STATIC_PROP(OBJC_STANDARD); - MAKE_STATIC_PROP(OBJCXX_STANDARD); - MAKE_STATIC_PROP(LINK_LIBRARIES); - MAKE_STATIC_PROP(TYPE); - MAKE_STATIC_PROP(INCLUDE_DIRECTORIES); - MAKE_STATIC_PROP(COMPILE_FEATURES); - MAKE_STATIC_PROP(COMPILE_OPTIONS); - MAKE_STATIC_PROP(COMPILE_DEFINITIONS); - MAKE_STATIC_PROP(LINK_OPTIONS); - MAKE_STATIC_PROP(LINK_DIRECTORIES); - MAKE_STATIC_PROP(PRECOMPILE_HEADERS); - MAKE_STATIC_PROP(IMPORTED); - MAKE_STATIC_PROP(IMPORTED_GLOBAL); - MAKE_STATIC_PROP(MANUALLY_ADDED_DEPENDENCIES); - MAKE_STATIC_PROP(NAME); - MAKE_STATIC_PROP(BINARY_DIR); - MAKE_STATIC_PROP(SOURCE_DIR); - MAKE_STATIC_PROP(SOURCES); - MAKE_STATIC_PROP(FALSE); - MAKE_STATIC_PROP(TRUE); -#undef MAKE_STATIC_PROP static std::unordered_set<std::string> const specialProps{ propC_STANDARD, propCXX_STANDARD, diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 29130c7..eced1ae 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -170,9 +170,10 @@ public: //! Set/Get a property of this target file void SetProperty(const std::string& prop, const char* value); + void SetProperty(const std::string& prop, cmProp value); void SetProperty(const std::string& prop, const std::string& value) { - this->SetProperty(prop, value.c_str()); + this->SetProperty(prop, cmProp(value)); } void AppendProperty(const std::string& prop, const std::string& value, bool asString = false); @@ -216,18 +217,12 @@ public: //! Get a backtrace from the creation of the target. cmListFileBacktrace const& GetBacktrace() const; - void InsertInclude(std::string const& entry, cmListFileBacktrace const& bt, - bool before = false); - void InsertCompileOption(std::string const& entry, - cmListFileBacktrace const& bt, bool before = false); - void InsertCompileDefinition(std::string const& entry, - cmListFileBacktrace const& bt); - void InsertLinkOption(std::string const& entry, - cmListFileBacktrace const& bt, bool before = false); - void InsertLinkDirectory(std::string const& entry, - cmListFileBacktrace const& bt, bool before = false); - void InsertPrecompileHeader(std::string const& entry, - cmListFileBacktrace const& bt); + void InsertInclude(BT<std::string> const& entry, bool before = false); + void InsertCompileOption(BT<std::string> const& entry, bool before = false); + void InsertCompileDefinition(BT<std::string> const& entry); + void InsertLinkOption(BT<std::string> const& entry, bool before = false); + void InsertLinkDirectory(BT<std::string> const& entry, bool before = false); + void InsertPrecompileHeader(BT<std::string> const& entry); void AppendBuildInterfaceIncludes(); @@ -247,32 +242,23 @@ public: std::string const& value, const std::string& feature); - cmStringRange GetIncludeDirectoriesEntries() const; - cmBacktraceRange GetIncludeDirectoriesBacktraces() const; + cmBTStringRange GetIncludeDirectoriesEntries() const; - cmStringRange GetCompileOptionsEntries() const; - cmBacktraceRange GetCompileOptionsBacktraces() const; + cmBTStringRange GetCompileOptionsEntries() const; - cmStringRange GetCompileFeaturesEntries() const; - cmBacktraceRange GetCompileFeaturesBacktraces() const; + cmBTStringRange GetCompileFeaturesEntries() const; - cmStringRange GetCompileDefinitionsEntries() const; - cmBacktraceRange GetCompileDefinitionsBacktraces() const; + cmBTStringRange GetCompileDefinitionsEntries() const; - cmStringRange GetPrecompileHeadersEntries() const; - cmBacktraceRange GetPrecompileHeadersBacktraces() const; + cmBTStringRange GetPrecompileHeadersEntries() const; - cmStringRange GetSourceEntries() const; - cmBacktraceRange GetSourceBacktraces() const; + cmBTStringRange GetSourceEntries() const; - cmStringRange GetLinkOptionsEntries() const; - cmBacktraceRange GetLinkOptionsBacktraces() const; + cmBTStringRange GetLinkOptionsEntries() const; - cmStringRange GetLinkDirectoriesEntries() const; - cmBacktraceRange GetLinkDirectoriesBacktraces() const; + cmBTStringRange GetLinkDirectoriesEntries() const; - cmStringRange GetLinkImplementationEntries() const; - cmBacktraceRange GetLinkImplementationBacktraces() const; + cmBTStringRange GetLinkImplementationEntries() const; std::string ImportedGetFullPath(const std::string& config, cmStateEnums::ArtifactType artifact) const; @@ -283,6 +269,9 @@ public: }; private: + template <typename ValueType> + void StoreProperty(const std::string& prop, ValueType value); + // Internal representation details. friend class cmGeneratorTarget; diff --git a/Source/cmTargetCompileOptionsCommand.cxx b/Source/cmTargetCompileOptionsCommand.cxx index dee2c10..8ca3842 100644 --- a/Source/cmTargetCompileOptionsCommand.cxx +++ b/Source/cmTargetCompileOptionsCommand.cxx @@ -37,7 +37,8 @@ private: } cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); - tgt->InsertCompileOption(this->Join(content), lfbt, prepend); + tgt->InsertCompileOption(BT<std::string>(this->Join(content), lfbt), + prepend); return true; // Successfully handled. } diff --git a/Source/cmTargetIncludeDirectoriesCommand.cxx b/Source/cmTargetIncludeDirectoriesCommand.cxx index 3897499..f31501e 100644 --- a/Source/cmTargetIncludeDirectoriesCommand.cxx +++ b/Source/cmTargetIncludeDirectoriesCommand.cxx @@ -63,7 +63,7 @@ bool TargetIncludeDirectoriesImpl::HandleDirectContent( bool system) { cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); - tgt->InsertInclude(this->Join(content), lfbt, prepend); + tgt->InsertInclude(BT<std::string>(this->Join(content), lfbt), prepend); if (system) { std::string prefix = this->Makefile->GetCurrentSourceDirectory() + "/"; std::set<std::string> sdirs; diff --git a/Source/cmTargetLinkDirectoriesCommand.cxx b/Source/cmTargetLinkDirectoriesCommand.cxx index 0c68d60..3ba27a8 100644 --- a/Source/cmTargetLinkDirectoriesCommand.cxx +++ b/Source/cmTargetLinkDirectoriesCommand.cxx @@ -34,7 +34,8 @@ private: bool prepend, bool /*system*/) override { cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); - tgt->InsertLinkDirectory(this->Join(content), lfbt, prepend); + tgt->InsertLinkDirectory(BT<std::string>(this->Join(content), lfbt), + prepend); return true; // Successfully handled. } }; diff --git a/Source/cmTargetLinkOptionsCommand.cxx b/Source/cmTargetLinkOptionsCommand.cxx index df9416f..3ea2d71 100644 --- a/Source/cmTargetLinkOptionsCommand.cxx +++ b/Source/cmTargetLinkOptionsCommand.cxx @@ -30,7 +30,7 @@ private: bool prepend, bool /*system*/) override { cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); - tgt->InsertLinkOption(this->Join(content), lfbt, prepend); + tgt->InsertLinkOption(BT<std::string>(this->Join(content), lfbt), prepend); return true; // Successfully handled. } diff --git a/Source/cmTest.cxx b/Source/cmTest.cxx index 5bc10c2..9d25ce9 100644 --- a/Source/cmTest.cxx +++ b/Source/cmTest.cxx @@ -57,6 +57,10 @@ void cmTest::SetProperty(const std::string& prop, const char* value) { this->Properties.SetProperty(prop, value); } +void cmTest::SetProperty(const std::string& prop, cmProp value) +{ + this->Properties.SetProperty(prop, value); +} void cmTest::AppendProperty(const std::string& prop, const std::string& value, bool asString) diff --git a/Source/cmTest.h b/Source/cmTest.h index 63e5e87..a790501 100644 --- a/Source/cmTest.h +++ b/Source/cmTest.h @@ -35,6 +35,11 @@ public: //! Set/Get a property of this source file void SetProperty(const std::string& prop, const char* value); + void SetProperty(const std::string& prop, cmProp value); + void SetProperty(const std::string& prop, const std::string& value) + { + this->SetProperty(prop, cmProp(value)); + } void AppendProperty(const std::string& prop, const std::string& value, bool asString = false); cmProp GetProperty(const std::string& prop) const; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 7f8f654..beb5d16 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2919,6 +2919,10 @@ void cmake::SetProperty(const std::string& prop, const char* value) { this->State->SetGlobalProperty(prop, value); } +void cmake::SetProperty(const std::string& prop, cmProp value) +{ + this->State->SetGlobalProperty(prop, value); +} void cmake::AppendProperty(const std::string& prop, const std::string& value, bool asString) diff --git a/Source/cmake.h b/Source/cmake.h index 12cce7e..32c7582 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -396,6 +396,11 @@ public: //! Set/Get a property of this target file void SetProperty(const std::string& prop, const char* value); + void SetProperty(const std::string& prop, cmProp value); + void SetProperty(const std::string& prop, const std::string& value) + { + this->SetProperty(prop, cmProp(value)); + } void AppendProperty(const std::string& prop, const std::string& value, bool asString = false); cmProp GetProperty(const std::string& prop); diff --git a/Source/kwsys/Status.hxx.in b/Source/kwsys/Status.hxx.in index ed46d5c..16efaef 100644 --- a/Source/kwsys/Status.hxx.in +++ b/Source/kwsys/Status.hxx.in @@ -55,7 +55,10 @@ public: #endif /** Return true on "Success", false otherwise. */ - explicit operator bool() const { return this->Kind_ == Kind::Success; } + bool IsSuccess() const { return this->Kind_ == Kind::Success; } + + /** Return true on "Success", false otherwise. */ + explicit operator bool() const { return this->IsSuccess(); } /** Return the kind of status. */ Kind GetKind() const { return this->Kind_; } diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx index 12f9139..f2bf85f 100644 --- a/Source/kwsys/SystemInformation.cxx +++ b/Source/kwsys/SystemInformation.cxx @@ -1356,14 +1356,12 @@ std::string SymbolProperties::Demangle(const char* symbol) const std::string result = safes(symbol); # if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE) int status = 0; - size_t bufferLen = 1024; - char* buffer = (char*)malloc(1024); char* demangledSymbol = - abi::__cxa_demangle(symbol, buffer, &bufferLen, &status); + abi::__cxa_demangle(symbol, nullptr, nullptr, &status); if (!status) { result = demangledSymbol; } - free(buffer); + free(demangledSymbol); # else (void)symbol; # endif diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 7c26974..930d84c 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -14,6 +14,10 @@ # endif #endif +#if defined(_WIN32) && !defined(_WIN32_WINNT) +# define _WIN32_WINNT _WIN32_WINNT_VISTA +#endif + #include "kwsysPrivate.h" #include KWSYS_HEADER(RegularExpression.hxx) #include KWSYS_HEADER(SystemTools.hxx) @@ -2419,7 +2423,7 @@ Status SystemTools::CopyFileAlways(std::string const& source, if (SystemTools::FileIsDirectory(source)) { status = SystemTools::MakeDirectory(destination); - if (!status) { + if (!status.IsSuccess()) { return status; } } else { @@ -2444,17 +2448,17 @@ Status SystemTools::CopyFileAlways(std::string const& source, // Create destination directory if (!destination_dir.empty()) { status = SystemTools::MakeDirectory(destination_dir); - if (!status) { + if (!status.IsSuccess()) { return status; } } status = SystemTools::CloneFileContent(source, real_destination); // if cloning did not succeed, fall back to blockwise copy - if (!status) { + if (!status.IsSuccess()) { status = SystemTools::CopyFileContentBlockwise(source, real_destination); } - if (!status) { + if (!status.IsSuccess()) { return status; } } @@ -2484,11 +2488,11 @@ Status SystemTools::CopyADirectory(std::string const& source, Status status; Directory dir; status = dir.Load(source); - if (!status) { + if (!status.IsSuccess()) { return status; } status = SystemTools::MakeDirectory(destination); - if (!status) { + if (!status.IsSuccess()) { return status; } @@ -2503,12 +2507,12 @@ Status SystemTools::CopyADirectory(std::string const& source, fullDestPath += "/"; fullDestPath += dir.GetFile(static_cast<unsigned long>(fileNum)); status = SystemTools::CopyADirectory(fullPath, fullDestPath, always); - if (!status) { + if (!status.IsSuccess()) { return status; } } else { status = SystemTools::CopyAFile(fullPath, destination, always); - if (!status) { + if (!status.IsSuccess()) { return status; } } @@ -2660,7 +2664,7 @@ Status SystemTools::RemoveADirectory(std::string const& source) Status status; Directory dir; status = dir.Load(source); - if (!status) { + if (!status.IsSuccess()) { return status; } @@ -2674,12 +2678,12 @@ Status SystemTools::RemoveADirectory(std::string const& source) if (SystemTools::FileIsDirectory(fullPath) && !SystemTools::FileIsSymlink(fullPath)) { status = SystemTools::RemoveADirectory(fullPath); - if (!status) { + if (!status.IsSuccess()) { return status; } } else { status = SystemTools::RemoveFile(fullPath); - if (!status) { + if (!status.IsSuccess()) { return status; } } @@ -3143,7 +3147,7 @@ Status SystemTools::ReadSymlink(std::string const& newName, status = Status::Windows_GetLastError(); } CloseHandle(hFile); - if (!status) { + if (!status.IsSuccess()) { return status; } PREPARSE_DATA_BUFFER data = diff --git a/Source/kwsys/testDirectory.cxx b/Source/kwsys/testDirectory.cxx index 06a22dc..a847462 100644 --- a/Source/kwsys/testDirectory.cxx +++ b/Source/kwsys/testDirectory.cxx @@ -122,7 +122,7 @@ int _copyDirectoryTest() } const Status copysuccess = SystemTools::CopyADirectory(source, destination); const bool destinationexists = SystemTools::PathExists(destination); - if (copysuccess) { + if (copysuccess.IsSuccess()) { std::cerr << "CopyADirectory should have returned false" << std::endl; SystemTools::RemoveADirectory(destination); return 3; diff --git a/Source/kwsys/testStatus.cxx b/Source/kwsys/testStatus.cxx index f85ef42..0a767a8 100644 --- a/Source/kwsys/testStatus.cxx +++ b/Source/kwsys/testStatus.cxx @@ -31,6 +31,10 @@ int testStatus(int, char* []) std::cerr << "Status Success constructor does not produce Success\n"; res = false; } + if (!status.IsSuccess()) { + std::cerr << "Status Success gives false IsSuccess\n"; + res = false; + } if (!status) { std::cerr << "Status Success kind is not true\n"; res = false; @@ -55,6 +59,10 @@ int testStatus(int, char* []) std::cerr << "Status POSIX constructor does not produce POSIX\n"; res = false; } + if (status.IsSuccess()) { + std::cerr << "Status POSIX gives true IsSuccess\n"; + res = false; + } if (status) { std::cerr << "Status POSIX kind is not false\n"; res = false; @@ -87,6 +95,10 @@ int testStatus(int, char* []) std::cerr << "Status Windows constructor does not produce Windows\n"; res = false; } + if (status.IsSuccess()) { + std::cerr << "Status Windows gives true IsSuccess\n"; + res = false; + } if (status) { std::cerr << "Status Windows kind is not false\n"; res = false; diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx index 39a19cb..6ccc7a7 100644 --- a/Source/kwsys/testSystemTools.cxx +++ b/Source/kwsys/testSystemTools.cxx @@ -436,7 +436,7 @@ static bool CheckFileOperations() if (symlinkStatus.GetWindows() != ERROR_PRIVILEGE_NOT_HELD) #endif { - if (!symlinkStatus) { + if (!symlinkStatus.IsSuccess()) { std::cerr << "CreateSymlink for: " << testBadSymlink << " -> " << testBadSymlinkTgt << " failed: " << symlinkStatus.GetString() << std::endl; diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 9dab5b9..76c6c05 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1649,15 +1649,14 @@ if(BUILD_TESTING) DEPENDS ExternalProjectUpdateSetup ) execute_process( - COMMAND ${CMAKE_CMAKE_COMMAND} + COMMAND ${CMAKE_COMMAND} "-E" create_symlink "${CMake_SOURCE_DIR}/Tests/CMakeLists.txt" # random source file that exists "${CMake_BINARY_DIR}/Tests/try_to_create_symlink" # random target file in existing directory - RESULT_VARIABLE _failed + RESULT_VARIABLE _symlink_result ) - if(_failed) - message("Failed to create a simple symlink on this machine. Skipping InstallMode tests.") - else() + if(_symlink_result EQUAL 0) + file(REMOVE "${CMake_BINARY_DIR}/Tests/try_to_create_symlink") function(add_installmode_test _mode) set(ENV{CMAKE_INSTALL_MODE} _mode) set(_maybe_InstallMode_CTEST_OPTIONS) diff --git a/Tests/InstallMode/Subproject.cmake b/Tests/InstallMode/Subproject.cmake index e4354d6..826e61e 100644 --- a/Tests/InstallMode/Subproject.cmake +++ b/Tests/InstallMode/Subproject.cmake @@ -10,12 +10,7 @@ function(add_subproject _name) set(_maybe_NO_INSTALL) if(_arg_NO_INSTALL) - set(_maybe_NO_INSTALL "INSTALL_COMMAND") - else() - # This is a trick to get a valid call. - # Since we set UPDATE_COMMAND to "" - # explicitly below, this won't harm. - set(_maybe_NO_INSTALL "UPDATE_COMMAND") + set(_maybe_NO_INSTALL INSTALL_COMMAND "") endif() if(CMAKE_GENERATOR MATCHES "Ninja Multi-Config") @@ -35,7 +30,9 @@ function(add_subproject _name) ExternalProject_Add("${_name}" DOWNLOAD_COMMAND "" UPDATE_COMMAND "" - ${_maybe_NO_INSTALL} "" + UPDATE_DISCONNECTED ON + + "${_maybe_NO_INSTALL}" BUILD_ALWAYS ON @@ -67,7 +64,7 @@ function(add_subproject _name) # however, we need to explicitly inherit other parent # project's build settings. "-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}" - ${_maybe_NINJA_MULTICONFIG_ARGS} + "${_maybe_NINJA_MULTICONFIG_ARGS}" # Subproject progress reports clutter up the output, disable "-DCMAKE_TARGET_MESSAGES:BOOL=OFF" diff --git a/Tests/InstallMode/subpro_b_shared_lib/CMakeLists.txt b/Tests/InstallMode/subpro_b_shared_lib/CMakeLists.txt index eb118c9..b3d9cb2 100644 --- a/Tests/InstallMode/subpro_b_shared_lib/CMakeLists.txt +++ b/Tests/InstallMode/subpro_b_shared_lib/CMakeLists.txt @@ -4,12 +4,18 @@ cmake_minimum_required(VERSION 3.20) project(shared_lib_project VERSION 2.3.4 LANGUAGES CXX) include(GNUInstallDirs) +include(GenerateExportHeader) add_library(the_shared_lib SHARED "include/shared_lib.h" "src/shared_lib.cpp" ) +generate_export_header(the_shared_lib + BASE_NAME shared_lib + EXPORT_FILE_NAME include/shared_lib_export.h +) + set_target_properties(the_shared_lib PROPERTIES VERSION "${PROJECT_VERSION}" @@ -18,11 +24,14 @@ set_target_properties(the_shared_lib target_include_directories(the_shared_lib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) install( - DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" + DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}/include/" + "${CMAKE_CURRENT_BINARY_DIR}/include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) diff --git a/Tests/InstallMode/subpro_b_shared_lib/include/shared_lib.h b/Tests/InstallMode/subpro_b_shared_lib/include/shared_lib.h index fd960db..550b2b4 100644 --- a/Tests/InstallMode/subpro_b_shared_lib/include/shared_lib.h +++ b/Tests/InstallMode/subpro_b_shared_lib/include/shared_lib.h @@ -1,3 +1,5 @@ #pragma once -void shared_hello(); +#include <shared_lib_export.h> + +void SHARED_LIB_EXPORT shared_hello(); diff --git a/Tests/InstallMode/subpro_c_nested_lib/subsubpro_c2_lib/CMakeLists.txt b/Tests/InstallMode/subpro_c_nested_lib/subsubpro_c2_lib/CMakeLists.txt index e139446..7580c77 100644 --- a/Tests/InstallMode/subpro_c_nested_lib/subsubpro_c2_lib/CMakeLists.txt +++ b/Tests/InstallMode/subpro_c_nested_lib/subsubpro_c2_lib/CMakeLists.txt @@ -18,6 +18,9 @@ target_link_libraries(the_c2_lib the_c1_lib ) +# This is to fix an issue on AIX/GCC (see commit 4fc47424) +set_property(TARGET the_c2_lib PROPERTY NO_SYSTEM_FROM_IMPORTED 1) + target_include_directories(the_c2_lib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> diff --git a/Tests/InstallMode/subpro_d_executable/CMakeLists.txt b/Tests/InstallMode/subpro_d_executable/CMakeLists.txt index 9847227..60189e2 100644 --- a/Tests/InstallMode/subpro_d_executable/CMakeLists.txt +++ b/Tests/InstallMode/subpro_d_executable/CMakeLists.txt @@ -17,6 +17,9 @@ target_link_libraries(the_executable PRIVATE the_c2_lib ) +# This is to fix an issue on AIX/GCC (see commit 4fc47424) +set_property(TARGET the_executable PROPERTY NO_SYSTEM_FROM_IMPORTED 1) + install( TARGETS the_executable diff --git a/Utilities/Scripts/update-libarchive.bash b/Utilities/Scripts/update-libarchive.bash index 3db89ff..3a24e2b 100755 --- a/Utilities/Scripts/update-libarchive.bash +++ b/Utilities/Scripts/update-libarchive.bash @@ -8,7 +8,7 @@ readonly name="LibArchive" readonly ownership="LibArchive Upstream <libarchive-discuss@googlegroups.com>" readonly subtree="Utilities/cmlibarchive" readonly repo="https://github.com/libarchive/libarchive.git" -readonly tag="v3.4.2" +readonly tag="v3.5.1" readonly shortlog=false readonly paths=" CMakeLists.txt diff --git a/Utilities/cmThirdPartyChecks.cmake b/Utilities/cmThirdPartyChecks.cmake index bab3046..7e38df9 100644 --- a/Utilities/cmThirdPartyChecks.cmake +++ b/Utilities/cmThirdPartyChecks.cmake @@ -180,6 +180,7 @@ if(WIN32) set(HAVE_STRERROR_R 0) set(HAVE_STRNCMPI 0) set(HAVE_STRNCPY_S 1) + set(HAVE_STRNLEN 1) set(HAVE_STROPTS_H 0) set(HAVE__STRTOI64 1) set(HAVE_STRTOLL 1) diff --git a/Utilities/cmlibarchive/CMakeLists.txt b/Utilities/cmlibarchive/CMakeLists.txt index 79452ff..ba65470 100644 --- a/Utilities/cmlibarchive/CMakeLists.txt +++ b/Utilities/cmlibarchive/CMakeLists.txt @@ -171,32 +171,32 @@ IF (MSVC) # This is added into CMAKE_C_FLAGS when CMAKE_BUILD_TYPE is "Debug" # Enable level 4 C4062: The enumerate has no associated handler in a switch # statement and there is no default that can catch it. - SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /we4062") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /w14062") # Enable level 4 C4254: A larger bit field was assigned to a smaller bit # field. - SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /we4254") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /w14254") # Enable level 4 C4295: An array was initialized but the last character in # the array is not a null; accessing the array may # produce unexpected results. - SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /we4295") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /w14295") # Enable level 4 C4296: An unsigned variable was used in a comparison # operation with zero. - SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /we4296") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /w14296") # Enable level 4 C4389: An operation involved signed and unsigned variables. # This could result in a loss of data. - SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /we4389") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /w14389") # Enable level 4 C4505: The given function is local and not referenced in # the body of the module; therefore, the function is # dead code. - SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /we4505") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /w14505") # Enable level 4 C4514: The optimizer removed an inline function that is not # called. - SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /we4514") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /w14514") # Enable level 4 C4702: Unreachable code. - SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /we4702") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /w14702") # Enable level 4 C4706: The test value in a conditional expression was the # result of an assignment. - SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /we4706") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /w14706") # /Oi option enables built-in functions. SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Oi") ################################################################# @@ -1404,6 +1404,7 @@ CHECK_FUNCTION_EXISTS_GLIBC(strchr HAVE_STRCHR) CHECK_FUNCTION_EXISTS_GLIBC(strdup HAVE_STRDUP) CHECK_FUNCTION_EXISTS_GLIBC(strerror HAVE_STRERROR) CHECK_FUNCTION_EXISTS_GLIBC(strncpy_s HAVE_STRNCPY_S) +CHECK_FUNCTION_EXISTS_GLIBC(strnlen HAVE_STRNLEN) CHECK_FUNCTION_EXISTS_GLIBC(strrchr HAVE_STRRCHR) CHECK_FUNCTION_EXISTS_GLIBC(symlink HAVE_SYMLINK) CHECK_FUNCTION_EXISTS_GLIBC(timegm HAVE_TIMEGM) @@ -1475,15 +1476,19 @@ CHECK_C_SOURCE_COMPILES( "#include <sys/sysmacros.h>\nint main() { return major(256); }" MAJOR_IN_SYSMACROS) +IF(ENABLE_LZMA) CMAKE_PUSH_CHECK_STATE() SET(CMAKE_REQUIRED_LIBRARIES ${LIBLZMA_LIBRARIES}) SET(CMAKE_REQUIRED_INCLUDES ${LIBLZMA_INCLUDE_DIR}) CHECK_C_SOURCE_COMPILES( "#include <lzma.h>\n#if LZMA_VERSION < 50020000\n#error unsupported\n#endif\nint main(void){lzma_stream_encoder_mt(0, 0); return 0;}" -HAVE_LZMA_STREAM_ENCODER_MT) + HAVE_LZMA_STREAM_ENCODER_MT) CMAKE_POP_CHECK_STATE() +ELSE() + SET(HAVE_LZMA_STREAM_ENCODER_MT 0) +ENDIF(ENABLE_LZMA) IF(HAVE_STRERROR_R) SET(HAVE_DECL_STRERROR_R 1) @@ -2007,6 +2012,11 @@ IF(MSVC) ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE) ENDIF(MSVC) +IF(APPLE) + # CC_MD5_Init() functions are deprecated on macOS 10.15, but we want to use them + ADD_DEFINITIONS(-Wno-deprecated-declarations) +ENDIF(APPLE) + IF(0) # CMake does not build libarchive's tests. IF(ENABLE_TEST) ADD_CUSTOM_TARGET(run_all_tests) diff --git a/Utilities/cmlibarchive/COPYING b/Utilities/cmlibarchive/COPYING index 14bbefa..1b97235 100644 --- a/Utilities/cmlibarchive/COPYING +++ b/Utilities/cmlibarchive/COPYING @@ -15,7 +15,6 @@ the actual statements in the files are controlling. * The following source files are also subject in whole or in part to a 3-clause UC Regents copyright; please read the individual source files for details: - libarchive/archive_entry.c libarchive/archive_read_support_filter_compress.c libarchive/archive_write_add_filter_compress.c libarchive/mtree.5 diff --git a/Utilities/cmlibarchive/build/cmake/CreatePkgConfigFile.cmake b/Utilities/cmlibarchive/build/cmake/CreatePkgConfigFile.cmake index fc8529a..bc5a43f 100644 --- a/Utilities/cmlibarchive/build/cmake/CreatePkgConfigFile.cmake +++ b/Utilities/cmlibarchive/build/cmake/CreatePkgConfigFile.cmake @@ -24,10 +24,10 @@ ENDFOREACH() # thus there's a good chance it'll make some binutils versions unhappy... # This only affects Libs.private (looked up for static builds) though. CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/build/pkgconfig/libarchive.pc.in - ${CMAKE_CURRENT_SOURCE_DIR}/build/pkgconfig/libarchive.pc + ${CMAKE_CURRENT_BINARY_DIR}/build/pkgconfig/libarchive.pc @ONLY) # And install it, of course ;). IF(ENABLE_INSTALL) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/build/pkgconfig/libarchive.pc + INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/build/pkgconfig/libarchive.pc DESTINATION "lib/pkgconfig") ENDIF() diff --git a/Utilities/cmlibarchive/build/cmake/config.h.in b/Utilities/cmlibarchive/build/cmake/config.h.in index f38601f..9bd2667 100644 --- a/Utilities/cmlibarchive/build/cmake/config.h.in +++ b/Utilities/cmlibarchive/build/cmake/config.h.in @@ -1,4 +1,5 @@ /* config.h. Generated from build/cmake/config.h.in by cmake configure */ +#define __LIBARCHIVE_CONFIG_H_INCLUDED 1 #if defined(__osf__) # define _OSF_SOURCE #endif @@ -742,6 +743,9 @@ /* Define to 1 if you have the `strchr' function. */ #cmakedefine HAVE_STRCHR 1 +/* Define to 1 if you have the `strnlen' function. */ +#cmakedefine HAVE_STRNLEN 1 + /* Define to 1 if you have the `strdup' function. */ #cmakedefine HAVE_STRDUP 1 diff --git a/Utilities/cmlibarchive/build/version b/Utilities/cmlibarchive/build/version index 78be3ab..205791c 100644 --- a/Utilities/cmlibarchive/build/version +++ b/Utilities/cmlibarchive/build/version @@ -1 +1 @@ -3004002 +3005001 diff --git a/Utilities/cmlibarchive/libarchive/archive.h b/Utilities/cmlibarchive/libarchive/archive.h index 574e087..a1f0b87 100644 --- a/Utilities/cmlibarchive/libarchive/archive.h +++ b/Utilities/cmlibarchive/libarchive/archive.h @@ -36,7 +36,7 @@ * assert that ARCHIVE_VERSION_NUMBER >= 2012108. */ /* Note: Compiler will complain if this does not match archive_entry.h! */ -#define ARCHIVE_VERSION_NUMBER 3004002 +#define ARCHIVE_VERSION_NUMBER 3005001 #include <sys/stat.h> #include <stddef.h> /* for wchar_t */ @@ -152,7 +152,7 @@ __LA_DECL int archive_version_number(void); /* * Textual name/version of the library, useful for version displays. */ -#define ARCHIVE_VERSION_ONLY_STRING "3.4.2" +#define ARCHIVE_VERSION_ONLY_STRING "3.5.1" #define ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING __LA_DECL const char * archive_version_string(void); @@ -243,6 +243,8 @@ typedef int archive_open_callback(struct archive *, void *_client_data); typedef int archive_close_callback(struct archive *, void *_client_data); +typedef int archive_free_callback(struct archive *, void *_client_data); + /* Switches from one client data object to the next/prev client data object. * This is useful for reading from different data blocks such as a set of files * that make up one large file. @@ -415,6 +417,7 @@ __LA_DECL int archive_read_support_compression_xz(struct archive *) #endif __LA_DECL int archive_read_support_filter_all(struct archive *); +__LA_DECL int archive_read_support_filter_by_code(struct archive *, int); __LA_DECL int archive_read_support_filter_bzip2(struct archive *); __LA_DECL int archive_read_support_filter_compress(struct archive *); __LA_DECL int archive_read_support_filter_gzip(struct archive *); @@ -814,9 +817,13 @@ __LA_DECL int archive_write_set_format_filter_by_ext(struct archive *a, const ch __LA_DECL int archive_write_set_format_filter_by_ext_def(struct archive *a, const char *filename, const char * def_ext); __LA_DECL int archive_write_zip_set_compression_deflate(struct archive *); __LA_DECL int archive_write_zip_set_compression_store(struct archive *); +/* Deprecated; use archive_write_open2 instead */ __LA_DECL int archive_write_open(struct archive *, void *, archive_open_callback *, archive_write_callback *, archive_close_callback *); +__LA_DECL int archive_write_open2(struct archive *, void *, + archive_open_callback *, archive_write_callback *, + archive_close_callback *, archive_free_callback *); __LA_DECL int archive_write_open_fd(struct archive *, int _fd); __LA_DECL int archive_write_open_filename(struct archive *, const char *_file); __LA_DECL int archive_write_open_filename_w(struct archive *, diff --git a/Utilities/cmlibarchive/libarchive/archive_acl.c b/Utilities/cmlibarchive/libarchive/archive_acl.c index 952e20d..ead7e36 100644 --- a/Utilities/cmlibarchive/libarchive/archive_acl.c +++ b/Utilities/cmlibarchive/libarchive/archive_acl.c @@ -595,7 +595,7 @@ archive_acl_text_len(struct archive_acl *acl, int want_type, int flags, else length += sizeof(uid_t) * 3 + 1; } else { - r = archive_mstring_get_mbs_l(&ap->name, &name, + r = archive_mstring_get_mbs_l(a, &ap->name, &name, &len, sc); if (r != 0) return (0); @@ -968,7 +968,7 @@ archive_acl_to_text_l(struct archive_acl *acl, ssize_t *text_len, int flags, else prefix = NULL; r = archive_mstring_get_mbs_l( - &ap->name, &name, &len, sc); + NULL, &ap->name, &name, &len, sc); if (r != 0) { free(s); return (NULL); @@ -1402,14 +1402,14 @@ isint_w(const wchar_t *start, const wchar_t *end, int *result) if (start >= end) return (0); while (start < end) { - if (*start < '0' || *start > '9') + if (*start < L'0' || *start > L'9') return (0); if (n > (INT_MAX / 10) || - (n == INT_MAX / 10 && (*start - '0') > INT_MAX % 10)) { + (n == INT_MAX / 10 && (*start - L'0') > INT_MAX % 10)) { n = INT_MAX; } else { n *= 10; - n += *start - '0'; + n += *start - L'0'; } start++; } diff --git a/Utilities/cmlibarchive/libarchive/archive_check_magic.c b/Utilities/cmlibarchive/libarchive/archive_check_magic.c index 288ce23..1f40072 100644 --- a/Utilities/cmlibarchive/libarchive/archive_check_magic.c +++ b/Utilities/cmlibarchive/libarchive/archive_check_magic.c @@ -54,7 +54,7 @@ errmsg(const char *m) ssize_t written; while (s > 0) { - written = write(2, m, strlen(m)); + written = write(2, m, s); if (written <= 0) return; m += written; diff --git a/Utilities/cmlibarchive/libarchive/archive_cryptor.c b/Utilities/cmlibarchive/libarchive/archive_cryptor.c index 8ab2b09..d4bca90 100644 --- a/Utilities/cmlibarchive/libarchive/archive_cryptor.c +++ b/Utilities/cmlibarchive/libarchive/archive_cryptor.c @@ -347,8 +347,31 @@ aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len) static int aes_ctr_encrypt_counter(archive_crypto_ctx *ctx) { +#if NETTLE_VERSION_MAJOR < 3 aes_set_encrypt_key(&ctx->ctx, ctx->key_len, ctx->key); aes_encrypt(&ctx->ctx, AES_BLOCK_SIZE, ctx->encr_buf, ctx->nonce); +#else + switch(ctx->key_len) { + case AES128_KEY_SIZE: + aes128_set_encrypt_key(&ctx->ctx.c128, ctx->key); + aes128_encrypt(&ctx->ctx.c128, AES_BLOCK_SIZE, ctx->encr_buf, + ctx->nonce); + break; + case AES192_KEY_SIZE: + aes192_set_encrypt_key(&ctx->ctx.c192, ctx->key); + aes192_encrypt(&ctx->ctx.c192, AES_BLOCK_SIZE, ctx->encr_buf, + ctx->nonce); + break; + case AES256_KEY_SIZE: + aes256_set_encrypt_key(&ctx->ctx.c256, ctx->key); + aes256_encrypt(&ctx->ctx.c256, AES_BLOCK_SIZE, ctx->encr_buf, + ctx->nonce); + break; + default: + return -1; + break; + } +#endif return 0; } diff --git a/Utilities/cmlibarchive/libarchive/archive_cryptor_private.h b/Utilities/cmlibarchive/libarchive/archive_cryptor_private.h index 64a2055..16b6d16 100644 --- a/Utilities/cmlibarchive/libarchive/archive_cryptor_private.h +++ b/Utilities/cmlibarchive/libarchive/archive_cryptor_private.h @@ -104,9 +104,18 @@ typedef struct { #include <nettle/pbkdf2.h> #endif #include <nettle/aes.h> +#include <nettle/version.h> typedef struct { +#if NETTLE_VERSION_MAJOR < 3 struct aes_ctx ctx; +#else + union { + struct aes128_ctx c128; + struct aes192_ctx c192; + struct aes256_ctx c256; + } ctx; +#endif uint8_t key[AES_MAX_KEY_SIZE]; unsigned key_len; uint8_t nonce[AES_BLOCK_SIZE]; diff --git a/Utilities/cmlibarchive/libarchive/archive_digest.c b/Utilities/cmlibarchive/libarchive/archive_digest.c index 34c58ac..410df01 100644 --- a/Utilities/cmlibarchive/libarchive/archive_digest.c +++ b/Utilities/cmlibarchive/libarchive/archive_digest.c @@ -109,14 +109,14 @@ win_crypto_Final(unsigned char *buf, size_t bufsize, Digest_CTX *ctx) #if defined(ARCHIVE_CRYPTO_MD5_LIBC) static int -__archive_libc_md5init(archive_md5_ctx *ctx) +__archive_md5init(archive_md5_ctx *ctx) { MD5Init(ctx); return (ARCHIVE_OK); } static int -__archive_libc_md5update(archive_md5_ctx *ctx, const void *indata, +__archive_md5update(archive_md5_ctx *ctx, const void *indata, size_t insize) { MD5Update(ctx, indata, insize); @@ -124,7 +124,7 @@ __archive_libc_md5update(archive_md5_ctx *ctx, const void *indata, } static int -__archive_libc_md5final(archive_md5_ctx *ctx, void *md) +__archive_md5final(archive_md5_ctx *ctx, void *md) { MD5Final(md, ctx); return (ARCHIVE_OK); @@ -133,14 +133,14 @@ __archive_libc_md5final(archive_md5_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_MD5_LIBMD) static int -__archive_libmd_md5init(archive_md5_ctx *ctx) +__archive_md5init(archive_md5_ctx *ctx) { MD5Init(ctx); return (ARCHIVE_OK); } static int -__archive_libmd_md5update(archive_md5_ctx *ctx, const void *indata, +__archive_md5update(archive_md5_ctx *ctx, const void *indata, size_t insize) { MD5Update(ctx, indata, insize); @@ -148,7 +148,7 @@ __archive_libmd_md5update(archive_md5_ctx *ctx, const void *indata, } static int -__archive_libmd_md5final(archive_md5_ctx *ctx, void *md) +__archive_md5final(archive_md5_ctx *ctx, void *md) { MD5Final(md, ctx); return (ARCHIVE_OK); @@ -157,14 +157,14 @@ __archive_libmd_md5final(archive_md5_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_MD5_LIBSYSTEM) static int -__archive_libsystem_md5init(archive_md5_ctx *ctx) +__archive_md5init(archive_md5_ctx *ctx) { CC_MD5_Init(ctx); return (ARCHIVE_OK); } static int -__archive_libsystem_md5update(archive_md5_ctx *ctx, const void *indata, +__archive_md5update(archive_md5_ctx *ctx, const void *indata, size_t insize) { CC_MD5_Update(ctx, indata, insize); @@ -172,7 +172,7 @@ __archive_libsystem_md5update(archive_md5_ctx *ctx, const void *indata, } static int -__archive_libsystem_md5final(archive_md5_ctx *ctx, void *md) +__archive_md5final(archive_md5_ctx *ctx, void *md) { CC_MD5_Final(md, ctx); return (ARCHIVE_OK); @@ -181,7 +181,7 @@ __archive_libsystem_md5final(archive_md5_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_MD5_MBEDTLS) static int -__archive_mbedtls_md5init(archive_md5_ctx *ctx) +__archive_md5init(archive_md5_ctx *ctx) { mbedtls_md5_init(ctx); if (mbedtls_md5_starts_ret(ctx) == 0) @@ -191,7 +191,7 @@ __archive_mbedtls_md5init(archive_md5_ctx *ctx) } static int -__archive_mbedtls_md5update(archive_md5_ctx *ctx, const void *indata, +__archive_md5update(archive_md5_ctx *ctx, const void *indata, size_t insize) { if (mbedtls_md5_update_ret(ctx, indata, insize) == 0) @@ -201,7 +201,7 @@ __archive_mbedtls_md5update(archive_md5_ctx *ctx, const void *indata, } static int -__archive_mbedtls_md5final(archive_md5_ctx *ctx, void *md) +__archive_md5final(archive_md5_ctx *ctx, void *md) { if (mbedtls_md5_finish_ret(ctx, md) == 0) { mbedtls_md5_free(ctx); @@ -215,14 +215,14 @@ __archive_mbedtls_md5final(archive_md5_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_MD5_NETTLE) static int -__archive_nettle_md5init(archive_md5_ctx *ctx) +__archive_md5init(archive_md5_ctx *ctx) { md5_init(ctx); return (ARCHIVE_OK); } static int -__archive_nettle_md5update(archive_md5_ctx *ctx, const void *indata, +__archive_md5update(archive_md5_ctx *ctx, const void *indata, size_t insize) { md5_update(ctx, insize, indata); @@ -230,7 +230,7 @@ __archive_nettle_md5update(archive_md5_ctx *ctx, const void *indata, } static int -__archive_nettle_md5final(archive_md5_ctx *ctx, void *md) +__archive_md5final(archive_md5_ctx *ctx, void *md) { md5_digest(ctx, MD5_DIGEST_SIZE, md); return (ARCHIVE_OK); @@ -239,7 +239,7 @@ __archive_nettle_md5final(archive_md5_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_MD5_OPENSSL) static int -__archive_openssl_md5init(archive_md5_ctx *ctx) +__archive_md5init(archive_md5_ctx *ctx) { if ((*ctx = EVP_MD_CTX_new()) == NULL) return (ARCHIVE_FAILED); @@ -248,7 +248,7 @@ __archive_openssl_md5init(archive_md5_ctx *ctx) } static int -__archive_openssl_md5update(archive_md5_ctx *ctx, const void *indata, +__archive_md5update(archive_md5_ctx *ctx, const void *indata, size_t insize) { EVP_DigestUpdate(*ctx, indata, insize); @@ -256,7 +256,7 @@ __archive_openssl_md5update(archive_md5_ctx *ctx, const void *indata, } static int -__archive_openssl_md5final(archive_md5_ctx *ctx, void *md) +__archive_md5final(archive_md5_ctx *ctx, void *md) { /* HACK: archive_write_set_format_xar.c is finalizing empty contexts, so * this is meant to cope with that. Real fix is probably to fix @@ -273,20 +273,20 @@ __archive_openssl_md5final(archive_md5_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_MD5_WIN) static int -__archive_windowsapi_md5init(archive_md5_ctx *ctx) +__archive_md5init(archive_md5_ctx *ctx) { return (win_crypto_init(ctx, CALG_MD5)); } static int -__archive_windowsapi_md5update(archive_md5_ctx *ctx, const void *indata, +__archive_md5update(archive_md5_ctx *ctx, const void *indata, size_t insize) { return (win_crypto_Update(ctx, indata, insize)); } static int -__archive_windowsapi_md5final(archive_md5_ctx *ctx, void *md) +__archive_md5final(archive_md5_ctx *ctx, void *md) { return (win_crypto_Final(md, 16, ctx)); } @@ -294,14 +294,14 @@ __archive_windowsapi_md5final(archive_md5_ctx *ctx, void *md) #else static int -__archive_stub_md5init(archive_md5_ctx *ctx) +__archive_md5init(archive_md5_ctx *ctx) { (void)ctx; /* UNUSED */ return (ARCHIVE_FAILED); } static int -__archive_stub_md5update(archive_md5_ctx *ctx, const void *indata, +__archive_md5update(archive_md5_ctx *ctx, const void *indata, size_t insize) { (void)ctx; /* UNUSED */ @@ -311,7 +311,7 @@ __archive_stub_md5update(archive_md5_ctx *ctx, const void *indata, } static int -__archive_stub_md5final(archive_md5_ctx *ctx, void *md) +__archive_md5final(archive_md5_ctx *ctx, void *md) { (void)ctx; /* UNUSED */ (void)md; /* UNUSED */ @@ -324,14 +324,14 @@ __archive_stub_md5final(archive_md5_ctx *ctx, void *md) #if defined(ARCHIVE_CRYPTO_RMD160_LIBC) static int -__archive_libc_ripemd160init(archive_rmd160_ctx *ctx) +__archive_ripemd160init(archive_rmd160_ctx *ctx) { RMD160Init(ctx); return (ARCHIVE_OK); } static int -__archive_libc_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, +__archive_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, size_t insize) { RMD160Update(ctx, indata, insize); @@ -339,7 +339,7 @@ __archive_libc_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, } static int -__archive_libc_ripemd160final(archive_rmd160_ctx *ctx, void *md) +__archive_ripemd160final(archive_rmd160_ctx *ctx, void *md) { RMD160Final(md, ctx); return (ARCHIVE_OK); @@ -348,14 +348,14 @@ __archive_libc_ripemd160final(archive_rmd160_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_RMD160_LIBMD) static int -__archive_libmd_ripemd160init(archive_rmd160_ctx *ctx) +__archive_ripemd160init(archive_rmd160_ctx *ctx) { RIPEMD160_Init(ctx); return (ARCHIVE_OK); } static int -__archive_libmd_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, +__archive_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, size_t insize) { RIPEMD160_Update(ctx, indata, insize); @@ -363,7 +363,7 @@ __archive_libmd_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, } static int -__archive_libmd_ripemd160final(archive_rmd160_ctx *ctx, void *md) +__archive_ripemd160final(archive_rmd160_ctx *ctx, void *md) { RIPEMD160_Final(md, ctx); return (ARCHIVE_OK); @@ -372,7 +372,7 @@ __archive_libmd_ripemd160final(archive_rmd160_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_RMD160_MBEDTLS) static int -__archive_mbedtls_ripemd160init(archive_rmd160_ctx *ctx) +__archive_ripemd160init(archive_rmd160_ctx *ctx) { mbedtls_ripemd160_init(ctx); if (mbedtls_ripemd160_starts_ret(ctx) == 0) @@ -382,7 +382,7 @@ __archive_mbedtls_ripemd160init(archive_rmd160_ctx *ctx) } static int -__archive_mbedtls_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, +__archive_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, size_t insize) { if (mbedtls_ripemd160_update_ret(ctx, indata, insize) == 0) @@ -392,7 +392,7 @@ __archive_mbedtls_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, } static int -__archive_mbedtls_ripemd160final(archive_rmd160_ctx *ctx, void *md) +__archive_ripemd160final(archive_rmd160_ctx *ctx, void *md) { if (mbedtls_ripemd160_finish_ret(ctx, md) == 0) { mbedtls_ripemd160_free(ctx); @@ -406,14 +406,14 @@ __archive_mbedtls_ripemd160final(archive_rmd160_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_RMD160_NETTLE) static int -__archive_nettle_ripemd160init(archive_rmd160_ctx *ctx) +__archive_ripemd160init(archive_rmd160_ctx *ctx) { ripemd160_init(ctx); return (ARCHIVE_OK); } static int -__archive_nettle_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, +__archive_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, size_t insize) { ripemd160_update(ctx, insize, indata); @@ -421,7 +421,7 @@ __archive_nettle_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, } static int -__archive_nettle_ripemd160final(archive_rmd160_ctx *ctx, void *md) +__archive_ripemd160final(archive_rmd160_ctx *ctx, void *md) { ripemd160_digest(ctx, RIPEMD160_DIGEST_SIZE, md); return (ARCHIVE_OK); @@ -430,7 +430,7 @@ __archive_nettle_ripemd160final(archive_rmd160_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_RMD160_OPENSSL) static int -__archive_openssl_ripemd160init(archive_rmd160_ctx *ctx) +__archive_ripemd160init(archive_rmd160_ctx *ctx) { if ((*ctx = EVP_MD_CTX_new()) == NULL) return (ARCHIVE_FAILED); @@ -439,7 +439,7 @@ __archive_openssl_ripemd160init(archive_rmd160_ctx *ctx) } static int -__archive_openssl_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, +__archive_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, size_t insize) { EVP_DigestUpdate(*ctx, indata, insize); @@ -447,7 +447,7 @@ __archive_openssl_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, } static int -__archive_openssl_ripemd160final(archive_rmd160_ctx *ctx, void *md) +__archive_ripemd160final(archive_rmd160_ctx *ctx, void *md) { if (*ctx) { EVP_DigestFinal(*ctx, md, NULL); @@ -460,14 +460,14 @@ __archive_openssl_ripemd160final(archive_rmd160_ctx *ctx, void *md) #else static int -__archive_stub_ripemd160init(archive_rmd160_ctx *ctx) +__archive_ripemd160init(archive_rmd160_ctx *ctx) { (void)ctx; /* UNUSED */ return (ARCHIVE_FAILED); } static int -__archive_stub_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, +__archive_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, size_t insize) { (void)ctx; /* UNUSED */ @@ -477,7 +477,7 @@ __archive_stub_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, } static int -__archive_stub_ripemd160final(archive_rmd160_ctx *ctx, void *md) +__archive_ripemd160final(archive_rmd160_ctx *ctx, void *md) { (void)ctx; /* UNUSED */ (void)md; /* UNUSED */ @@ -490,14 +490,14 @@ __archive_stub_ripemd160final(archive_rmd160_ctx *ctx, void *md) #if defined(ARCHIVE_CRYPTO_SHA1_LIBC) static int -__archive_libc_sha1init(archive_sha1_ctx *ctx) +__archive_sha1init(archive_sha1_ctx *ctx) { SHA1Init(ctx); return (ARCHIVE_OK); } static int -__archive_libc_sha1update(archive_sha1_ctx *ctx, const void *indata, +__archive_sha1update(archive_sha1_ctx *ctx, const void *indata, size_t insize) { SHA1Update(ctx, indata, insize); @@ -505,7 +505,7 @@ __archive_libc_sha1update(archive_sha1_ctx *ctx, const void *indata, } static int -__archive_libc_sha1final(archive_sha1_ctx *ctx, void *md) +__archive_sha1final(archive_sha1_ctx *ctx, void *md) { SHA1Final(md, ctx); return (ARCHIVE_OK); @@ -514,14 +514,14 @@ __archive_libc_sha1final(archive_sha1_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA1_LIBMD) static int -__archive_libmd_sha1init(archive_sha1_ctx *ctx) +__archive_sha1init(archive_sha1_ctx *ctx) { SHA1_Init(ctx); return (ARCHIVE_OK); } static int -__archive_libmd_sha1update(archive_sha1_ctx *ctx, const void *indata, +__archive_sha1update(archive_sha1_ctx *ctx, const void *indata, size_t insize) { SHA1_Update(ctx, indata, insize); @@ -529,7 +529,7 @@ __archive_libmd_sha1update(archive_sha1_ctx *ctx, const void *indata, } static int -__archive_libmd_sha1final(archive_sha1_ctx *ctx, void *md) +__archive_sha1final(archive_sha1_ctx *ctx, void *md) { SHA1_Final(md, ctx); return (ARCHIVE_OK); @@ -538,14 +538,14 @@ __archive_libmd_sha1final(archive_sha1_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA1_LIBSYSTEM) static int -__archive_libsystem_sha1init(archive_sha1_ctx *ctx) +__archive_sha1init(archive_sha1_ctx *ctx) { CC_SHA1_Init(ctx); return (ARCHIVE_OK); } static int -__archive_libsystem_sha1update(archive_sha1_ctx *ctx, const void *indata, +__archive_sha1update(archive_sha1_ctx *ctx, const void *indata, size_t insize) { CC_SHA1_Update(ctx, indata, insize); @@ -553,7 +553,7 @@ __archive_libsystem_sha1update(archive_sha1_ctx *ctx, const void *indata, } static int -__archive_libsystem_sha1final(archive_sha1_ctx *ctx, void *md) +__archive_sha1final(archive_sha1_ctx *ctx, void *md) { CC_SHA1_Final(md, ctx); return (ARCHIVE_OK); @@ -562,7 +562,7 @@ __archive_libsystem_sha1final(archive_sha1_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA1_MBEDTLS) static int -__archive_mbedtls_sha1init(archive_sha1_ctx *ctx) +__archive_sha1init(archive_sha1_ctx *ctx) { mbedtls_sha1_init(ctx); if (mbedtls_sha1_starts_ret(ctx) == 0) @@ -572,7 +572,7 @@ __archive_mbedtls_sha1init(archive_sha1_ctx *ctx) } static int -__archive_mbedtls_sha1update(archive_sha1_ctx *ctx, const void *indata, +__archive_sha1update(archive_sha1_ctx *ctx, const void *indata, size_t insize) { if (mbedtls_sha1_update_ret(ctx, indata, insize) == 0) @@ -582,7 +582,7 @@ __archive_mbedtls_sha1update(archive_sha1_ctx *ctx, const void *indata, } static int -__archive_mbedtls_sha1final(archive_sha1_ctx *ctx, void *md) +__archive_sha1final(archive_sha1_ctx *ctx, void *md) { if (mbedtls_sha1_finish_ret(ctx, md) == 0) { mbedtls_sha1_free(ctx); @@ -596,14 +596,14 @@ __archive_mbedtls_sha1final(archive_sha1_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA1_NETTLE) static int -__archive_nettle_sha1init(archive_sha1_ctx *ctx) +__archive_sha1init(archive_sha1_ctx *ctx) { sha1_init(ctx); return (ARCHIVE_OK); } static int -__archive_nettle_sha1update(archive_sha1_ctx *ctx, const void *indata, +__archive_sha1update(archive_sha1_ctx *ctx, const void *indata, size_t insize) { sha1_update(ctx, insize, indata); @@ -611,7 +611,7 @@ __archive_nettle_sha1update(archive_sha1_ctx *ctx, const void *indata, } static int -__archive_nettle_sha1final(archive_sha1_ctx *ctx, void *md) +__archive_sha1final(archive_sha1_ctx *ctx, void *md) { sha1_digest(ctx, SHA1_DIGEST_SIZE, md); return (ARCHIVE_OK); @@ -620,7 +620,7 @@ __archive_nettle_sha1final(archive_sha1_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA1_OPENSSL) static int -__archive_openssl_sha1init(archive_sha1_ctx *ctx) +__archive_sha1init(archive_sha1_ctx *ctx) { if ((*ctx = EVP_MD_CTX_new()) == NULL) return (ARCHIVE_FAILED); @@ -629,7 +629,7 @@ __archive_openssl_sha1init(archive_sha1_ctx *ctx) } static int -__archive_openssl_sha1update(archive_sha1_ctx *ctx, const void *indata, +__archive_sha1update(archive_sha1_ctx *ctx, const void *indata, size_t insize) { EVP_DigestUpdate(*ctx, indata, insize); @@ -637,7 +637,7 @@ __archive_openssl_sha1update(archive_sha1_ctx *ctx, const void *indata, } static int -__archive_openssl_sha1final(archive_sha1_ctx *ctx, void *md) +__archive_sha1final(archive_sha1_ctx *ctx, void *md) { /* HACK: archive_write_set_format_xar.c is finalizing empty contexts, so * this is meant to cope with that. Real fix is probably to fix @@ -654,20 +654,20 @@ __archive_openssl_sha1final(archive_sha1_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA1_WIN) static int -__archive_windowsapi_sha1init(archive_sha1_ctx *ctx) +__archive_sha1init(archive_sha1_ctx *ctx) { return (win_crypto_init(ctx, CALG_SHA1)); } static int -__archive_windowsapi_sha1update(archive_sha1_ctx *ctx, const void *indata, +__archive_sha1update(archive_sha1_ctx *ctx, const void *indata, size_t insize) { return (win_crypto_Update(ctx, indata, insize)); } static int -__archive_windowsapi_sha1final(archive_sha1_ctx *ctx, void *md) +__archive_sha1final(archive_sha1_ctx *ctx, void *md) { return (win_crypto_Final(md, 20, ctx)); } @@ -675,14 +675,14 @@ __archive_windowsapi_sha1final(archive_sha1_ctx *ctx, void *md) #else static int -__archive_stub_sha1init(archive_sha1_ctx *ctx) +__archive_sha1init(archive_sha1_ctx *ctx) { (void)ctx; /* UNUSED */ return (ARCHIVE_FAILED); } static int -__archive_stub_sha1update(archive_sha1_ctx *ctx, const void *indata, +__archive_sha1update(archive_sha1_ctx *ctx, const void *indata, size_t insize) { (void)ctx; /* UNUSED */ @@ -692,7 +692,7 @@ __archive_stub_sha1update(archive_sha1_ctx *ctx, const void *indata, } static int -__archive_stub_sha1final(archive_sha1_ctx *ctx, void *md) +__archive_sha1final(archive_sha1_ctx *ctx, void *md) { (void)ctx; /* UNUSED */ (void)md; /* UNUSED */ @@ -705,14 +705,14 @@ __archive_stub_sha1final(archive_sha1_ctx *ctx, void *md) #if defined(ARCHIVE_CRYPTO_SHA256_LIBC) static int -__archive_libc_sha256init(archive_sha256_ctx *ctx) +__archive_sha256init(archive_sha256_ctx *ctx) { SHA256_Init(ctx); return (ARCHIVE_OK); } static int -__archive_libc_sha256update(archive_sha256_ctx *ctx, const void *indata, +__archive_sha256update(archive_sha256_ctx *ctx, const void *indata, size_t insize) { SHA256_Update(ctx, indata, insize); @@ -720,7 +720,7 @@ __archive_libc_sha256update(archive_sha256_ctx *ctx, const void *indata, } static int -__archive_libc_sha256final(archive_sha256_ctx *ctx, void *md) +__archive_sha256final(archive_sha256_ctx *ctx, void *md) { SHA256_Final(md, ctx); return (ARCHIVE_OK); @@ -729,14 +729,14 @@ __archive_libc_sha256final(archive_sha256_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA256_LIBC2) static int -__archive_libc2_sha256init(archive_sha256_ctx *ctx) +__archive_sha256init(archive_sha256_ctx *ctx) { SHA256Init(ctx); return (ARCHIVE_OK); } static int -__archive_libc2_sha256update(archive_sha256_ctx *ctx, const void *indata, +__archive_sha256update(archive_sha256_ctx *ctx, const void *indata, size_t insize) { SHA256Update(ctx, indata, insize); @@ -744,7 +744,7 @@ __archive_libc2_sha256update(archive_sha256_ctx *ctx, const void *indata, } static int -__archive_libc2_sha256final(archive_sha256_ctx *ctx, void *md) +__archive_sha256final(archive_sha256_ctx *ctx, void *md) { SHA256Final(md, ctx); return (ARCHIVE_OK); @@ -753,14 +753,14 @@ __archive_libc2_sha256final(archive_sha256_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA256_LIBC3) static int -__archive_libc3_sha256init(archive_sha256_ctx *ctx) +__archive_sha256init(archive_sha256_ctx *ctx) { SHA256Init(ctx); return (ARCHIVE_OK); } static int -__archive_libc3_sha256update(archive_sha256_ctx *ctx, const void *indata, +__archive_sha256update(archive_sha256_ctx *ctx, const void *indata, size_t insize) { SHA256Update(ctx, indata, insize); @@ -768,7 +768,7 @@ __archive_libc3_sha256update(archive_sha256_ctx *ctx, const void *indata, } static int -__archive_libc3_sha256final(archive_sha256_ctx *ctx, void *md) +__archive_sha256final(archive_sha256_ctx *ctx, void *md) { SHA256Final(md, ctx); return (ARCHIVE_OK); @@ -777,14 +777,14 @@ __archive_libc3_sha256final(archive_sha256_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA256_LIBMD) static int -__archive_libmd_sha256init(archive_sha256_ctx *ctx) +__archive_sha256init(archive_sha256_ctx *ctx) { SHA256_Init(ctx); return (ARCHIVE_OK); } static int -__archive_libmd_sha256update(archive_sha256_ctx *ctx, const void *indata, +__archive_sha256update(archive_sha256_ctx *ctx, const void *indata, size_t insize) { SHA256_Update(ctx, indata, insize); @@ -792,7 +792,7 @@ __archive_libmd_sha256update(archive_sha256_ctx *ctx, const void *indata, } static int -__archive_libmd_sha256final(archive_sha256_ctx *ctx, void *md) +__archive_sha256final(archive_sha256_ctx *ctx, void *md) { SHA256_Final(md, ctx); return (ARCHIVE_OK); @@ -801,14 +801,14 @@ __archive_libmd_sha256final(archive_sha256_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA256_LIBSYSTEM) static int -__archive_libsystem_sha256init(archive_sha256_ctx *ctx) +__archive_sha256init(archive_sha256_ctx *ctx) { CC_SHA256_Init(ctx); return (ARCHIVE_OK); } static int -__archive_libsystem_sha256update(archive_sha256_ctx *ctx, const void *indata, +__archive_sha256update(archive_sha256_ctx *ctx, const void *indata, size_t insize) { CC_SHA256_Update(ctx, indata, insize); @@ -816,7 +816,7 @@ __archive_libsystem_sha256update(archive_sha256_ctx *ctx, const void *indata, } static int -__archive_libsystem_sha256final(archive_sha256_ctx *ctx, void *md) +__archive_sha256final(archive_sha256_ctx *ctx, void *md) { CC_SHA256_Final(md, ctx); return (ARCHIVE_OK); @@ -825,7 +825,7 @@ __archive_libsystem_sha256final(archive_sha256_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA256_MBEDTLS) static int -__archive_mbedtls_sha256init(archive_sha256_ctx *ctx) +__archive_sha256init(archive_sha256_ctx *ctx) { mbedtls_sha256_init(ctx); if (mbedtls_sha256_starts_ret(ctx, 0) == 0) @@ -835,7 +835,7 @@ __archive_mbedtls_sha256init(archive_sha256_ctx *ctx) } static int -__archive_mbedtls_sha256update(archive_sha256_ctx *ctx, const void *indata, +__archive_sha256update(archive_sha256_ctx *ctx, const void *indata, size_t insize) { if (mbedtls_sha256_update_ret(ctx, indata, insize) == 0) @@ -845,7 +845,7 @@ __archive_mbedtls_sha256update(archive_sha256_ctx *ctx, const void *indata, } static int -__archive_mbedtls_sha256final(archive_sha256_ctx *ctx, void *md) +__archive_sha256final(archive_sha256_ctx *ctx, void *md) { if (mbedtls_sha256_finish_ret(ctx, md) == 0) { mbedtls_sha256_free(ctx); @@ -859,14 +859,14 @@ __archive_mbedtls_sha256final(archive_sha256_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA256_NETTLE) static int -__archive_nettle_sha256init(archive_sha256_ctx *ctx) +__archive_sha256init(archive_sha256_ctx *ctx) { sha256_init(ctx); return (ARCHIVE_OK); } static int -__archive_nettle_sha256update(archive_sha256_ctx *ctx, const void *indata, +__archive_sha256update(archive_sha256_ctx *ctx, const void *indata, size_t insize) { sha256_update(ctx, insize, indata); @@ -874,7 +874,7 @@ __archive_nettle_sha256update(archive_sha256_ctx *ctx, const void *indata, } static int -__archive_nettle_sha256final(archive_sha256_ctx *ctx, void *md) +__archive_sha256final(archive_sha256_ctx *ctx, void *md) { sha256_digest(ctx, SHA256_DIGEST_SIZE, md); return (ARCHIVE_OK); @@ -883,7 +883,7 @@ __archive_nettle_sha256final(archive_sha256_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA256_OPENSSL) static int -__archive_openssl_sha256init(archive_sha256_ctx *ctx) +__archive_sha256init(archive_sha256_ctx *ctx) { if ((*ctx = EVP_MD_CTX_new()) == NULL) return (ARCHIVE_FAILED); @@ -892,7 +892,7 @@ __archive_openssl_sha256init(archive_sha256_ctx *ctx) } static int -__archive_openssl_sha256update(archive_sha256_ctx *ctx, const void *indata, +__archive_sha256update(archive_sha256_ctx *ctx, const void *indata, size_t insize) { EVP_DigestUpdate(*ctx, indata, insize); @@ -900,7 +900,7 @@ __archive_openssl_sha256update(archive_sha256_ctx *ctx, const void *indata, } static int -__archive_openssl_sha256final(archive_sha256_ctx *ctx, void *md) +__archive_sha256final(archive_sha256_ctx *ctx, void *md) { if (*ctx) { EVP_DigestFinal(*ctx, md, NULL); @@ -913,20 +913,20 @@ __archive_openssl_sha256final(archive_sha256_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA256_WIN) static int -__archive_windowsapi_sha256init(archive_sha256_ctx *ctx) +__archive_sha256init(archive_sha256_ctx *ctx) { return (win_crypto_init(ctx, CALG_SHA_256)); } static int -__archive_windowsapi_sha256update(archive_sha256_ctx *ctx, const void *indata, +__archive_sha256update(archive_sha256_ctx *ctx, const void *indata, size_t insize) { return (win_crypto_Update(ctx, indata, insize)); } static int -__archive_windowsapi_sha256final(archive_sha256_ctx *ctx, void *md) +__archive_sha256final(archive_sha256_ctx *ctx, void *md) { return (win_crypto_Final(md, 32, ctx)); } @@ -934,14 +934,14 @@ __archive_windowsapi_sha256final(archive_sha256_ctx *ctx, void *md) #else static int -__archive_stub_sha256init(archive_sha256_ctx *ctx) +__archive_sha256init(archive_sha256_ctx *ctx) { (void)ctx; /* UNUSED */ return (ARCHIVE_FAILED); } static int -__archive_stub_sha256update(archive_sha256_ctx *ctx, const void *indata, +__archive_sha256update(archive_sha256_ctx *ctx, const void *indata, size_t insize) { (void)ctx; /* UNUSED */ @@ -951,7 +951,7 @@ __archive_stub_sha256update(archive_sha256_ctx *ctx, const void *indata, } static int -__archive_stub_sha256final(archive_sha256_ctx *ctx, void *md) +__archive_sha256final(archive_sha256_ctx *ctx, void *md) { (void)ctx; /* UNUSED */ (void)md; /* UNUSED */ @@ -964,14 +964,14 @@ __archive_stub_sha256final(archive_sha256_ctx *ctx, void *md) #if defined(ARCHIVE_CRYPTO_SHA384_LIBC) static int -__archive_libc_sha384init(archive_sha384_ctx *ctx) +__archive_sha384init(archive_sha384_ctx *ctx) { SHA384_Init(ctx); return (ARCHIVE_OK); } static int -__archive_libc_sha384update(archive_sha384_ctx *ctx, const void *indata, +__archive_sha384update(archive_sha384_ctx *ctx, const void *indata, size_t insize) { SHA384_Update(ctx, indata, insize); @@ -979,7 +979,7 @@ __archive_libc_sha384update(archive_sha384_ctx *ctx, const void *indata, } static int -__archive_libc_sha384final(archive_sha384_ctx *ctx, void *md) +__archive_sha384final(archive_sha384_ctx *ctx, void *md) { SHA384_Final(md, ctx); return (ARCHIVE_OK); @@ -988,14 +988,14 @@ __archive_libc_sha384final(archive_sha384_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA384_LIBC2) static int -__archive_libc2_sha384init(archive_sha384_ctx *ctx) +__archive_sha384init(archive_sha384_ctx *ctx) { SHA384Init(ctx); return (ARCHIVE_OK); } static int -__archive_libc2_sha384update(archive_sha384_ctx *ctx, const void *indata, +__archive_sha384update(archive_sha384_ctx *ctx, const void *indata, size_t insize) { SHA384Update(ctx, indata, insize); @@ -1003,7 +1003,7 @@ __archive_libc2_sha384update(archive_sha384_ctx *ctx, const void *indata, } static int -__archive_libc2_sha384final(archive_sha384_ctx *ctx, void *md) +__archive_sha384final(archive_sha384_ctx *ctx, void *md) { SHA384Final(md, ctx); return (ARCHIVE_OK); @@ -1012,14 +1012,14 @@ __archive_libc2_sha384final(archive_sha384_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA384_LIBC3) static int -__archive_libc3_sha384init(archive_sha384_ctx *ctx) +__archive_sha384init(archive_sha384_ctx *ctx) { SHA384Init(ctx); return (ARCHIVE_OK); } static int -__archive_libc3_sha384update(archive_sha384_ctx *ctx, const void *indata, +__archive_sha384update(archive_sha384_ctx *ctx, const void *indata, size_t insize) { SHA384Update(ctx, indata, insize); @@ -1027,7 +1027,7 @@ __archive_libc3_sha384update(archive_sha384_ctx *ctx, const void *indata, } static int -__archive_libc3_sha384final(archive_sha384_ctx *ctx, void *md) +__archive_sha384final(archive_sha384_ctx *ctx, void *md) { SHA384Final(md, ctx); return (ARCHIVE_OK); @@ -1036,14 +1036,14 @@ __archive_libc3_sha384final(archive_sha384_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA384_LIBSYSTEM) static int -__archive_libsystem_sha384init(archive_sha384_ctx *ctx) +__archive_sha384init(archive_sha384_ctx *ctx) { CC_SHA384_Init(ctx); return (ARCHIVE_OK); } static int -__archive_libsystem_sha384update(archive_sha384_ctx *ctx, const void *indata, +__archive_sha384update(archive_sha384_ctx *ctx, const void *indata, size_t insize) { CC_SHA384_Update(ctx, indata, insize); @@ -1051,7 +1051,7 @@ __archive_libsystem_sha384update(archive_sha384_ctx *ctx, const void *indata, } static int -__archive_libsystem_sha384final(archive_sha384_ctx *ctx, void *md) +__archive_sha384final(archive_sha384_ctx *ctx, void *md) { CC_SHA384_Final(md, ctx); return (ARCHIVE_OK); @@ -1060,7 +1060,7 @@ __archive_libsystem_sha384final(archive_sha384_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA384_MBEDTLS) static int -__archive_mbedtls_sha384init(archive_sha384_ctx *ctx) +__archive_sha384init(archive_sha384_ctx *ctx) { mbedtls_sha512_init(ctx); if (mbedtls_sha512_starts_ret(ctx, 1) == 0) @@ -1070,7 +1070,7 @@ __archive_mbedtls_sha384init(archive_sha384_ctx *ctx) } static int -__archive_mbedtls_sha384update(archive_sha384_ctx *ctx, const void *indata, +__archive_sha384update(archive_sha384_ctx *ctx, const void *indata, size_t insize) { if (mbedtls_sha512_update_ret(ctx, indata, insize) == 0) @@ -1080,7 +1080,7 @@ __archive_mbedtls_sha384update(archive_sha384_ctx *ctx, const void *indata, } static int -__archive_mbedtls_sha384final(archive_sha384_ctx *ctx, void *md) +__archive_sha384final(archive_sha384_ctx *ctx, void *md) { if (mbedtls_sha512_finish_ret(ctx, md) == 0) { mbedtls_sha512_free(ctx); @@ -1094,14 +1094,14 @@ __archive_mbedtls_sha384final(archive_sha384_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA384_NETTLE) static int -__archive_nettle_sha384init(archive_sha384_ctx *ctx) +__archive_sha384init(archive_sha384_ctx *ctx) { sha384_init(ctx); return (ARCHIVE_OK); } static int -__archive_nettle_sha384update(archive_sha384_ctx *ctx, const void *indata, +__archive_sha384update(archive_sha384_ctx *ctx, const void *indata, size_t insize) { sha384_update(ctx, insize, indata); @@ -1109,7 +1109,7 @@ __archive_nettle_sha384update(archive_sha384_ctx *ctx, const void *indata, } static int -__archive_nettle_sha384final(archive_sha384_ctx *ctx, void *md) +__archive_sha384final(archive_sha384_ctx *ctx, void *md) { sha384_digest(ctx, SHA384_DIGEST_SIZE, md); return (ARCHIVE_OK); @@ -1118,7 +1118,7 @@ __archive_nettle_sha384final(archive_sha384_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA384_OPENSSL) static int -__archive_openssl_sha384init(archive_sha384_ctx *ctx) +__archive_sha384init(archive_sha384_ctx *ctx) { if ((*ctx = EVP_MD_CTX_new()) == NULL) return (ARCHIVE_FAILED); @@ -1127,7 +1127,7 @@ __archive_openssl_sha384init(archive_sha384_ctx *ctx) } static int -__archive_openssl_sha384update(archive_sha384_ctx *ctx, const void *indata, +__archive_sha384update(archive_sha384_ctx *ctx, const void *indata, size_t insize) { EVP_DigestUpdate(*ctx, indata, insize); @@ -1135,7 +1135,7 @@ __archive_openssl_sha384update(archive_sha384_ctx *ctx, const void *indata, } static int -__archive_openssl_sha384final(archive_sha384_ctx *ctx, void *md) +__archive_sha384final(archive_sha384_ctx *ctx, void *md) { if (*ctx) { EVP_DigestFinal(*ctx, md, NULL); @@ -1148,20 +1148,20 @@ __archive_openssl_sha384final(archive_sha384_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA384_WIN) static int -__archive_windowsapi_sha384init(archive_sha384_ctx *ctx) +__archive_sha384init(archive_sha384_ctx *ctx) { return (win_crypto_init(ctx, CALG_SHA_384)); } static int -__archive_windowsapi_sha384update(archive_sha384_ctx *ctx, const void *indata, +__archive_sha384update(archive_sha384_ctx *ctx, const void *indata, size_t insize) { return (win_crypto_Update(ctx, indata, insize)); } static int -__archive_windowsapi_sha384final(archive_sha384_ctx *ctx, void *md) +__archive_sha384final(archive_sha384_ctx *ctx, void *md) { return (win_crypto_Final(md, 48, ctx)); } @@ -1169,14 +1169,14 @@ __archive_windowsapi_sha384final(archive_sha384_ctx *ctx, void *md) #else static int -__archive_stub_sha384init(archive_sha384_ctx *ctx) +__archive_sha384init(archive_sha384_ctx *ctx) { (void)ctx; /* UNUSED */ return (ARCHIVE_FAILED); } static int -__archive_stub_sha384update(archive_sha384_ctx *ctx, const void *indata, +__archive_sha384update(archive_sha384_ctx *ctx, const void *indata, size_t insize) { (void)ctx; /* UNUSED */ @@ -1186,7 +1186,7 @@ __archive_stub_sha384update(archive_sha384_ctx *ctx, const void *indata, } static int -__archive_stub_sha384final(archive_sha384_ctx *ctx, void *md) +__archive_sha384final(archive_sha384_ctx *ctx, void *md) { (void)ctx; /* UNUSED */ (void)md; /* UNUSED */ @@ -1199,14 +1199,14 @@ __archive_stub_sha384final(archive_sha384_ctx *ctx, void *md) #if defined(ARCHIVE_CRYPTO_SHA512_LIBC) static int -__archive_libc_sha512init(archive_sha512_ctx *ctx) +__archive_sha512init(archive_sha512_ctx *ctx) { SHA512_Init(ctx); return (ARCHIVE_OK); } static int -__archive_libc_sha512update(archive_sha512_ctx *ctx, const void *indata, +__archive_sha512update(archive_sha512_ctx *ctx, const void *indata, size_t insize) { SHA512_Update(ctx, indata, insize); @@ -1214,7 +1214,7 @@ __archive_libc_sha512update(archive_sha512_ctx *ctx, const void *indata, } static int -__archive_libc_sha512final(archive_sha512_ctx *ctx, void *md) +__archive_sha512final(archive_sha512_ctx *ctx, void *md) { SHA512_Final(md, ctx); return (ARCHIVE_OK); @@ -1223,14 +1223,14 @@ __archive_libc_sha512final(archive_sha512_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA512_LIBC2) static int -__archive_libc2_sha512init(archive_sha512_ctx *ctx) +__archive_sha512init(archive_sha512_ctx *ctx) { SHA512Init(ctx); return (ARCHIVE_OK); } static int -__archive_libc2_sha512update(archive_sha512_ctx *ctx, const void *indata, +__archive_sha512update(archive_sha512_ctx *ctx, const void *indata, size_t insize) { SHA512Update(ctx, indata, insize); @@ -1238,7 +1238,7 @@ __archive_libc2_sha512update(archive_sha512_ctx *ctx, const void *indata, } static int -__archive_libc2_sha512final(archive_sha512_ctx *ctx, void *md) +__archive_sha512final(archive_sha512_ctx *ctx, void *md) { SHA512Final(md, ctx); return (ARCHIVE_OK); @@ -1247,14 +1247,14 @@ __archive_libc2_sha512final(archive_sha512_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA512_LIBC3) static int -__archive_libc3_sha512init(archive_sha512_ctx *ctx) +__archive_sha512init(archive_sha512_ctx *ctx) { SHA512Init(ctx); return (ARCHIVE_OK); } static int -__archive_libc3_sha512update(archive_sha512_ctx *ctx, const void *indata, +__archive_sha512update(archive_sha512_ctx *ctx, const void *indata, size_t insize) { SHA512Update(ctx, indata, insize); @@ -1262,7 +1262,7 @@ __archive_libc3_sha512update(archive_sha512_ctx *ctx, const void *indata, } static int -__archive_libc3_sha512final(archive_sha512_ctx *ctx, void *md) +__archive_sha512final(archive_sha512_ctx *ctx, void *md) { SHA512Final(md, ctx); return (ARCHIVE_OK); @@ -1271,14 +1271,14 @@ __archive_libc3_sha512final(archive_sha512_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA512_LIBMD) static int -__archive_libmd_sha512init(archive_sha512_ctx *ctx) +__archive_sha512init(archive_sha512_ctx *ctx) { SHA512_Init(ctx); return (ARCHIVE_OK); } static int -__archive_libmd_sha512update(archive_sha512_ctx *ctx, const void *indata, +__archive_sha512update(archive_sha512_ctx *ctx, const void *indata, size_t insize) { SHA512_Update(ctx, indata, insize); @@ -1286,7 +1286,7 @@ __archive_libmd_sha512update(archive_sha512_ctx *ctx, const void *indata, } static int -__archive_libmd_sha512final(archive_sha512_ctx *ctx, void *md) +__archive_sha512final(archive_sha512_ctx *ctx, void *md) { SHA512_Final(md, ctx); return (ARCHIVE_OK); @@ -1295,14 +1295,14 @@ __archive_libmd_sha512final(archive_sha512_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA512_LIBSYSTEM) static int -__archive_libsystem_sha512init(archive_sha512_ctx *ctx) +__archive_sha512init(archive_sha512_ctx *ctx) { CC_SHA512_Init(ctx); return (ARCHIVE_OK); } static int -__archive_libsystem_sha512update(archive_sha512_ctx *ctx, const void *indata, +__archive_sha512update(archive_sha512_ctx *ctx, const void *indata, size_t insize) { CC_SHA512_Update(ctx, indata, insize); @@ -1310,7 +1310,7 @@ __archive_libsystem_sha512update(archive_sha512_ctx *ctx, const void *indata, } static int -__archive_libsystem_sha512final(archive_sha512_ctx *ctx, void *md) +__archive_sha512final(archive_sha512_ctx *ctx, void *md) { CC_SHA512_Final(md, ctx); return (ARCHIVE_OK); @@ -1319,7 +1319,7 @@ __archive_libsystem_sha512final(archive_sha512_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA512_MBEDTLS) static int -__archive_mbedtls_sha512init(archive_sha512_ctx *ctx) +__archive_sha512init(archive_sha512_ctx *ctx) { mbedtls_sha512_init(ctx); if (mbedtls_sha512_starts_ret(ctx, 0) == 0) @@ -1329,7 +1329,7 @@ __archive_mbedtls_sha512init(archive_sha512_ctx *ctx) } static int -__archive_mbedtls_sha512update(archive_sha512_ctx *ctx, const void *indata, +__archive_sha512update(archive_sha512_ctx *ctx, const void *indata, size_t insize) { if (mbedtls_sha512_update_ret(ctx, indata, insize) == 0) @@ -1339,7 +1339,7 @@ __archive_mbedtls_sha512update(archive_sha512_ctx *ctx, const void *indata, } static int -__archive_mbedtls_sha512final(archive_sha512_ctx *ctx, void *md) +__archive_sha512final(archive_sha512_ctx *ctx, void *md) { if (mbedtls_sha512_finish_ret(ctx, md) == 0) { mbedtls_sha512_free(ctx); @@ -1353,14 +1353,14 @@ __archive_mbedtls_sha512final(archive_sha512_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA512_NETTLE) static int -__archive_nettle_sha512init(archive_sha512_ctx *ctx) +__archive_sha512init(archive_sha512_ctx *ctx) { sha512_init(ctx); return (ARCHIVE_OK); } static int -__archive_nettle_sha512update(archive_sha512_ctx *ctx, const void *indata, +__archive_sha512update(archive_sha512_ctx *ctx, const void *indata, size_t insize) { sha512_update(ctx, insize, indata); @@ -1368,7 +1368,7 @@ __archive_nettle_sha512update(archive_sha512_ctx *ctx, const void *indata, } static int -__archive_nettle_sha512final(archive_sha512_ctx *ctx, void *md) +__archive_sha512final(archive_sha512_ctx *ctx, void *md) { sha512_digest(ctx, SHA512_DIGEST_SIZE, md); return (ARCHIVE_OK); @@ -1377,7 +1377,7 @@ __archive_nettle_sha512final(archive_sha512_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA512_OPENSSL) static int -__archive_openssl_sha512init(archive_sha512_ctx *ctx) +__archive_sha512init(archive_sha512_ctx *ctx) { if ((*ctx = EVP_MD_CTX_new()) == NULL) return (ARCHIVE_FAILED); @@ -1386,7 +1386,7 @@ __archive_openssl_sha512init(archive_sha512_ctx *ctx) } static int -__archive_openssl_sha512update(archive_sha512_ctx *ctx, const void *indata, +__archive_sha512update(archive_sha512_ctx *ctx, const void *indata, size_t insize) { EVP_DigestUpdate(*ctx, indata, insize); @@ -1394,7 +1394,7 @@ __archive_openssl_sha512update(archive_sha512_ctx *ctx, const void *indata, } static int -__archive_openssl_sha512final(archive_sha512_ctx *ctx, void *md) +__archive_sha512final(archive_sha512_ctx *ctx, void *md) { if (*ctx) { EVP_DigestFinal(*ctx, md, NULL); @@ -1407,20 +1407,20 @@ __archive_openssl_sha512final(archive_sha512_ctx *ctx, void *md) #elif defined(ARCHIVE_CRYPTO_SHA512_WIN) static int -__archive_windowsapi_sha512init(archive_sha512_ctx *ctx) +__archive_sha512init(archive_sha512_ctx *ctx) { return (win_crypto_init(ctx, CALG_SHA_512)); } static int -__archive_windowsapi_sha512update(archive_sha512_ctx *ctx, const void *indata, +__archive_sha512update(archive_sha512_ctx *ctx, const void *indata, size_t insize) { return (win_crypto_Update(ctx, indata, insize)); } static int -__archive_windowsapi_sha512final(archive_sha512_ctx *ctx, void *md) +__archive_sha512final(archive_sha512_ctx *ctx, void *md) { return (win_crypto_Final(md, 64, ctx)); } @@ -1428,14 +1428,14 @@ __archive_windowsapi_sha512final(archive_sha512_ctx *ctx, void *md) #else static int -__archive_stub_sha512init(archive_sha512_ctx *ctx) +__archive_sha512init(archive_sha512_ctx *ctx) { (void)ctx; /* UNUSED */ return (ARCHIVE_FAILED); } static int -__archive_stub_sha512update(archive_sha512_ctx *ctx, const void *indata, +__archive_sha512update(archive_sha512_ctx *ctx, const void *indata, size_t insize) { (void)ctx; /* UNUSED */ @@ -1445,7 +1445,7 @@ __archive_stub_sha512update(archive_sha512_ctx *ctx, const void *indata, } static int -__archive_stub_sha512final(archive_sha512_ctx *ctx, void *md) +__archive_sha512final(archive_sha512_ctx *ctx, void *md) { (void)ctx; /* UNUSED */ (void)md; /* UNUSED */ @@ -1468,224 +1468,32 @@ __archive_stub_sha512final(archive_sha512_ctx *ctx, void *md) const struct archive_digest __archive_digest = { /* MD5 */ -#if defined(ARCHIVE_CRYPTO_MD5_LIBC) - &__archive_libc_md5init, - &__archive_libc_md5update, - &__archive_libc_md5final, -#elif defined(ARCHIVE_CRYPTO_MD5_LIBMD) - &__archive_libmd_md5init, - &__archive_libmd_md5update, - &__archive_libmd_md5final, -#elif defined(ARCHIVE_CRYPTO_MD5_LIBSYSTEM) - &__archive_libsystem_md5init, - &__archive_libsystem_md5update, - &__archive_libsystem_md5final, -#elif defined(ARCHIVE_CRYPTO_MD5_MBEDTLS) - &__archive_mbedtls_md5init, - &__archive_mbedtls_md5update, - &__archive_mbedtls_md5final, -#elif defined(ARCHIVE_CRYPTO_MD5_NETTLE) - &__archive_nettle_md5init, - &__archive_nettle_md5update, - &__archive_nettle_md5final, -#elif defined(ARCHIVE_CRYPTO_MD5_OPENSSL) - &__archive_openssl_md5init, - &__archive_openssl_md5update, - &__archive_openssl_md5final, -#elif defined(ARCHIVE_CRYPTO_MD5_WIN) - &__archive_windowsapi_md5init, - &__archive_windowsapi_md5update, - &__archive_windowsapi_md5final, -#elif !defined(ARCHIVE_MD5_COMPILE_TEST) - &__archive_stub_md5init, - &__archive_stub_md5update, - &__archive_stub_md5final, -#endif + &__archive_md5init, + &__archive_md5update, + &__archive_md5final, /* RIPEMD160 */ -#if defined(ARCHIVE_CRYPTO_RMD160_LIBC) - &__archive_libc_ripemd160init, - &__archive_libc_ripemd160update, - &__archive_libc_ripemd160final, -#elif defined(ARCHIVE_CRYPTO_RMD160_LIBMD) - &__archive_libmd_ripemd160init, - &__archive_libmd_ripemd160update, - &__archive_libmd_ripemd160final, -#elif defined(ARCHIVE_CRYPTO_RMD160_MBEDTLS) - &__archive_mbedtls_ripemd160init, - &__archive_mbedtls_ripemd160update, - &__archive_mbedtls_ripemd160final, -#elif defined(ARCHIVE_CRYPTO_RMD160_NETTLE) - &__archive_nettle_ripemd160init, - &__archive_nettle_ripemd160update, - &__archive_nettle_ripemd160final, -#elif defined(ARCHIVE_CRYPTO_RMD160_OPENSSL) - &__archive_openssl_ripemd160init, - &__archive_openssl_ripemd160update, - &__archive_openssl_ripemd160final, -#elif !defined(ARCHIVE_RMD160_COMPILE_TEST) - &__archive_stub_ripemd160init, - &__archive_stub_ripemd160update, - &__archive_stub_ripemd160final, -#endif + &__archive_ripemd160init, + &__archive_ripemd160update, + &__archive_ripemd160final, /* SHA1 */ -#if defined(ARCHIVE_CRYPTO_SHA1_LIBC) - &__archive_libc_sha1init, - &__archive_libc_sha1update, - &__archive_libc_sha1final, -#elif defined(ARCHIVE_CRYPTO_SHA1_LIBMD) - &__archive_libmd_sha1init, - &__archive_libmd_sha1update, - &__archive_libmd_sha1final, -#elif defined(ARCHIVE_CRYPTO_SHA1_LIBSYSTEM) - &__archive_libsystem_sha1init, - &__archive_libsystem_sha1update, - &__archive_libsystem_sha1final, -#elif defined(ARCHIVE_CRYPTO_SHA1_MBEDTLS) - &__archive_mbedtls_sha1init, - &__archive_mbedtls_sha1update, - &__archive_mbedtls_sha1final, -#elif defined(ARCHIVE_CRYPTO_SHA1_NETTLE) - &__archive_nettle_sha1init, - &__archive_nettle_sha1update, - &__archive_nettle_sha1final, -#elif defined(ARCHIVE_CRYPTO_SHA1_OPENSSL) - &__archive_openssl_sha1init, - &__archive_openssl_sha1update, - &__archive_openssl_sha1final, -#elif defined(ARCHIVE_CRYPTO_SHA1_WIN) - &__archive_windowsapi_sha1init, - &__archive_windowsapi_sha1update, - &__archive_windowsapi_sha1final, -#elif !defined(ARCHIVE_SHA1_COMPILE_TEST) - &__archive_stub_sha1init, - &__archive_stub_sha1update, - &__archive_stub_sha1final, -#endif + &__archive_sha1init, + &__archive_sha1update, + &__archive_sha1final, /* SHA256 */ -#if defined(ARCHIVE_CRYPTO_SHA256_LIBC) - &__archive_libc_sha256init, - &__archive_libc_sha256update, - &__archive_libc_sha256final, -#elif defined(ARCHIVE_CRYPTO_SHA256_LIBC2) - &__archive_libc2_sha256init, - &__archive_libc2_sha256update, - &__archive_libc2_sha256final, -#elif defined(ARCHIVE_CRYPTO_SHA256_LIBC3) - &__archive_libc3_sha256init, - &__archive_libc3_sha256update, - &__archive_libc3_sha256final, -#elif defined(ARCHIVE_CRYPTO_SHA256_LIBMD) - &__archive_libmd_sha256init, - &__archive_libmd_sha256update, - &__archive_libmd_sha256final, -#elif defined(ARCHIVE_CRYPTO_SHA256_LIBSYSTEM) - &__archive_libsystem_sha256init, - &__archive_libsystem_sha256update, - &__archive_libsystem_sha256final, -#elif defined(ARCHIVE_CRYPTO_SHA256_MBEDTLS) - &__archive_mbedtls_sha256init, - &__archive_mbedtls_sha256update, - &__archive_mbedtls_sha256final, -#elif defined(ARCHIVE_CRYPTO_SHA256_NETTLE) - &__archive_nettle_sha256init, - &__archive_nettle_sha256update, - &__archive_nettle_sha256final, -#elif defined(ARCHIVE_CRYPTO_SHA256_OPENSSL) - &__archive_openssl_sha256init, - &__archive_openssl_sha256update, - &__archive_openssl_sha256final, -#elif defined(ARCHIVE_CRYPTO_SHA256_WIN) - &__archive_windowsapi_sha256init, - &__archive_windowsapi_sha256update, - &__archive_windowsapi_sha256final, -#elif !defined(ARCHIVE_SHA256_COMPILE_TEST) - &__archive_stub_sha256init, - &__archive_stub_sha256update, - &__archive_stub_sha256final, -#endif + &__archive_sha256init, + &__archive_sha256update, + &__archive_sha256final, /* SHA384 */ -#if defined(ARCHIVE_CRYPTO_SHA384_LIBC) - &__archive_libc_sha384init, - &__archive_libc_sha384update, - &__archive_libc_sha384final, -#elif defined(ARCHIVE_CRYPTO_SHA384_LIBC2) - &__archive_libc2_sha384init, - &__archive_libc2_sha384update, - &__archive_libc2_sha384final, -#elif defined(ARCHIVE_CRYPTO_SHA384_LIBC3) - &__archive_libc3_sha384init, - &__archive_libc3_sha384update, - &__archive_libc3_sha384final, -#elif defined(ARCHIVE_CRYPTO_SHA384_LIBSYSTEM) - &__archive_libsystem_sha384init, - &__archive_libsystem_sha384update, - &__archive_libsystem_sha384final, -#elif defined(ARCHIVE_CRYPTO_SHA384_MBEDTLS) - &__archive_mbedtls_sha384init, - &__archive_mbedtls_sha384update, - &__archive_mbedtls_sha384final, -#elif defined(ARCHIVE_CRYPTO_SHA384_NETTLE) - &__archive_nettle_sha384init, - &__archive_nettle_sha384update, - &__archive_nettle_sha384final, -#elif defined(ARCHIVE_CRYPTO_SHA384_OPENSSL) - &__archive_openssl_sha384init, - &__archive_openssl_sha384update, - &__archive_openssl_sha384final, -#elif defined(ARCHIVE_CRYPTO_SHA384_WIN) - &__archive_windowsapi_sha384init, - &__archive_windowsapi_sha384update, - &__archive_windowsapi_sha384final, -#elif !defined(ARCHIVE_SHA384_COMPILE_TEST) - &__archive_stub_sha384init, - &__archive_stub_sha384update, - &__archive_stub_sha384final, -#endif + &__archive_sha384init, + &__archive_sha384update, + &__archive_sha384final, /* SHA512 */ -#if defined(ARCHIVE_CRYPTO_SHA512_LIBC) - &__archive_libc_sha512init, - &__archive_libc_sha512update, - &__archive_libc_sha512final -#elif defined(ARCHIVE_CRYPTO_SHA512_LIBC2) - &__archive_libc2_sha512init, - &__archive_libc2_sha512update, - &__archive_libc2_sha512final -#elif defined(ARCHIVE_CRYPTO_SHA512_LIBC3) - &__archive_libc3_sha512init, - &__archive_libc3_sha512update, - &__archive_libc3_sha512final -#elif defined(ARCHIVE_CRYPTO_SHA512_LIBMD) - &__archive_libmd_sha512init, - &__archive_libmd_sha512update, - &__archive_libmd_sha512final -#elif defined(ARCHIVE_CRYPTO_SHA512_LIBSYSTEM) - &__archive_libsystem_sha512init, - &__archive_libsystem_sha512update, - &__archive_libsystem_sha512final -#elif defined(ARCHIVE_CRYPTO_SHA512_MBEDTLS) - &__archive_mbedtls_sha512init, - &__archive_mbedtls_sha512update, - &__archive_mbedtls_sha512final -#elif defined(ARCHIVE_CRYPTO_SHA512_NETTLE) - &__archive_nettle_sha512init, - &__archive_nettle_sha512update, - &__archive_nettle_sha512final -#elif defined(ARCHIVE_CRYPTO_SHA512_OPENSSL) - &__archive_openssl_sha512init, - &__archive_openssl_sha512update, - &__archive_openssl_sha512final -#elif defined(ARCHIVE_CRYPTO_SHA512_WIN) - &__archive_windowsapi_sha512init, - &__archive_windowsapi_sha512update, - &__archive_windowsapi_sha512final -#elif !defined(ARCHIVE_SHA512_COMPILE_TEST) - &__archive_stub_sha512init, - &__archive_stub_sha512update, - &__archive_stub_sha512final -#endif + &__archive_sha512init, + &__archive_sha512update, + &__archive_sha512final }; diff --git a/Utilities/cmlibarchive/libarchive/archive_digest_private.h b/Utilities/cmlibarchive/libarchive/archive_digest_private.h index 15312ee..9b3bd66 100644 --- a/Utilities/cmlibarchive/libarchive/archive_digest_private.h +++ b/Utilities/cmlibarchive/libarchive/archive_digest_private.h @@ -30,6 +30,10 @@ #ifndef __LIBARCHIVE_BUILD #error This header is only to be used internally to libarchive. #endif +#ifndef __LIBARCHIVE_CONFIG_H_INCLUDED +#error "Should have include config.h first!" +#endif + /* * Crypto support in various Operating Systems: * diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.c b/Utilities/cmlibarchive/libarchive/archive_entry.c index a15e98c..ca7a4bd 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry.c +++ b/Utilities/cmlibarchive/libarchive/archive_entry.c @@ -208,6 +208,19 @@ archive_entry_clone(struct archive_entry *entry) /* Copy encryption status */ entry2->encryption = entry->encryption; + + /* Copy digests */ +#define copy_digest(_e2, _e, _t) \ + memcpy(_e2->digest._t, _e->digest._t, sizeof(_e2->digest._t)) + + copy_digest(entry2, entry, md5); + copy_digest(entry2, entry, rmd160); + copy_digest(entry2, entry, sha1); + copy_digest(entry2, entry, sha256); + copy_digest(entry2, entry, sha384); + copy_digest(entry2, entry, sha512); + +#undef copy_digest /* Copy ACL data over. */ archive_acl_copy(&entry2->acl, &entry->acl); @@ -353,7 +366,7 @@ archive_entry_devminor(struct archive_entry *entry) return minor(entry->ae_stat.aest_dev); } -mode_t +__LA_MODE_T archive_entry_filetype(struct archive_entry *entry) { return (AE_IFMT & entry->acl.mode); @@ -450,7 +463,7 @@ int _archive_entry_gname_l(struct archive_entry *entry, const char **p, size_t *len, struct archive_string_conv *sc) { - return (archive_mstring_get_mbs_l(&entry->ae_gname, p, len, sc)); + return (archive_mstring_get_mbs_l(entry->archive, &entry->ae_gname, p, len, sc)); } const char * @@ -504,7 +517,7 @@ _archive_entry_hardlink_l(struct archive_entry *entry, *len = 0; return (0); } - return (archive_mstring_get_mbs_l(&entry->ae_hardlink, p, len, sc)); + return (archive_mstring_get_mbs_l(entry->archive, &entry->ae_hardlink, p, len, sc)); } la_int64_t @@ -525,7 +538,7 @@ archive_entry_ino64(struct archive_entry *entry) return (entry->ae_stat.aest_ino); } -mode_t +__LA_MODE_T archive_entry_mode(struct archive_entry *entry) { return (entry->acl.mode); @@ -595,10 +608,10 @@ int _archive_entry_pathname_l(struct archive_entry *entry, const char **p, size_t *len, struct archive_string_conv *sc) { - return (archive_mstring_get_mbs_l(&entry->ae_pathname, p, len, sc)); + return (archive_mstring_get_mbs_l(entry->archive, &entry->ae_pathname, p, len, sc)); } -mode_t +__LA_MODE_T archive_entry_perm(struct archive_entry *entry) { return (~AE_IFMT & entry->acl.mode); @@ -723,7 +736,7 @@ _archive_entry_symlink_l(struct archive_entry *entry, *len = 0; return (0); } - return (archive_mstring_get_mbs_l( &entry->ae_symlink, p, len, sc)); + return (archive_mstring_get_mbs_l(entry->archive, &entry->ae_symlink, p, len, sc)); } la_int64_t @@ -769,7 +782,7 @@ int _archive_entry_uname_l(struct archive_entry *entry, const char **p, size_t *len, struct archive_string_conv *sc) { - return (archive_mstring_get_mbs_l(&entry->ae_uname, p, len, sc)); + return (archive_mstring_get_mbs_l(entry->archive, &entry->ae_uname, p, len, sc)); } int @@ -1416,6 +1429,62 @@ archive_entry_copy_mac_metadata(struct archive_entry *entry, } } +/* Digest handling */ +const unsigned char * +archive_entry_digest(struct archive_entry *entry, int type) +{ + switch (type) { + case ARCHIVE_ENTRY_DIGEST_MD5: + return entry->digest.md5; + case ARCHIVE_ENTRY_DIGEST_RMD160: + return entry->digest.rmd160; + case ARCHIVE_ENTRY_DIGEST_SHA1: + return entry->digest.sha1; + case ARCHIVE_ENTRY_DIGEST_SHA256: + return entry->digest.sha256; + case ARCHIVE_ENTRY_DIGEST_SHA384: + return entry->digest.sha384; + case ARCHIVE_ENTRY_DIGEST_SHA512: + return entry->digest.sha512; + default: + return NULL; + } +} + +int +archive_entry_set_digest(struct archive_entry *entry, int type, + const unsigned char *digest) +{ +#define copy_digest(_e, _t, _d)\ + memcpy(_e->digest._t, _d, sizeof(_e->digest._t)) + + switch (type) { + case ARCHIVE_ENTRY_DIGEST_MD5: + copy_digest(entry, md5, digest); + break; + case ARCHIVE_ENTRY_DIGEST_RMD160: + copy_digest(entry, rmd160, digest); + break; + case ARCHIVE_ENTRY_DIGEST_SHA1: + copy_digest(entry, sha1, digest); + break; + case ARCHIVE_ENTRY_DIGEST_SHA256: + copy_digest(entry, sha256, digest); + break; + case ARCHIVE_ENTRY_DIGEST_SHA384: + copy_digest(entry, sha384, digest); + break; + case ARCHIVE_ENTRY_DIGEST_SHA512: + copy_digest(entry, sha512, digest); + break; + default: + return ARCHIVE_WARN; + } + + return ARCHIVE_OK; +#undef copy_digest +} + /* * ACL management. The following would, of course, be a lot simpler * if: 1) the last draft of POSIX.1e were a really thorough and diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.h b/Utilities/cmlibarchive/libarchive/archive_entry.h index 0053faa..21e89d2 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry.h +++ b/Utilities/cmlibarchive/libarchive/archive_entry.h @@ -30,7 +30,7 @@ #define ARCHIVE_ENTRY_H_INCLUDED /* Note: Compiler will complain if this does not match archive.h! */ -#define ARCHIVE_VERSION_NUMBER 3004002 +#define ARCHIVE_VERSION_NUMBER 3005001 /* * Note: archive_entry.h is for use outside of libarchive; the @@ -394,6 +394,19 @@ __LA_DECL const void * archive_entry_mac_metadata(struct archive_entry *, size_t __LA_DECL void archive_entry_copy_mac_metadata(struct archive_entry *, const void *, size_t); /* + * Digest routine. This is used to query the raw hex digest for the + * given entry. The type of digest is provided as an argument. + */ +#define ARCHIVE_ENTRY_DIGEST_MD5 0x00000001 +#define ARCHIVE_ENTRY_DIGEST_RMD160 0x00000002 +#define ARCHIVE_ENTRY_DIGEST_SHA1 0x00000003 +#define ARCHIVE_ENTRY_DIGEST_SHA256 0x00000004 +#define ARCHIVE_ENTRY_DIGEST_SHA384 0x00000005 +#define ARCHIVE_ENTRY_DIGEST_SHA512 0x00000006 + +__LA_DECL const unsigned char * archive_entry_digest(struct archive_entry *, int /* type */); + +/* * ACL routines. This used to simply store and return text-format ACL * strings, but that proved insufficient for a number of reasons: * = clients need control over uname/uid and gname/gid mappings diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_private.h b/Utilities/cmlibarchive/libarchive/archive_entry_private.h index 2b9a084..cf4deb2 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry_private.h +++ b/Utilities/cmlibarchive/libarchive/archive_entry_private.h @@ -50,6 +50,15 @@ struct ae_sparse { int64_t length; }; +struct ae_digest { + unsigned char md5[16]; + unsigned char rmd160[20]; + unsigned char sha1[20]; + unsigned char sha256[32]; + unsigned char sha384[48]; + unsigned char sha512[64]; +}; + /* * Description of an archive entry. * @@ -162,6 +171,9 @@ struct archive_entry { void *mac_metadata; size_t mac_metadata_size; + /* Digest support. */ + struct ae_digest digest; + /* ACL support. */ struct archive_acl acl; @@ -181,4 +193,8 @@ struct archive_entry { int ae_symlink_type; }; +int +archive_entry_set_digest(struct archive_entry *entry, int type, + const unsigned char *digest); + #endif /* ARCHIVE_ENTRY_PRIVATE_H_INCLUDED */ diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_stat.3 b/Utilities/cmlibarchive/libarchive/archive_entry_stat.3 index aa5c8e0..29a53f7 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry_stat.3 +++ b/Utilities/cmlibarchive/libarchive/archive_entry_stat.3 @@ -215,9 +215,9 @@ and set and unset the size, respectively. .Pp The number of references (hardlinks) can be obtained by calling -.Fn archive_entry_nlinks +.Fn archive_entry_nlink and set with -.Fn archive_entry_set_nlinks . +.Fn archive_entry_set_nlink . .Ss Identifying unique files The functions .Fn archive_entry_dev diff --git a/Utilities/cmlibarchive/libarchive/archive_ppmd7.c b/Utilities/cmlibarchive/libarchive/archive_ppmd7.c index 4029395..cc3f778 100644 --- a/Utilities/cmlibarchive/libarchive/archive_ppmd7.c +++ b/Utilities/cmlibarchive/libarchive/archive_ppmd7.c @@ -4,7 +4,7 @@ This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ #include "archive_platform.h" -#include <memory.h> +#include <stdlib.h> #include "archive_ppmd7_private.h" diff --git a/Utilities/cmlibarchive/libarchive/archive_read.c b/Utilities/cmlibarchive/libarchive/archive_read.c index 4a933b2..c59f051 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read.c +++ b/Utilities/cmlibarchive/libarchive/archive_read.c @@ -892,15 +892,16 @@ archive_read_data(struct archive *_a, void *buff, size_t s) len = a->read_data_remaining; if (len > s) len = s; - if (len) + if (len) { memcpy(dest, a->read_data_block, len); - s -= len; - a->read_data_block += len; - a->read_data_remaining -= len; - a->read_data_output_offset += len; - a->read_data_offset += len; - dest += len; - bytes_read += len; + s -= len; + a->read_data_block += len; + a->read_data_remaining -= len; + a->read_data_output_offset += len; + a->read_data_offset += len; + dest += len; + bytes_read += len; + } } } a->read_data_is_posix_read = 0; diff --git a/Utilities/cmlibarchive/libarchive/archive_read_add_passphrase.c b/Utilities/cmlibarchive/libarchive/archive_read_add_passphrase.c index cf821b5..f0b1ab9 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_add_passphrase.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_add_passphrase.c @@ -57,6 +57,10 @@ insert_passphrase_to_head(struct archive_read *a, { p->next = a->passphrases.first; a->passphrases.first = p; + if (&a->passphrases.first == a->passphrases.last) { + a->passphrases.last = &p->next; + p->next = NULL; + } } static struct archive_read_passphrase * diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c index 2a8cec8..9c9cf38 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c @@ -103,6 +103,10 @@ __FBSDID("$FreeBSD"); static int setup_mac_metadata(struct archive_read_disk *, struct archive_entry *, int *fd); +#ifdef ARCHIVE_XATTR_FREEBSD +static int setup_xattrs_namespace(struct archive_read_disk *, + struct archive_entry *, int *, int); +#endif static int setup_xattrs(struct archive_read_disk *, struct archive_entry *, int *fd); static int setup_sparse(struct archive_read_disk *, @@ -701,14 +705,13 @@ setup_xattr(struct archive_read_disk *a, struct archive_entry *entry, } static int -setup_xattrs(struct archive_read_disk *a, - struct archive_entry *entry, int *fd) +setup_xattrs_namespace(struct archive_read_disk *a, + struct archive_entry *entry, int *fd, int namespace) { char buff[512]; char *list, *p; ssize_t list_size; const char *path; - int namespace = EXTATTR_NAMESPACE_USER; path = NULL; @@ -727,6 +730,8 @@ setup_xattrs(struct archive_read_disk *a, if (list_size == -1 && errno == EOPNOTSUPP) return (ARCHIVE_OK); + if (list_size == -1 && errno == EPERM) + return (ARCHIVE_OK); if (list_size == -1) { archive_set_error(&a->archive, errno, "Couldn't list extended attributes"); @@ -760,7 +765,17 @@ setup_xattrs(struct archive_read_disk *a, size_t len = 255 & (int)*p; char *name; - strcpy(buff, "user."); + if (namespace == EXTATTR_NAMESPACE_SYSTEM) { + if (!strcmp(p + 1, "nfs4.acl") || + !strcmp(p + 1, "posix1e.acl_access") || + !strcmp(p + 1, "posix1e.acl_default")) { + p += 1 + len; + continue; + } + strcpy(buff, "system."); + } else { + strcpy(buff, "user."); + } name = buff + strlen(buff); memcpy(name, p + 1, len); name[len] = '\0'; @@ -772,6 +787,31 @@ setup_xattrs(struct archive_read_disk *a, return (ARCHIVE_OK); } +static int +setup_xattrs(struct archive_read_disk *a, + struct archive_entry *entry, int *fd) +{ + int namespaces[2]; + int i, res; + + namespaces[0] = EXTATTR_NAMESPACE_USER; + namespaces[1] = EXTATTR_NAMESPACE_SYSTEM; + + for (i = 0; i < 2; i++) { + res = setup_xattrs_namespace(a, entry, fd, + namespaces[i]); + switch (res) { + case (ARCHIVE_OK): + case (ARCHIVE_WARN): + break; + default: + return (res); + } + } + + return (ARCHIVE_OK); +} + #else /* diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c index 52fec7b..2898206 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c @@ -1658,7 +1658,7 @@ static int setup_current_filesystem(struct archive_read_disk *a) { struct tree *t = a->tree; - struct statvfs sfs; + struct statvfs svfs; int r, xr = 0; t->current_filesystem->synthetic = -1; @@ -1667,16 +1667,16 @@ setup_current_filesystem(struct archive_read_disk *a) return (ARCHIVE_FAILED); } if (tree_current_is_symblic_link_target(t)) { - r = statvfs(tree_current_access_path(t), &sfs); + r = statvfs(tree_current_access_path(t), &svfs); if (r == 0) xr = get_xfer_size(t, -1, tree_current_access_path(t)); } else { #ifdef HAVE_FSTATVFS - r = fstatvfs(tree_current_dir_fd(t), &sfs); + r = fstatvfs(tree_current_dir_fd(t), &svfs); if (r == 0) xr = get_xfer_size(t, tree_current_dir_fd(t), NULL); #else - r = statvfs(".", &sfs); + r = statvfs(".", &svfs); if (r == 0) xr = get_xfer_size(t, -1, "."); #endif @@ -1688,30 +1688,30 @@ setup_current_filesystem(struct archive_read_disk *a) } else if (xr == 1) { /* Usually come here unless NetBSD supports _PC_REC_XFER_ALIGN * for pathconf() function. */ - t->current_filesystem->xfer_align = sfs.f_frsize; + t->current_filesystem->xfer_align = svfs.f_frsize; t->current_filesystem->max_xfer_size = -1; #if defined(HAVE_STRUCT_STATVFS_F_IOSIZE) - t->current_filesystem->min_xfer_size = sfs.f_iosize; - t->current_filesystem->incr_xfer_size = sfs.f_iosize; + t->current_filesystem->min_xfer_size = svfs.f_iosize; + t->current_filesystem->incr_xfer_size = svfs.f_iosize; #else - t->current_filesystem->min_xfer_size = sfs.f_bsize; - t->current_filesystem->incr_xfer_size = sfs.f_bsize; + t->current_filesystem->min_xfer_size = svfs.f_bsize; + t->current_filesystem->incr_xfer_size = svfs.f_bsize; #endif } - if (sfs.f_flag & ST_LOCAL) + if (svfs.f_flag & ST_LOCAL) t->current_filesystem->remote = 0; else t->current_filesystem->remote = 1; #if defined(ST_NOATIME) - if (sfs.f_flag & ST_NOATIME) + if (svfs.f_flag & ST_NOATIME) t->current_filesystem->noatime = 1; else #endif t->current_filesystem->noatime = 0; /* Set maximum filename length. */ - t->current_filesystem->name_max = sfs.f_namemax; + t->current_filesystem->name_max = svfs.f_namemax; return (ARCHIVE_OK); } @@ -1840,7 +1840,7 @@ setup_current_filesystem(struct archive_read_disk *a) #if defined(HAVE_STATVFS) if (svfs.f_flag & ST_NOATIME) #else - if (sfs.f_flag & ST_NOATIME) + if (sfs.f_flags & ST_NOATIME) #endif t->current_filesystem->noatime = 1; else @@ -1864,7 +1864,7 @@ static int setup_current_filesystem(struct archive_read_disk *a) { struct tree *t = a->tree; - struct statvfs sfs; + struct statvfs svfs; int r, xr = 0; t->current_filesystem->synthetic = -1;/* Not supported */ @@ -1883,7 +1883,7 @@ setup_current_filesystem(struct archive_read_disk *a) "openat failed"); return (ARCHIVE_FAILED); } - r = fstatvfs(fd, &sfs); + r = fstatvfs(fd, &svfs); if (r == 0) xr = get_xfer_size(t, fd, NULL); close(fd); @@ -1892,13 +1892,13 @@ setup_current_filesystem(struct archive_read_disk *a) archive_set_error(&a->archive, errno, "fchdir failed"); return (ARCHIVE_FAILED); } - r = statvfs(tree_current_access_path(t), &sfs); + r = statvfs(tree_current_access_path(t), &svfs); if (r == 0) xr = get_xfer_size(t, -1, tree_current_access_path(t)); #endif } else { #ifdef HAVE_FSTATVFS - r = fstatvfs(tree_current_dir_fd(t), &sfs); + r = fstatvfs(tree_current_dir_fd(t), &svfs); if (r == 0) xr = get_xfer_size(t, tree_current_dir_fd(t), NULL); #else @@ -1906,7 +1906,7 @@ setup_current_filesystem(struct archive_read_disk *a) archive_set_error(&a->archive, errno, "fchdir failed"); return (ARCHIVE_FAILED); } - r = statvfs(".", &sfs); + r = statvfs(".", &svfs); if (r == 0) xr = get_xfer_size(t, -1, "."); #endif @@ -1918,14 +1918,14 @@ setup_current_filesystem(struct archive_read_disk *a) return (ARCHIVE_FAILED); } else if (xr == 1) { /* pathconf(_PC_REX_*) operations are not supported. */ - t->current_filesystem->xfer_align = sfs.f_frsize; + t->current_filesystem->xfer_align = svfs.f_frsize; t->current_filesystem->max_xfer_size = -1; - t->current_filesystem->min_xfer_size = sfs.f_bsize; - t->current_filesystem->incr_xfer_size = sfs.f_bsize; + t->current_filesystem->min_xfer_size = svfs.f_bsize; + t->current_filesystem->incr_xfer_size = svfs.f_bsize; } #if defined(ST_NOATIME) - if (sfs.f_flag & ST_NOATIME) + if (svfs.f_flag & ST_NOATIME) t->current_filesystem->noatime = 1; else #endif @@ -1933,7 +1933,7 @@ setup_current_filesystem(struct archive_read_disk *a) #if defined(USE_READDIR_R) /* Set maximum filename length. */ - t->current_filesystem->name_max = sfs.f_namemax; + t->current_filesystem->name_max = svfs.f_namemax; #endif return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_filter.3 b/Utilities/cmlibarchive/libarchive/archive_read_filter.3 index 1ba5fcb..4f5c351 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_filter.3 +++ b/Utilities/cmlibarchive/libarchive/archive_read_filter.3 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 14, 2014 +.Dd June 9, 2020 .Dt ARCHIVE_READ_FILTER 3 .Os .Sh NAME @@ -50,6 +50,8 @@ Streaming Archive Library (libarchive, -larchive) .Ft int .Fn archive_read_support_filter_all "struct archive *" .Ft int +.Fn archive_read_support_filter_by_code "struct archive *" "int" +.Ft int .Fn archive_read_support_filter_bzip2 "struct archive *" .Ft int .Fn archive_read_support_filter_compress "struct archive *" @@ -116,6 +118,14 @@ Note that is always enabled by default. .It Fn archive_read_support_filter_all Enables all available decompression filters. +.It Fn archive_read_support_filter_by_code +Enables a single filter specified by the filter code. +This function does not work with +.Cm ARCHIVE_FILTER_PROGRAM . +Note: In statically-linked executables, this will cause +your program to include support for every filter. +If executable size is a concern, you may wish to avoid +using this function. .It Fn archive_read_support_filter_program Data is fed through the specified external program before being dearchived. Note that this disables automatic detection of the compression format, diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open_filename.c b/Utilities/cmlibarchive/libarchive/archive_read_open_filename.c index 86635e2..561289b 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_open_filename.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_open_filename.c @@ -221,7 +221,9 @@ file_open(struct archive *a, void *client_data) struct read_file_data *mine = (struct read_file_data *)client_data; void *buffer; const char *filename = NULL; +#if defined(_WIN32) && !defined(__CYGWIN__) const wchar_t *wfilename = NULL; +#endif int fd = -1; int is_disk_like = 0; #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) @@ -281,10 +283,12 @@ file_open(struct archive *a, void *client_data) #endif } if (fstat(fd, &st) != 0) { +#if defined(_WIN32) && !defined(__CYGWIN__) if (mine->filename_type == FNT_WCS) archive_set_error(a, errno, "Can't stat '%S'", wfilename); else +#endif archive_set_error(a, errno, "Can't stat '%s'", filename); goto fail; diff --git a/Utilities/cmlibarchive/libarchive/archive_read_set_format.c b/Utilities/cmlibarchive/libarchive/archive_read_set_format.c index 1d3e49d..796dcdc 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_set_format.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_set_format.c @@ -61,6 +61,9 @@ archive_read_set_format(struct archive *_a, int code) case ARCHIVE_FORMAT_CPIO: strcpy(str, "cpio"); break; + case ARCHIVE_FORMAT_EMPTY: + strcpy(str, "empty"); + break; case ARCHIVE_FORMAT_ISO9660: strcpy(str, "iso9660"); break; @@ -76,9 +79,15 @@ archive_read_set_format(struct archive *_a, int code) case ARCHIVE_FORMAT_RAR_V5: strcpy(str, "rar5"); break; + case ARCHIVE_FORMAT_RAW: + strcpy(str, "raw"); + break; case ARCHIVE_FORMAT_TAR: strcpy(str, "tar"); break; + case ARCHIVE_FORMAT_WARC: + strcpy(str, "warc"); + break; case ARCHIVE_FORMAT_XAR: strcpy(str, "xar"); break; diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_by_code.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_by_code.c new file mode 100644 index 0000000..94c4af6 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_by_code.c @@ -0,0 +1,83 @@ +/*- + * Copyright (c) 2020 Martin Matuska + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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 AUTHOR(S) 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 "archive_platform.h" +__FBSDID("$FreeBSD$"); + +#include "archive.h" +#include "archive_private.h" + +int +archive_read_support_filter_by_code(struct archive *a, int filter_code) +{ + archive_check_magic(a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_filter_by_code"); + + switch (filter_code) { + case ARCHIVE_FILTER_NONE: + return archive_read_support_filter_none(a); + break; + case ARCHIVE_FILTER_GZIP: + return archive_read_support_filter_gzip(a); + break; + case ARCHIVE_FILTER_BZIP2: + return archive_read_support_filter_bzip2(a); + break; + case ARCHIVE_FILTER_COMPRESS: + return archive_read_support_filter_compress(a); + break; + case ARCHIVE_FILTER_LZMA: + return archive_read_support_filter_lzma(a); + break; + case ARCHIVE_FILTER_XZ: + return archive_read_support_filter_xz(a); + break; + case ARCHIVE_FILTER_UU: + return archive_read_support_filter_uu(a); + break; + case ARCHIVE_FILTER_RPM: + return archive_read_support_filter_rpm(a); + break; + case ARCHIVE_FILTER_LZIP: + return archive_read_support_filter_lzip(a); + break; + case ARCHIVE_FILTER_LRZIP: + return archive_read_support_filter_lrzip(a); + break; + case ARCHIVE_FILTER_LZOP: + return archive_read_support_filter_lzop(a); + break; + case ARCHIVE_FILTER_GRZIP: + return archive_read_support_filter_grzip(a); + break; + case ARCHIVE_FILTER_LZ4: + return archive_read_support_filter_lz4(a); + break; + case ARCHIVE_FILTER_ZSTD: + return archive_read_support_filter_zstd(a); + break; + } + return (ARCHIVE_FATAL); +} diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_program.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_program.c index b8bf128..bf5b6f2 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_program.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_program.c @@ -400,7 +400,7 @@ __archive_read_program(struct archive_read_filter *self, const char *cmd) static const size_t out_buf_len = 65536; char *out_buf; const char *prefix = "Program: "; - pid_t child; + int ret; size_t l; l = strlen(prefix) + strlen(cmd) + 1; @@ -426,9 +426,9 @@ __archive_read_program(struct archive_read_filter *self, const char *cmd) state->out_buf = out_buf; state->out_buf_len = out_buf_len; - child = __archive_create_child(cmd, &state->child_stdin, - &state->child_stdout); - if (child == -1) { + ret = __archive_create_child(cmd, &state->child_stdin, + &state->child_stdout, &state->child); + if (ret != ARCHIVE_OK) { free(state->out_buf); archive_string_free(&state->description); free(state); @@ -437,21 +437,6 @@ __archive_read_program(struct archive_read_filter *self, const char *cmd) cmd); return (ARCHIVE_FATAL); } -#if defined(_WIN32) && !defined(__CYGWIN__) - state->child = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, child); - if (state->child == NULL) { - child_stop(self, state); - free(state->out_buf); - archive_string_free(&state->description); - free(state); - archive_set_error(&self->archive->archive, EINVAL, - "Can't initialize filter; unable to run program \"%s\"", - cmd); - return (ARCHIVE_FATAL); - } -#else - state->child = child; -#endif self->data = state; self->read = program_filter_read; diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_zstd.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_zstd.c index e1ec60e..c4e8ec7 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_zstd.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_zstd.c @@ -119,6 +119,8 @@ zstd_bidder_bid(struct archive_read_filter_bidder *self, /* Zstd frame magic values */ const unsigned zstd_magic = 0xFD2FB528U; + const unsigned zstd_magic_skippable_start = 0x184D2A50U; + const unsigned zstd_magic_skippable_mask = 0xFFFFFFF0; (void) self; /* UNUSED */ @@ -129,6 +131,8 @@ zstd_bidder_bid(struct archive_read_filter_bidder *self, prefix = archive_le32dec(buffer); if (prefix == zstd_magic) return (32); + if ((prefix & zstd_magic_skippable_mask) == zstd_magic_skippable_start) + return (32); return (0); } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_by_code.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_by_code.c index 034353d..89e96f1 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_by_code.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_by_code.c @@ -26,6 +26,10 @@ #include "archive_platform.h" __FBSDID("$FreeBSD$"); +#ifdef HAVE_ERRNO_H +#include <errno.h> +#endif + #include "archive.h" #include "archive_private.h" @@ -48,6 +52,9 @@ archive_read_support_format_by_code(struct archive *a, int format_code) case ARCHIVE_FORMAT_CPIO: return archive_read_support_format_cpio(a); break; + case ARCHIVE_FORMAT_EMPTY: + return archive_read_support_format_empty(a); + break; case ARCHIVE_FORMAT_ISO9660: return archive_read_support_format_iso9660(a); break; @@ -63,9 +70,15 @@ archive_read_support_format_by_code(struct archive *a, int format_code) case ARCHIVE_FORMAT_RAR_V5: return archive_read_support_format_rar5(a); break; + case ARCHIVE_FORMAT_RAW: + return archive_read_support_format_raw(a); + break; case ARCHIVE_FORMAT_TAR: return archive_read_support_format_tar(a); break; + case ARCHIVE_FORMAT_WARC: + return archive_read_support_format_warc(a); + break; case ARCHIVE_FORMAT_XAR: return archive_read_support_format_xar(a); break; @@ -73,5 +86,7 @@ archive_read_support_format_by_code(struct archive *a, int format_code) return archive_read_support_format_zip(a); break; } + archive_set_error(a, ARCHIVE_ERRNO_PROGRAMMER, + "Invalid format code specified"); return (ARCHIVE_FATAL); } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c index 58644ba..57547d4 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c @@ -1172,7 +1172,7 @@ cab_checksum_finish(struct archive_read *a) cfdata->memimage + CFDATA_cbData, l, cfdata->sum_calculated); if (cfdata->sum_calculated != cfdata->sum) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Checksum error CFDATA[%d] %x:%x in %d bytes", + "Checksum error CFDATA[%d] %" PRIx32 ":%" PRIx32 " in %d bytes", cab->entry_cffolder->cfdata_index -1, cfdata->sum, cfdata->sum_calculated, cfdata->compressed_size); diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_empty.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_empty.c index c641eb9..53fb6cc 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_empty.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_empty.c @@ -47,7 +47,7 @@ archive_read_support_format_empty(struct archive *_a) r = __archive_read_register_format(a, NULL, - NULL, + "empty", archive_read_format_empty_bid, NULL, archive_read_format_empty_read_header, diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c index 332944a..93ba295 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_mtree.c 2011 #include "archive.h" #include "archive_entry.h" +#include "archive_entry_private.h" #include "archive_private.h" #include "archive_rb.h" #include "archive_read_private.h" @@ -135,6 +136,9 @@ static int skip(struct archive_read *a); static int read_header(struct archive_read *, struct archive_entry *); static int64_t mtree_atol(char **, int base); +#ifndef HAVE_STRNLEN +static size_t mtree_strnlen(const char *, size_t); +#endif /* * There's no standard for TIME_T_MAX/TIME_T_MIN. So we compute them @@ -186,6 +190,24 @@ get_time_t_min(void) #endif } +#ifdef HAVE_STRNLEN +#define mtree_strnlen(a,b) strnlen(a,b) +#else +static size_t +mtree_strnlen(const char *p, size_t maxlen) +{ + size_t i; + + for (i = 0; i <= maxlen; i++) { + if (p[i] == 0) + break; + } + if (i > maxlen) + return (-1);/* invalid */ + return (i); +} +#endif + static int archive_read_format_mtree_options(struct archive_read *a, const char *key, const char *val) @@ -1482,6 +1504,84 @@ parse_device(dev_t *pdev, struct archive *a, char *val) #undef MAX_PACK_ARGS } +static int +parse_hex_nibble(char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + if (c >= 'a' && c <= 'f') + return 10 + c - 'a'; +#if 0 + /* XXX: Is uppercase something we should support? */ + if (c >= 'A' && c <= 'F') + return 10 + c - 'A'; +#endif + + return -1; +} + +static int +parse_digest(struct archive_read *a, struct archive_entry *entry, + const char *digest, int type) +{ + unsigned char digest_buf[64]; + int high, low; + size_t i, j, len; + + switch (type) { + case ARCHIVE_ENTRY_DIGEST_MD5: + len = sizeof(entry->digest.md5); + break; + case ARCHIVE_ENTRY_DIGEST_RMD160: + len = sizeof(entry->digest.rmd160); + break; + case ARCHIVE_ENTRY_DIGEST_SHA1: + len = sizeof(entry->digest.sha1); + break; + case ARCHIVE_ENTRY_DIGEST_SHA256: + len = sizeof(entry->digest.sha256); + break; + case ARCHIVE_ENTRY_DIGEST_SHA384: + len = sizeof(entry->digest.sha384); + break; + case ARCHIVE_ENTRY_DIGEST_SHA512: + len = sizeof(entry->digest.sha512); + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, + "Internal error: Unknown digest type"); + return ARCHIVE_FATAL; + } + + if (len > sizeof(digest_buf)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, + "Internal error: Digest storage too large"); + return ARCHIVE_FATAL; + } + + len *= 2; + + if (mtree_strnlen(digest, len+1) != len) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "incorrect digest length, ignoring"); + return ARCHIVE_WARN; + } + + for (i = 0, j = 0; i < len; i += 2, j++) { + high = parse_hex_nibble(digest[i]); + low = parse_hex_nibble(digest[i+1]); + if (high == -1 || low == -1) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "invalid digest data, ignoring"); + return ARCHIVE_WARN; + } + + digest_buf[j] = high << 4 | low; + } + + return archive_entry_set_digest(entry, type, digest_buf); +} + /* * Parse a single keyword and its value. */ @@ -1580,8 +1680,10 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, } __LA_FALLTHROUGH; case 'm': - if (strcmp(key, "md5") == 0 || strcmp(key, "md5digest") == 0) - break; + if (strcmp(key, "md5") == 0 || strcmp(key, "md5digest") == 0) { + return parse_digest(a, entry, val, + ARCHIVE_ENTRY_DIGEST_MD5); + } if (strcmp(key, "mode") == 0) { if (val[0] >= '0' && val[0] <= '7') { *parsed_kws |= MTREE_HAS_PERM; @@ -1617,21 +1719,32 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, return r; } if (strcmp(key, "rmd160") == 0 || - strcmp(key, "rmd160digest") == 0) - break; + strcmp(key, "rmd160digest") == 0) { + return parse_digest(a, entry, val, + ARCHIVE_ENTRY_DIGEST_RMD160); + } __LA_FALLTHROUGH; case 's': - if (strcmp(key, "sha1") == 0 || strcmp(key, "sha1digest") == 0) - break; + if (strcmp(key, "sha1") == 0 || + strcmp(key, "sha1digest") == 0) { + return parse_digest(a, entry, val, + ARCHIVE_ENTRY_DIGEST_SHA1); + } if (strcmp(key, "sha256") == 0 || - strcmp(key, "sha256digest") == 0) - break; + strcmp(key, "sha256digest") == 0) { + return parse_digest(a, entry, val, + ARCHIVE_ENTRY_DIGEST_SHA256); + } if (strcmp(key, "sha384") == 0 || - strcmp(key, "sha384digest") == 0) - break; + strcmp(key, "sha384digest") == 0) { + return parse_digest(a, entry, val, + ARCHIVE_ENTRY_DIGEST_SHA384); + } if (strcmp(key, "sha512") == 0 || - strcmp(key, "sha512digest") == 0) - break; + strcmp(key, "sha512digest") == 0) { + return parse_digest(a, entry, val, + ARCHIVE_ENTRY_DIGEST_SHA512); + } if (strcmp(key, "size") == 0) { archive_entry_set_size(entry, mtree_atol(&val, 10)); break; diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c index 61f2330..6dca350 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c @@ -151,6 +151,9 @@ #undef minimum #define minimum(a, b) ((a)<(b)?(a):(b)) +/* Stack overflow check */ +#define MAX_COMPRESS_DEPTH 1024 + /* Fields common to all headers */ struct rar_header { @@ -340,7 +343,7 @@ static int read_symlink_stored(struct archive_read *, struct archive_entry *, static int read_data_stored(struct archive_read *, const void **, size_t *, int64_t *); static int read_data_compressed(struct archive_read *, const void **, size_t *, - int64_t *); + int64_t *, size_t); static int rar_br_preparation(struct archive_read *, struct rar_br *); static int parse_codes(struct archive_read *); static void free_codes(struct archive_read *); @@ -1026,7 +1029,7 @@ archive_read_format_rar_read_data(struct archive_read *a, const void **buff, case COMPRESS_METHOD_NORMAL: case COMPRESS_METHOD_GOOD: case COMPRESS_METHOD_BEST: - ret = read_data_compressed(a, buff, size, offset); + ret = read_data_compressed(a, buff, size, offset, 0); if (ret != ARCHIVE_OK && ret != ARCHIVE_WARN) { __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context); rar->start_new_table = 1; @@ -1883,8 +1886,11 @@ read_data_stored(struct archive_read *a, const void **buff, size_t *size, static int read_data_compressed(struct archive_read *a, const void **buff, size_t *size, - int64_t *offset) + int64_t *offset, size_t looper) { + if (looper++ > MAX_COMPRESS_DEPTH) + return (ARCHIVE_FATAL); + struct rar *rar; int64_t start, end, actualend; size_t bs; @@ -1982,7 +1988,7 @@ read_data_compressed(struct archive_read *a, const void **buff, size_t *size, { case 0: rar->start_new_table = 1; - return read_data_compressed(a, buff, size, offset); + return read_data_compressed(a, buff, size, offset, looper); case 2: rar->ppmd_eod = 1;/* End Of ppmd Data. */ diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar5.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar5.c index d3a1c1b..3131955 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar5.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar5.c @@ -3084,12 +3084,6 @@ static int do_uncompress_block(struct archive_read* a, const uint8_t* p) { continue; } - - /* The program counter shouldn't reach here. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Unsupported block code: 0x%x", num); - - return ARCHIVE_FATAL; } return ARCHIVE_OK; @@ -3837,7 +3831,7 @@ static int verify_checksums(struct archive_read* a) { DEBUG_CODE { printf("Checksum error: CRC32 " - "(was: %08x, expected: %08x)\n", + "(was: %08" PRIx32 ", expected: %08" PRIx32 ")\n", rar->file.calculated_crc32, rar->file.stored_crc32); } @@ -3851,7 +3845,7 @@ static int verify_checksums(struct archive_read* a) { } else { DEBUG_CODE { printf("Checksum OK: CRC32 " - "(%08x/%08x)\n", + "(%08" PRIx32 "/%08" PRIx32 ")\n", rar->file.stored_crc32, rar->file.calculated_crc32); } @@ -3912,6 +3906,9 @@ static int rar5_read_data(struct archive_read *a, const void **buff, int ret; struct rar5* rar = get_context(a); + if (size) + *size = 0; + if(rar->file.dir > 0) { /* Don't process any data if this file entry was declared * as a directory. This is needed, because entries marked as diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c index c63d46f..96d8101 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c @@ -1797,6 +1797,16 @@ pax_attribute_schily_xattr(struct archive_entry *entry, } static int +pax_attribute_rht_security_selinux(struct archive_entry *entry, + const char *value, size_t value_length) +{ + archive_entry_xattr_add_entry(entry, "security.selinux", + value, value_length); + + return 0; +} + +static int pax_attribute_acl(struct archive_read *a, struct tar *tar, struct archive_entry *entry, const char *value, int type) { @@ -1966,6 +1976,14 @@ pax_attribute(struct archive_read *a, struct tar *tar, if (memcmp(key, "LIBARCHIVE.xattr.", 17) == 0) pax_attribute_xattr(entry, key, value); break; + case 'R': + /* GNU tar uses RHT.security header to store SELinux xattrs + * SCHILY.xattr.security.selinux == RHT.security.selinux */ + if (strcmp(key, "RHT.security.selinux") == 0) { + pax_attribute_rht_security_selinux(entry, value, + value_length); + } + break; case 'S': /* We support some keys used by the "star" archiver */ if (strcmp(key, "SCHILY.acl.access") == 0) { diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_warc.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_warc.c index 72977b8..2732996 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_warc.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_warc.c @@ -127,7 +127,7 @@ static int _warc_skip(struct archive_read *a); static int _warc_rdhdr(struct archive_read *a, struct archive_entry *e); /* private routines */ -static unsigned int _warc_rdver(const char buf[10], size_t bsz); +static unsigned int _warc_rdver(const char *buf, size_t bsz); static unsigned int _warc_rdtyp(const char *buf, size_t bsz); static warc_string_t _warc_rduri(const char *buf, size_t bsz); static ssize_t _warc_rdlen(const char *buf, size_t bsz); @@ -337,6 +337,14 @@ start_over: mtime = rtime; } break; + case WT_NONE: + case WT_INFO: + case WT_META: + case WT_REQ: + case WT_RVIS: + case WT_CONV: + case WT_CONT: + case LAST_WT: default: fnam.len = 0U; fnam.str = NULL; @@ -361,6 +369,14 @@ start_over: break; } /* FALLTHROUGH */ + case WT_NONE: + case WT_INFO: + case WT_META: + case WT_REQ: + case WT_RVIS: + case WT_CONV: + case WT_CONT: + case LAST_WT: default: /* consume the content and start over */ _warc_skip(a); @@ -427,7 +443,7 @@ _warc_skip(struct archive_read *a) static void* deconst(const void *c) { - return (char *)0x1 + (((const char *)c) - (const char *)0x1); + return (void *)(uintptr_t)c; } static char* diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c index bcb67fe..2e60cf7 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c @@ -458,6 +458,11 @@ archive_read_support_format_xar(struct archive *_a) return (ARCHIVE_FATAL); } + /* initialize xar->file_queue */ + xar->file_queue.allocated = 0; + xar->file_queue.used = 0; + xar->file_queue.files = NULL; + r = __archive_read_register_format(a, xar, "xar", @@ -1221,10 +1226,12 @@ heap_add_entry(struct archive_read *a, /* Expand our pending files list as necessary. */ if (heap->used >= heap->allocated) { struct xar_file **new_pending_files; - int new_size = heap->allocated * 2; + int new_size; if (heap->allocated < 1024) new_size = 1024; + else + new_size = heap->allocated * 2; /* Overflow might keep us from growing the list. */ if (new_size <= heap->allocated) { archive_set_error(&a->archive, @@ -1238,9 +1245,11 @@ heap_add_entry(struct archive_read *a, ENOMEM, "Out of memory"); return (ARCHIVE_FATAL); } - memcpy(new_pending_files, heap->files, - heap->allocated * sizeof(new_pending_files[0])); - free(heap->files); + if (heap->allocated) { + memcpy(new_pending_files, heap->files, + heap->allocated * sizeof(new_pending_files[0])); + free(heap->files); + } heap->files = new_pending_files; heap->allocated = new_size; } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c index 62f98a4..6314c68 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c @@ -899,6 +899,81 @@ process_extra(struct archive_read *a, struct archive_entry *entry, return ARCHIVE_OK; } +#if HAVE_LZMA_H && HAVE_LIBLZMA +/* + * Auxiliary function to uncompress data chunk from zipx archive + * (zip with lzma compression). + */ +static int +zipx_lzma_uncompress_buffer(const char *compressed_buffer, + size_t compressed_buffer_size, + char *uncompressed_buffer, + size_t uncompressed_buffer_size) +{ + int status = ARCHIVE_FATAL; + // length of 'lzma properties data' in lzma compressed + // data segment (stream) inside zip archive + const size_t lzma_params_length = 5; + // offset of 'lzma properties data' from the beginning of lzma stream + const size_t lzma_params_offset = 4; + // end position of 'lzma properties data' in lzma stream + const size_t lzma_params_end = lzma_params_offset + lzma_params_length; + if (compressed_buffer == NULL || + compressed_buffer_size < lzma_params_end || + uncompressed_buffer == NULL) + return status; + + // prepare header for lzma_alone_decoder to replace zipx header + // (see comments in 'zipx_lzma_alone_init' for justification) +#pragma pack(push) +#pragma pack(1) + struct _alone_header + { + uint8_t bytes[5]; // lzma_params_length + uint64_t uncompressed_size; + } alone_header; +#pragma pack(pop) + // copy 'lzma properties data' blob + memcpy(&alone_header.bytes[0], compressed_buffer + lzma_params_offset, + lzma_params_length); + alone_header.uncompressed_size = UINT64_MAX; + + // prepare new compressed buffer, see 'zipx_lzma_alone_init' for details + const size_t lzma_alone_buffer_size = + compressed_buffer_size - lzma_params_end + sizeof(alone_header); + unsigned char *lzma_alone_compressed_buffer = + (unsigned char*) malloc(lzma_alone_buffer_size); + if (lzma_alone_compressed_buffer == NULL) + return status; + // copy lzma_alone header into new buffer + memcpy(lzma_alone_compressed_buffer, (void*) &alone_header, + sizeof(alone_header)); + // copy compressed data into new buffer + memcpy(lzma_alone_compressed_buffer + sizeof(alone_header), + compressed_buffer + lzma_params_end, + compressed_buffer_size - lzma_params_end); + + // create and fill in lzma_alone_decoder stream + lzma_stream stream = LZMA_STREAM_INIT; + lzma_ret ret = lzma_alone_decoder(&stream, UINT64_MAX); + if (ret == LZMA_OK) + { + stream.next_in = lzma_alone_compressed_buffer; + stream.avail_in = lzma_alone_buffer_size; + stream.total_in = 0; + stream.next_out = (unsigned char*)uncompressed_buffer; + stream.avail_out = uncompressed_buffer_size; + stream.total_out = 0; + ret = lzma_code(&stream, LZMA_RUN); + if (ret == LZMA_OK || ret == LZMA_STREAM_END) + status = ARCHIVE_OK; + } + lzma_end(&stream); + free(lzma_alone_compressed_buffer); + return status; +} +#endif + /* * Assumes file pointer is at beginning of local file header. */ @@ -1173,18 +1248,64 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry, "Truncated Zip file"); return ARCHIVE_FATAL; } + // take into account link compression if any + size_t linkname_full_length = linkname_length; + if (zip->entry->compression != 0) + { + // symlink target string appeared to be compressed + int status = ARCHIVE_FATAL; + char *uncompressed_buffer = + (char*) malloc(zip_entry->uncompressed_size); + if (uncompressed_buffer == NULL) + { + archive_set_error(&a->archive, ENOMEM, + "No memory for lzma decompression"); + return status; + } + + switch (zip->entry->compression) + { +#if HAVE_LZMA_H && HAVE_LIBLZMA + case 14: /* ZIPx LZMA compression. */ + /*(see zip file format specification, section 4.4.5)*/ + status = zipx_lzma_uncompress_buffer(p, + linkname_length, + uncompressed_buffer, + (size_t)zip_entry->uncompressed_size); + break; +#endif + default: /* Unsupported compression. */ + break; + } + if (status == ARCHIVE_OK) + { + p = uncompressed_buffer; + linkname_full_length = + (size_t)zip_entry->uncompressed_size; + } + else + { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Unsupported ZIP compression method " + "during decompression of link entry (%d: %s)", + zip->entry->compression, + compression_name(zip->entry->compression)); + return ARCHIVE_FAILED; + } + } sconv = zip->sconv; if (sconv == NULL && (zip->entry->zip_flags & ZIP_UTF8_NAME)) sconv = zip->sconv_utf8; if (sconv == NULL) sconv = zip->sconv_default; - if (archive_entry_copy_symlink_l(entry, p, linkname_length, + if (archive_entry_copy_symlink_l(entry, p, linkname_full_length, sconv) != 0) { if (errno != ENOMEM && sconv == zip->sconv_utf8 && (zip->entry->zip_flags & ZIP_UTF8_NAME)) archive_entry_copy_symlink_l(entry, p, - linkname_length, NULL); + linkname_full_length, NULL); if (errno == ENOMEM) { archive_set_error(&a->archive, ENOMEM, "Can't allocate memory for Symlink"); @@ -1901,15 +2022,15 @@ zipx_ppmd8_init(struct archive_read *a, struct zip *zip) if(order < 2 || restore_method > 2) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Invalid parameter set in PPMd8 stream (order=%d, " - "restore=%d)", order, restore_method); + "Invalid parameter set in PPMd8 stream (order=%" PRId32 ", " + "restore=%" PRId32 ")", order, restore_method); return (ARCHIVE_FAILED); } /* Allocate the memory needed to properly decompress the file. */ if(!__archive_ppmd8_functions.Ppmd8_Alloc(&zip->ppmd8, mem << 20)) { archive_set_error(&a->archive, ENOMEM, - "Unable to allocate memory for PPMd8 stream: %d bytes", + "Unable to allocate memory for PPMd8 stream: %" PRId32 " bytes", mem << 20); return (ARCHIVE_FATAL); } diff --git a/Utilities/cmlibarchive/libarchive/archive_string.c b/Utilities/cmlibarchive/libarchive/archive_string.c index c77dcf5..7460ded 100644 --- a/Utilities/cmlibarchive/libarchive/archive_string.c +++ b/Utilities/cmlibarchive/libarchive/archive_string.c @@ -3881,6 +3881,11 @@ archive_mstring_get_utf8(struct archive *a, struct archive_mstring *aes, } *p = NULL; + /* Try converting WCS to MBS first if MBS does not exist yet. */ + if ((aes->aes_set & AES_SET_MBS) == 0) { + const char *pm; /* unused */ + archive_mstring_get_mbs(a, aes, &pm); /* ignore errors, we'll handle it later */ + } if (aes->aes_set & AES_SET_MBS) { sc = archive_string_conversion_to_charset(a, "UTF-8", 1); if (sc == NULL) @@ -3903,9 +3908,9 @@ int archive_mstring_get_mbs(struct archive *a, struct archive_mstring *aes, const char **p) { + struct archive_string_conv *sc; int r, ret = 0; - (void)a; /* UNUSED */ /* If we already have an MBS form, return that immediately. */ if (aes->aes_set & AES_SET_MBS) { *p = aes->aes_mbs.s; @@ -3926,10 +3931,23 @@ archive_mstring_get_mbs(struct archive *a, struct archive_mstring *aes, ret = -1; } - /* - * Only a UTF-8 form cannot avail because its conversion already - * failed at archive_mstring_update_utf8(). - */ + /* If there's a UTF-8 form, try converting with the native locale. */ + if (aes->aes_set & AES_SET_UTF8) { + archive_string_empty(&(aes->aes_mbs)); + sc = archive_string_conversion_from_charset(a, "UTF-8", 1); + if (sc == NULL) + return (-1);/* Couldn't allocate memory for sc. */ + r = archive_strncpy_l(&(aes->aes_mbs), + aes->aes_utf8.s, aes->aes_utf8.length, sc); + if (a == NULL) + free_sconv_object(sc); + *p = aes->aes_mbs.s; + if (r == 0) { + aes->aes_set |= AES_SET_MBS; + ret = 0;/* success; overwrite previous error. */ + } else + ret = -1;/* failure. */ + } return (ret); } @@ -3947,6 +3965,11 @@ archive_mstring_get_wcs(struct archive *a, struct archive_mstring *aes, } *wp = NULL; + /* Try converting UTF8 to MBS first if MBS does not exist yet. */ + if ((aes->aes_set & AES_SET_MBS) == 0) { + const char *p; /* unused */ + archive_mstring_get_mbs(a, aes, &p); /* ignore errors, we'll handle it later */ + } /* Try converting MBS to WCS using native locale. */ if (aes->aes_set & AES_SET_MBS) { archive_wstring_empty(&(aes->aes_wcs)); @@ -3962,11 +3985,12 @@ archive_mstring_get_wcs(struct archive *a, struct archive_mstring *aes, } int -archive_mstring_get_mbs_l(struct archive_mstring *aes, +archive_mstring_get_mbs_l(struct archive *a, struct archive_mstring *aes, const char **p, size_t *length, struct archive_string_conv *sc) { int r, ret = 0; + (void)r; /* UNUSED */ #if defined(_WIN32) && !defined(__CYGWIN__) /* * Internationalization programming on Windows must use Wide @@ -3989,20 +4013,12 @@ archive_mstring_get_mbs_l(struct archive_mstring *aes, } #endif - /* If there is not an MBS form but is a WCS form, try converting + /* If there is not an MBS form but there is a WCS or UTF8 form, try converting * with the native locale to be used for translating it to specified * character-set. */ - if ((aes->aes_set & AES_SET_MBS) == 0 && - (aes->aes_set & AES_SET_WCS) != 0) { - archive_string_empty(&(aes->aes_mbs)); - r = archive_string_append_from_wcs(&(aes->aes_mbs), - aes->aes_wcs.s, aes->aes_wcs.length); - if (r == 0) - aes->aes_set |= AES_SET_MBS; - else if (errno == ENOMEM) - return (-1); - else - ret = -1; + if ((aes->aes_set & AES_SET_MBS) == 0) { + const char *pm; /* unused */ + archive_mstring_get_mbs(a, aes, &pm); /* ignore errors, we'll handle it later */ } /* If we already have an MBS form, use it to be translated to * specified character-set. */ diff --git a/Utilities/cmlibarchive/libarchive/archive_string.h b/Utilities/cmlibarchive/libarchive/archive_string.h index 27e1ad6..49d7d30 100644 --- a/Utilities/cmlibarchive/libarchive/archive_string.h +++ b/Utilities/cmlibarchive/libarchive/archive_string.h @@ -226,7 +226,7 @@ void archive_mstring_copy(struct archive_mstring *dest, struct archive_mstring * int archive_mstring_get_mbs(struct archive *, struct archive_mstring *, const char **); int archive_mstring_get_utf8(struct archive *, struct archive_mstring *, const char **); int archive_mstring_get_wcs(struct archive *, struct archive_mstring *, const wchar_t **); -int archive_mstring_get_mbs_l(struct archive_mstring *, const char **, +int archive_mstring_get_mbs_l(struct archive *, struct archive_mstring *, const char **, size_t *, struct archive_string_conv *); int archive_mstring_copy_mbs(struct archive_mstring *, const char *mbs); int archive_mstring_copy_mbs_len(struct archive_mstring *, const char *mbs, diff --git a/Utilities/cmlibarchive/libarchive/archive_util.c b/Utilities/cmlibarchive/libarchive/archive_util.c index 10dca73..83586b5 100644 --- a/Utilities/cmlibarchive/libarchive/archive_util.c +++ b/Utilities/cmlibarchive/libarchive/archive_util.c @@ -365,6 +365,7 @@ __archive_mktempx(const char *tmpdir, wchar_t *template) } fd = _open_osfhandle((intptr_t)h, _O_BINARY | _O_RDWR); if (fd == -1) { + la_dosmaperr(GetLastError()); CloseHandle(h); goto exit_tmpfile; } else @@ -432,6 +433,11 @@ __archive_mktemp(const char *tmpdir) if (temp_name.s[temp_name.length-1] != '/') archive_strappend_char(&temp_name, '/'); } +#ifdef O_TMPFILE + fd = open(temp_name.s, O_RDWR|O_CLOEXEC|O_TMPFILE|O_EXCL, 0600); + if(fd >= 0) + goto exit_tmpfile; +#endif archive_strcat(&temp_name, "libarchive_XXXXXX"); fd = mkstemp(temp_name.s); if (fd < 0) diff --git a/Utilities/cmlibarchive/libarchive/archive_write.c b/Utilities/cmlibarchive/libarchive/archive_write.c index 98a55fb..8d70f51 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write.c +++ b/Utilities/cmlibarchive/libarchive/archive_write.c @@ -456,6 +456,25 @@ archive_write_client_write(struct archive_write_filter *f, } static int +archive_write_client_free(struct archive_write_filter *f) +{ + struct archive_write *a = (struct archive_write *)f->archive; + + if (a->client_freer) + (*a->client_freer)(&a->archive, a->client_data); + a->client_data = NULL; + + /* Clear passphrase. */ + if (a->passphrase != NULL) { + memset(a->passphrase, 0, strlen(a->passphrase)); + free(a->passphrase); + a->passphrase = NULL; + } + + return (ARCHIVE_OK); +} + +static int archive_write_client_close(struct archive_write_filter *f) { struct archive_write *a = (struct archive_write *)f->archive; @@ -493,13 +512,7 @@ archive_write_client_close(struct archive_write_filter *f) (*a->client_closer)(&a->archive, a->client_data); free(state->buffer); free(state); - a->client_data = NULL; - /* Clear passphrase. */ - if (a->passphrase != NULL) { - memset(a->passphrase, 0, strlen(a->passphrase)); - free(a->passphrase); - a->passphrase = NULL; - } + /* Clear the close handler myself not to be called again. */ f->state = ARCHIVE_WRITE_FILTER_STATE_CLOSED; return (ret); @@ -509,9 +522,9 @@ archive_write_client_close(struct archive_write_filter *f) * Open the archive using the current settings. */ int -archive_write_open(struct archive *_a, void *client_data, +archive_write_open2(struct archive *_a, void *client_data, archive_open_callback *opener, archive_write_callback *writer, - archive_close_callback *closer) + archive_close_callback *closer, archive_free_callback *freer) { struct archive_write *a = (struct archive_write *)_a; struct archive_write_filter *client_filter; @@ -524,12 +537,14 @@ archive_write_open(struct archive *_a, void *client_data, a->client_writer = writer; a->client_opener = opener; a->client_closer = closer; + a->client_freer = freer; a->client_data = client_data; client_filter = __archive_write_allocate_filter(_a); client_filter->open = archive_write_client_open; client_filter->write = archive_write_client_write; client_filter->close = archive_write_client_close; + client_filter->free = archive_write_client_free; ret = __archive_write_filters_open(a); if (ret < ARCHIVE_WARN) { @@ -544,6 +559,15 @@ archive_write_open(struct archive *_a, void *client_data, return (ret); } +int +archive_write_open(struct archive *_a, void *client_data, + archive_open_callback *opener, archive_write_callback *writer, + archive_close_callback *closer) +{ + return archive_write_open2(_a, client_data, opener, writer, + closer, NULL); +} + /* * Close out the archive. */ diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c index a4bc1d9..c096e72 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c @@ -196,10 +196,6 @@ __archive_write_program_free(struct archive_write_program_data *data) { if (data) { -#if defined(_WIN32) && !defined(__CYGWIN__) - if (data->child) - CloseHandle(data->child); -#endif free(data->program_name); free(data->child_buf); free(data); @@ -211,7 +207,7 @@ int __archive_write_program_open(struct archive_write_filter *f, struct archive_write_program_data *data, const char *cmd) { - pid_t child; + int ret; if (data->child_buf == NULL) { data->child_buf_len = 65536; @@ -225,27 +221,13 @@ __archive_write_program_open(struct archive_write_filter *f, } } - child = __archive_create_child(cmd, &data->child_stdin, - &data->child_stdout); - if (child == -1) { + ret = __archive_create_child(cmd, &data->child_stdin, + &data->child_stdout, &data->child); + if (ret != ARCHIVE_OK) { archive_set_error(f->archive, EINVAL, "Can't launch external program: %s", cmd); return (ARCHIVE_FATAL); } -#if defined(_WIN32) && !defined(__CYGWIN__) - data->child = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, child); - if (data->child == NULL) { - close(data->child_stdin); - data->child_stdin = -1; - close(data->child_stdout); - data->child_stdout = -1; - archive_set_error(f->archive, EINVAL, - "Can't launch external program: %s", cmd); - return (ARCHIVE_FATAL); - } -#else - data->child = child; -#endif return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_xz.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_xz.c index d567ac9..00df8da 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_xz.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_xz.c @@ -382,8 +382,12 @@ archive_compressor_xz_options(struct archive_write_filter *f, value[1] != '\0') return (ARCHIVE_WARN); data->compression_level = value[0] - '0'; + if (data->compression_level > 9) + data->compression_level = 9; +#ifdef _AIX if (data->compression_level > 6) data->compression_level = 6; +#endif return (ARCHIVE_OK); } else if (strcmp(key, "threads") == 0) { char *endptr; diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_zstd.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_zstd.c index f67b025..6d71628 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_zstd.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_zstd.c @@ -59,6 +59,16 @@ struct private_data { #endif }; +/* If we don't have the library use default range values (zstdcli.c v1.4.0) */ +#define CLEVEL_MIN -99 +#define CLEVEL_STD_MIN 0 /* prior to 1.3.4 and more recent without using --fast */ +#define CLEVEL_DEFAULT 3 +#define CLEVEL_STD_MAX 19 /* without using --ultra */ +#define CLEVEL_MAX 22 + +#define MINVER_NEGCLEVEL 10304 +#define MINVER_MINCLEVEL 10306 + static int archive_compressor_zstd_options(struct archive_write_filter *, const char *, const char *); static int archive_compressor_zstd_open(struct archive_write_filter *); @@ -96,7 +106,7 @@ archive_write_add_filter_zstd(struct archive *_a) f->free = &archive_compressor_zstd_free; f->code = ARCHIVE_FILTER_ZSTD; f->name = "zstd"; - data->compression_level = 3; /* Default level used by the zstd CLI */ + data->compression_level = CLEVEL_DEFAULT; #if HAVE_ZSTD_H && HAVE_LIBZSTD data->cstream = ZSTD_createCStream(); if (data->cstream == NULL) { @@ -135,6 +145,31 @@ archive_compressor_zstd_free(struct archive_write_filter *f) return (ARCHIVE_OK); } +static int string_is_numeric (const char* value) +{ + size_t len = strlen(value); + size_t i; + + if (len == 0) { + return (ARCHIVE_WARN); + } + else if (len == 1 && !(value[0] >= '0' && value[0] <= '9')) { + return (ARCHIVE_WARN); + } + else if (!(value[0] >= '0' && value[0] <= '9') && + value[0] != '-' && value[0] != '+') { + return (ARCHIVE_WARN); + } + + for (i = 1; i < len; i++) { + if (!(value[i] >= '0' && value[i] <= '9')) { + return (ARCHIVE_WARN); + } + } + + return (ARCHIVE_OK); +} + /* * Set write options. */ @@ -146,12 +181,25 @@ archive_compressor_zstd_options(struct archive_write_filter *f, const char *key, if (strcmp(key, "compression-level") == 0) { int level = atoi(value); -#if HAVE_ZSTD_H && HAVE_LIBZSTD - if (level < 1 || level > ZSTD_maxCLevel()) { -#else /* If we don't have the library, hard-code the max level */ - if (level < 1 || level > 22) { + int minimum = CLEVEL_MIN; + int maximum = CLEVEL_MAX; + if (string_is_numeric(value) != ARCHIVE_OK) { + return (ARCHIVE_WARN); + } +#if HAVE_ZSTD_H && HAVE_LIBZSTD + maximum = ZSTD_maxCLevel(); +#if ZSTD_VERSION_NUMBER >= MINVER_MINCLEVEL + if (ZSTD_versionNumber() >= MINVER_MINCLEVEL) { + minimum = ZSTD_minCLevel(); + } + else +#endif + if (ZSTD_versionNumber() < MINVER_NEGCLEVEL) { + minimum = CLEVEL_STD_MIN; + } #endif + if (level < minimum || level > maximum) { return (ARCHIVE_WARN); } data->compression_level = level; @@ -297,7 +345,26 @@ archive_compressor_zstd_open(struct archive_write_filter *f) int r; archive_string_init(&as); - archive_string_sprintf(&as, "zstd -%d", data->compression_level); + /* --no-check matches library default */ + archive_strcpy(&as, "zstd --no-check"); + + if (data->compression_level < CLEVEL_STD_MIN) { + struct archive_string as2; + archive_string_init(&as2); + archive_string_sprintf(&as2, " --fast=%d", -data->compression_level); + archive_string_concat(&as, &as2); + archive_string_free(&as2); + } else { + struct archive_string as2; + archive_string_init(&as2); + archive_string_sprintf(&as2, " -%d", data->compression_level); + archive_string_concat(&as, &as2); + archive_string_free(&as2); + } + + if (data->compression_level > CLEVEL_STD_MAX) { + archive_strcat(&as, " --ultra"); + } f->write = archive_compressor_zstd_write; r = __archive_write_program_open(f, data->pdata, as.s); diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c index c4be9b0..2551ebe 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c @@ -546,6 +546,7 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry) { struct archive_write_disk *a = (struct archive_write_disk *)_a; struct fixup_entry *fe; + const char *linkname; int ret, r; archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, @@ -591,6 +592,17 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry) return (ret); /* + * Check if we have a hardlink that points to itself. + */ + linkname = archive_entry_hardlink(a->entry); + if (linkname != NULL && strcmp(a->name, linkname) == 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Skipping hardlink pointing to itself: %s", + a->name); + return (ARCHIVE_WARN); + } + + /* * Query the umask so we get predictable mode settings. * This gets done on every call to _write_header in case the * user edits their umask during the extraction for some @@ -1856,8 +1868,9 @@ finish_metadata: if (a->tmpname) { if (rename(a->tmpname, a->name) == -1) { archive_set_error(&a->archive, errno, - "rename failed"); - ret = ARCHIVE_FATAL; + "Failed to rename temporary file"); + ret = ARCHIVE_FAILED; + unlink(a->tmpname); } a->tmpname = NULL; } @@ -2144,8 +2157,11 @@ restore_entry(struct archive_write_disk *a) if ((a->flags & ARCHIVE_EXTRACT_SAFE_WRITES) && S_ISREG(a->st.st_mode)) { /* Use a temporary file to extract */ - if ((a->fd = la_mktemp(a)) == -1) + if ((a->fd = la_mktemp(a)) == -1) { + archive_set_error(&a->archive, errno, + "Can't create temporary file"); return ARCHIVE_FAILED; + } a->pst = NULL; en = 0; } else { @@ -4407,10 +4423,19 @@ set_xattrs(struct archive_write_disk *a) int e; int namespace; + namespace = EXTATTR_NAMESPACE_USER; + if (strncmp(name, "user.", 5) == 0) { /* "user." attributes go to user namespace */ name += 5; namespace = EXTATTR_NAMESPACE_USER; + } else if (strncmp(name, "system.", 7) == 0) { + name += 7; + namespace = EXTATTR_NAMESPACE_SYSTEM; + if (!strcmp(name, "nfs4.acl") || + !strcmp(name, "posix1e.acl_access") || + !strcmp(name, "posix1e.acl_default")) + continue; } else { /* Other namespaces are unsupported */ archive_strcat(&errlist, name); @@ -4421,8 +4446,29 @@ set_xattrs(struct archive_write_disk *a) } if (a->fd >= 0) { + /* + * On FreeBSD, extattr_set_fd does not + * return the same as + * extattr_set_file. It returns zero + * on success, non-zero on failure. + * + * We can detect the failure by + * manually setting errno prior to the + * call and checking after. + * + * If errno remains zero, fake the + * return value by setting e to size. + * + * This is a hack for now until I + * (Shawn Webb) get FreeBSD to fix the + * issue, if that's even possible. + */ + errno = 0; e = extattr_set_fd(a->fd, namespace, name, value, size); + if (e == 0 && errno == 0) { + e = size; + } } else { e = extattr_set_link( archive_entry_pathname(entry), namespace, diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c index 77e36c4..0c60017 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c @@ -549,6 +549,8 @@ la_mktemp(struct archive_write_disk *a) a->tmpname = a->_tmpname_data.s; fd = __archive_mkstemp(a->tmpname); + if (fd == -1) + return -1; mode = a->mode & 0777 & ~a->user_umask; if (la_chmod(a->tmpname, mode) == -1) { @@ -1281,9 +1283,11 @@ _archive_write_disk_finish_entry(struct archive *_a) /* Windows does not support atomic rename */ disk_unlink(a->name); if (_wrename(a->tmpname, a->name) != 0) { + la_dosmaperr(GetLastError()); archive_set_error(&a->archive, errno, - "rename failed"); - ret = ARCHIVE_FATAL; + "Failed to rename temporary file"); + ret = ARCHIVE_FAILED; + disk_unlink(a->tmpname); } a->tmpname = NULL; } @@ -1573,12 +1577,17 @@ restore_entry(struct archive_write_disk *a) S_ISREG(st_mode)) { int fd = la_mktemp(a); - if (fd == -1) + if (fd == -1) { + la_dosmaperr(GetLastError()); + archive_set_error(&a->archive, errno, + "Can't create temporary file"); return (ARCHIVE_FAILED); + } a->fh = (HANDLE)_get_osfhandle(fd); - if (a->fh == INVALID_HANDLE_VALUE) + if (a->fh == INVALID_HANDLE_VALUE) { + la_dosmaperr(GetLastError()); return (ARCHIVE_FAILED); - + } a->pst = NULL; en = 0; } else { diff --git a/Utilities/cmlibarchive/libarchive/archive_write_open.3 b/Utilities/cmlibarchive/libarchive/archive_write_open.3 index 0129d10..29bffe4 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_open.3 +++ b/Utilities/cmlibarchive/libarchive/archive_write_open.3 @@ -24,11 +24,12 @@ .\" .\" $FreeBSD$ .\" -.Dd February 2, 2012 +.Dd November 12, 2020 .Dt ARCHIVE_WRITE_OPEN 3 .Os .Sh NAME .Nm archive_write_open , +.Nm archive_write_open2 , .Nm archive_write_open_fd , .Nm archive_write_open_FILE , .Nm archive_write_open_filename , @@ -47,6 +48,15 @@ Streaming Archive Library (libarchive, -larchive) .Fa "archive_close_callback *" .Fc .Ft int +.Fo archive_write_open2 +.Fa "struct archive *" +.Fa "void *client_data" +.Fa "archive_open_callback *" +.Fa "archive_write_callback *" +.Fa "archive_close_callback *" +.Fa "archive_free_callback *" +.Fc +.Ft int .Fn archive_write_open_fd "struct archive *" "int fd" .Ft int .Fn archive_write_open_FILE "struct archive *" "FILE *file" @@ -67,6 +77,11 @@ This is the most generic form of this function, which accepts pointers to three callback functions which will be invoked by the compression layer to write the constructed archive. This does not alter the default archive padding. +.It Fn archive_write_open2 +Same as +.Fn archive_write_open +with an additional fourth free callback. This function should be preferred to +.Fn archive_write_open . .It Fn archive_write_open_fd A convenience form of .Fn archive_write_open @@ -106,14 +121,14 @@ to a character or block device node, it will disable padding otherwise. You can override this by manually invoking .Fn archive_write_set_bytes_in_last_block before calling -.Fn archive_write_open . +.Fn archive_write_open2 . The .Fn archive_write_open_filename function is safe for use with tape drives or other block-oriented devices. .It Fn archive_write_open_memory A convenience form of -.Fn archive_write_open +.Fn archive_write_open2 that accepts a pointer to a block of memory that will receive the archive. The final @@ -145,7 +160,7 @@ To use this library, you will need to define and register callback functions that will be invoked to write data to the resulting archive. These functions are registered by calling -.Fn archive_write_open : +.Fn archive_write_open2 : .Bl -item -offset indent .It .Ft typedef int @@ -162,6 +177,8 @@ If the open fails, it should call .Fn archive_set_error to register an error code and message and return .Cm ARCHIVE_FATAL . +Please note that if open fails, close is not called and resources must be +freed inside the open callback or with the free callback. .Bl -item -offset indent .It .Ft typedef la_ssize_t @@ -192,7 +209,8 @@ to register an error code and message and return -1. .El .Pp The close callback is invoked by archive_close when -the archive processing is complete. +the archive processing is complete. If the open callback fails, the close +callback is not invoked. The callback should return .Cm ARCHIVE_OK on success. @@ -200,7 +218,14 @@ On failure, the callback should invoke .Fn archive_set_error to register an error code and message and return -.Cm ARCHIVE_FATAL . +.Bl -item -offset indent +.It +.Ft typedef int +.Fn archive_free_callback "struct archive *" "void *client_data" +.El +.Pp +The free callback is always invoked on archive_free. +The return code of this callback is not processed. .Pp Note that if the client-provided write callback function returns a non-zero value, that error will be propagated back to the caller diff --git a/Utilities/cmlibarchive/libarchive/archive_write_open_fd.c b/Utilities/cmlibarchive/libarchive/archive_write_open_fd.c index d5c426c..b8d491f 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_open_fd.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_open_fd.c @@ -54,7 +54,7 @@ struct write_fd_data { int fd; }; -static int file_close(struct archive *, void *); +static int file_free(struct archive *, void *); static int file_open(struct archive *, void *); static ssize_t file_write(struct archive *, void *, const void *buff, size_t); @@ -72,8 +72,8 @@ archive_write_open_fd(struct archive *a, int fd) #if defined(__CYGWIN__) || defined(_WIN32) setmode(mine->fd, O_BINARY); #endif - return (archive_write_open(a, mine, - file_open, file_write, file_close)); + return (archive_write_open2(a, mine, + file_open, file_write, NULL, file_free)); } static int @@ -134,11 +134,13 @@ file_write(struct archive *a, void *client_data, const void *buff, size_t length } static int -file_close(struct archive *a, void *client_data) +file_free(struct archive *a, void *client_data) { struct write_fd_data *mine = (struct write_fd_data *)client_data; (void)a; /* UNUSED */ + if (mine == NULL) + return (ARCHIVE_OK); free(mine); return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_open_file.c b/Utilities/cmlibarchive/libarchive/archive_write_open_file.c index f6b1412..bf5b55a 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_open_file.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_open_file.c @@ -51,7 +51,7 @@ struct write_FILE_data { FILE *f; }; -static int file_close(struct archive *, void *); +static int file_free(struct archive *, void *); static int file_open(struct archive *, void *); static ssize_t file_write(struct archive *, void *, const void *buff, size_t); @@ -66,8 +66,8 @@ archive_write_open_FILE(struct archive *a, FILE *f) return (ARCHIVE_FATAL); } mine->f = f; - return (archive_write_open(a, mine, - file_open, file_write, file_close)); + return (archive_write_open2(a, mine, file_open, file_write, + NULL, file_free)); } static int @@ -99,11 +99,13 @@ file_write(struct archive *a, void *client_data, const void *buff, size_t length } static int -file_close(struct archive *a, void *client_data) +file_free(struct archive *a, void *client_data) { struct write_FILE_data *mine = client_data; (void)a; /* UNUSED */ + if (mine == NULL) + return (ARCHIVE_OK); free(mine); return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_open_filename.c b/Utilities/cmlibarchive/libarchive/archive_write_open_filename.c index 66e0dfe..9ceefb1 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_open_filename.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_open_filename.c @@ -62,6 +62,7 @@ struct write_file_data { }; static int file_close(struct archive *, void *); +static int file_free(struct archive *, void *); static int file_open(struct archive *, void *); static ssize_t file_write(struct archive *, void *, const void *buff, size_t); static int open_filename(struct archive *, int, const void *); @@ -123,8 +124,8 @@ open_filename(struct archive *a, int mbs_fn, const void *filename) return (ARCHIVE_FAILED); } mine->fd = -1; - return (archive_write_open(a, mine, - file_open, file_write, file_close)); + return (archive_write_open2(a, mine, + file_open, file_write, file_close, file_free)); } static int @@ -244,9 +245,25 @@ file_close(struct archive *a, void *client_data) (void)a; /* UNUSED */ + if (mine == NULL) + return (ARCHIVE_FATAL); + if (mine->fd >= 0) close(mine->fd); + return (ARCHIVE_OK); +} + +static int +file_free(struct archive *a, void *client_data) +{ + struct write_file_data *mine = (struct write_file_data *)client_data; + + (void)a; /* UNUSED */ + + if (mine == NULL) + return (ARCHIVE_OK); + archive_mstring_clean(&mine->filename); free(mine); return (ARCHIVE_OK); diff --git a/Utilities/cmlibarchive/libarchive/archive_write_open_memory.c b/Utilities/cmlibarchive/libarchive/archive_write_open_memory.c index ea6ae0a..a8a0b81 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_open_memory.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_open_memory.c @@ -39,7 +39,7 @@ struct write_memory_data { unsigned char * buff; }; -static int memory_write_close(struct archive *, void *); +static int memory_write_free(struct archive *, void *); static int memory_write_open(struct archive *, void *); static ssize_t memory_write(struct archive *, void *, const void *buff, size_t); @@ -61,8 +61,8 @@ archive_write_open_memory(struct archive *a, void *buff, size_t buffSize, size_t mine->buff = buff; mine->size = buffSize; mine->client_size = used; - return (archive_write_open(a, mine, - memory_write_open, memory_write, memory_write_close)); + return (archive_write_open2(a, mine, + memory_write_open, memory_write, NULL, memory_write_free)); } static int @@ -103,11 +103,13 @@ memory_write(struct archive *a, void *client_data, const void *buff, size_t leng } static int -memory_write_close(struct archive *a, void *client_data) +memory_write_free(struct archive *a, void *client_data) { struct write_memory_data *mine; (void)a; /* UNUSED */ mine = client_data; + if (mine == NULL) + return (ARCHIVE_OK); free(mine); return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_private.h b/Utilities/cmlibarchive/libarchive/archive_write_private.h index 27cba03..155fdd7 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_private.h +++ b/Utilities/cmlibarchive/libarchive/archive_write_private.h @@ -89,6 +89,7 @@ struct archive_write { archive_open_callback *client_opener; archive_write_callback *client_writer; archive_close_callback *client_closer; + archive_free_callback *client_freer; void *client_data; /* diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format.c index 12de080..7dbe7b9 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format.c @@ -82,7 +82,7 @@ void __archive_write_entry_filetype_unsupported(struct archive *a, struct archive_entry *entry, const char *format) { - char *name = NULL; + const char *name = NULL; switch (archive_entry_filetype(entry)) { /* diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c index 69af814..7f2e6ac 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c @@ -1927,8 +1927,8 @@ compression_init_encoder_lzma(struct archive *a, return (ARCHIVE_FATAL); } lzmafilters = (lzma_filter *)(strm+1); - if (level > 6) - level = 6; + if (level > 9) + level = 9; if (lzma_lzma_preset(&lzma_opt, level)) { free(strm); lastrm->real_stream = NULL; diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio.c index 729f9c7..e066733 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio.c @@ -250,7 +250,7 @@ archive_write_cpio_header(struct archive_write *a, struct archive_entry *entry) const char *path; size_t len; - if (archive_entry_filetype(entry) == 0) { + if (archive_entry_filetype(entry) == 0 && archive_entry_hardlink(entry) == NULL) { archive_set_error(&a->archive, -1, "Filetype required"); return (ARCHIVE_FAILED); } @@ -348,7 +348,7 @@ write_header(struct archive_write *a, struct archive_entry *entry) format_octal(archive_entry_nlink(entry), h + c_nlink_offset, c_nlink_size); if (archive_entry_filetype(entry) == AE_IFBLK || archive_entry_filetype(entry) == AE_IFCHR) - format_octal(archive_entry_dev(entry), h + c_rdev_offset, c_rdev_size); + format_octal(archive_entry_rdev(entry), h + c_rdev_offset, c_rdev_size); else format_octal(0, h + c_rdev_offset, c_rdev_size); format_octal(archive_entry_mtime(entry), h + c_mtime_offset, c_mtime_size); diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio_newc.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio_newc.c index 172fda6..f0f3980 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio_newc.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio_newc.c @@ -190,7 +190,7 @@ archive_write_newc_header(struct archive_write *a, struct archive_entry *entry) const char *path; size_t len; - if (archive_entry_filetype(entry) == 0) { + if (archive_entry_filetype(entry) == 0 && archive_entry_hardlink(entry) == NULL) { archive_set_error(&a->archive, -1, "Filetype required"); return (ARCHIVE_FAILED); } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_iso9660.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_iso9660.c index 5db414f..68e3fe3 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_iso9660.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_iso9660.c @@ -2178,7 +2178,8 @@ get_system_identitier(char *system_id, size_t size) strncpy(system_id, "Windows", size-1); system_id[size-1] = '\0'; #else -#error no way to get the system identifier on your platform. + strncpy(system_id, "Unknown", size-1); + system_id[size-1] = '\0'; #endif } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_mtree.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_mtree.c index aa41e9a..619b771 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_mtree.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_mtree.c @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_mtree.c 201171 #include "archive.h" #include "archive_digest_private.h" #include "archive_entry.h" +#include "archive_entry_private.h" #include "archive_private.h" #include "archive_rb.h" #include "archive_string.h" @@ -82,24 +83,7 @@ struct dir_info { struct reg_info { int compute_sum; uint32_t crc; -#ifdef ARCHIVE_HAS_MD5 - unsigned char buf_md5[16]; -#endif -#ifdef ARCHIVE_HAS_RMD160 - unsigned char buf_rmd160[20]; -#endif -#ifdef ARCHIVE_HAS_SHA1 - unsigned char buf_sha1[20]; -#endif -#ifdef ARCHIVE_HAS_SHA256 - unsigned char buf_sha256[32]; -#endif -#ifdef ARCHIVE_HAS_SHA384 - unsigned char buf_sha384[48]; -#endif -#ifdef ARCHIVE_HAS_SHA512 - unsigned char buf_sha512[64]; -#endif + struct ae_digest digest; }; struct mtree_entry { @@ -1571,27 +1555,27 @@ sum_final(struct mtree_writer *mtree, struct reg_info *reg) } #ifdef ARCHIVE_HAS_MD5 if (mtree->compute_sum & F_MD5) - archive_md5_final(&mtree->md5ctx, reg->buf_md5); + archive_md5_final(&mtree->md5ctx, reg->digest.md5); #endif #ifdef ARCHIVE_HAS_RMD160 if (mtree->compute_sum & F_RMD160) - archive_rmd160_final(&mtree->rmd160ctx, reg->buf_rmd160); + archive_rmd160_final(&mtree->rmd160ctx, reg->digest.rmd160); #endif #ifdef ARCHIVE_HAS_SHA1 if (mtree->compute_sum & F_SHA1) - archive_sha1_final(&mtree->sha1ctx, reg->buf_sha1); + archive_sha1_final(&mtree->sha1ctx, reg->digest.sha1); #endif #ifdef ARCHIVE_HAS_SHA256 if (mtree->compute_sum & F_SHA256) - archive_sha256_final(&mtree->sha256ctx, reg->buf_sha256); + archive_sha256_final(&mtree->sha256ctx, reg->digest.sha256); #endif #ifdef ARCHIVE_HAS_SHA384 if (mtree->compute_sum & F_SHA384) - archive_sha384_final(&mtree->sha384ctx, reg->buf_sha384); + archive_sha384_final(&mtree->sha384ctx, reg->digest.sha384); #endif #ifdef ARCHIVE_HAS_SHA512 if (mtree->compute_sum & F_SHA512) - archive_sha512_final(&mtree->sha512ctx, reg->buf_sha512); + archive_sha512_final(&mtree->sha512ctx, reg->digest.sha512); #endif /* Save what types of sum are computed. */ reg->compute_sum = mtree->compute_sum; @@ -1621,42 +1605,47 @@ sum_write(struct archive_string *str, struct reg_info *reg) archive_string_sprintf(str, " cksum=%ju", (uintmax_t)reg->crc); } + +#define append_digest(_s, _r, _t) \ + strappend_bin(_s, _r->digest._t, sizeof(_r->digest._t)) + #ifdef ARCHIVE_HAS_MD5 if (reg->compute_sum & F_MD5) { archive_strcat(str, " md5digest="); - strappend_bin(str, reg->buf_md5, sizeof(reg->buf_md5)); + append_digest(str, reg, md5); } #endif #ifdef ARCHIVE_HAS_RMD160 if (reg->compute_sum & F_RMD160) { archive_strcat(str, " rmd160digest="); - strappend_bin(str, reg->buf_rmd160, sizeof(reg->buf_rmd160)); + append_digest(str, reg, rmd160); } #endif #ifdef ARCHIVE_HAS_SHA1 if (reg->compute_sum & F_SHA1) { archive_strcat(str, " sha1digest="); - strappend_bin(str, reg->buf_sha1, sizeof(reg->buf_sha1)); + append_digest(str, reg, sha1); } #endif #ifdef ARCHIVE_HAS_SHA256 if (reg->compute_sum & F_SHA256) { archive_strcat(str, " sha256digest="); - strappend_bin(str, reg->buf_sha256, sizeof(reg->buf_sha256)); + append_digest(str, reg, sha256); } #endif #ifdef ARCHIVE_HAS_SHA384 if (reg->compute_sum & F_SHA384) { archive_strcat(str, " sha384digest="); - strappend_bin(str, reg->buf_sha384, sizeof(reg->buf_sha384)); + append_digest(str, reg, sha384); } #endif #ifdef ARCHIVE_HAS_SHA512 if (reg->compute_sum & F_SHA512) { archive_strcat(str, " sha512digest="); - strappend_bin(str, reg->buf_sha512, sizeof(reg->buf_sha512)); + append_digest(str, reg, sha512); } #endif +#undef append_digest } static int diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_xar.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_xar.c index 3b0ffb3..1e35375 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_xar.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_xar.c @@ -681,7 +681,8 @@ xar_write_data(struct archive_write *a, const void *buff, size_t s) { struct xar *xar; enum la_zaction run; - size_t size, rsize; + size_t size = 0; + size_t rsize; int r; xar = (struct xar *)a->format_data; @@ -2930,8 +2931,8 @@ compression_init_encoder_xz(struct archive *a, return (ARCHIVE_FATAL); } lzmafilters = (lzma_filter *)(strm+1); - if (level > 6) - level = 6; + if (level > 9) + level = 9; if (lzma_lzma_preset(&lzma_opt, level)) { free(strm); lastrm->real_stream = NULL; diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_zip.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_zip.c index b0cd215..66a1f84 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_zip.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_zip.c @@ -584,6 +584,7 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) zip->entry_flags |= ZIP_ENTRY_FLAG_ENCRYPTED; zip->entry_encryption = zip->encryption_type; break; + case ENCRYPTION_NONE: default: break; } @@ -710,6 +711,7 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) + AUTH_CODE_SIZE; version_needed = 20; break; + case ENCRYPTION_NONE: default: break; } @@ -762,6 +764,7 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) if (version_needed < 20) version_needed = 20; break; + case ENCRYPTION_NONE: default: break; } @@ -1029,6 +1032,7 @@ archive_write_zip_data(struct archive_write *a, const void *buff, size_t s) zip->cctx_valid = zip->hctx_valid = 1; } break; + case ENCRYPTION_NONE: default: break; } @@ -1117,6 +1121,7 @@ archive_write_zip_data(struct archive_write *a, const void *buff, size_t s) break; #endif + case COMPRESSION_UNSPECIFIED: default: archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Invalid ZIP compression type"); diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_options.3 b/Utilities/cmlibarchive/libarchive/archive_write_set_options.3 index cffe571..d4a52e3 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_options.3 +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_options.3 @@ -255,7 +255,8 @@ If supported, the default value is read from .Bl -tag -compact -width indent .It Cm compression-level The value is interpreted as a decimal integer specifying the -compression level. Supported values are from 1 to 22. +compression level. Supported values depend on the library version, +common values are from 1 to 22. .El .It Format 7zip .Bl -tag -compact -width indent diff --git a/Utilities/cmlibarchive/libarchive/config_freebsd.h b/Utilities/cmlibarchive/libarchive/config_freebsd.h index f16fd34..a484618 100644 --- a/Utilities/cmlibarchive/libarchive/config_freebsd.h +++ b/Utilities/cmlibarchive/libarchive/config_freebsd.h @@ -24,6 +24,7 @@ * * $FreeBSD$ */ +#define __LIBARCHIVE_CONFIG_H_INCLUDED 1 #include <osreldate.h> @@ -183,6 +184,7 @@ #define HAVE_STRFTIME 1 #define HAVE_STRINGS_H 1 #define HAVE_STRING_H 1 +#define HAVE_STRNLEN 1 #define HAVE_STRRCHR 1 #define HAVE_STRUCT_STATFS_F_NAMEMAX 1 #define HAVE_STRUCT_STAT_ST_BIRTHTIME 1 diff --git a/Utilities/cmlibarchive/libarchive/cpio.5 b/Utilities/cmlibarchive/libarchive/cpio.5 index 1a2886f..a91f0c5 100644 --- a/Utilities/cmlibarchive/libarchive/cpio.5 +++ b/Utilities/cmlibarchive/libarchive/cpio.5 @@ -244,7 +244,7 @@ Note that this format supports only 4 gigabyte files (unlike the older ASCII format, which supports 8 gigabyte files). .Pp In this format, hardlinked files are handled by setting the -filesize to zero for each entry except the last one that +filesize to zero for each entry except the first one that appears in the archive. .Ss New CRC Format The CRC format is identical to the new ASCII format described diff --git a/Utilities/cmlibarchive/libarchive/filter_fork.h b/Utilities/cmlibarchive/libarchive/filter_fork.h index 908e7cd..2bf290c 100644 --- a/Utilities/cmlibarchive/libarchive/filter_fork.h +++ b/Utilities/cmlibarchive/libarchive/filter_fork.h @@ -32,8 +32,13 @@ #error This header is only to be used internally to libarchive. #endif -pid_t -__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout); +int +__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout, +#if defined(_WIN32) && !defined(__CYGWIN__) + HANDLE *out_child); +#else + pid_t *out_child); +#endif void __archive_check_child(int in, int out); diff --git a/Utilities/cmlibarchive/libarchive/filter_fork_posix.c b/Utilities/cmlibarchive/libarchive/filter_fork_posix.c index 02dbd4b..ac255c4 100644 --- a/Utilities/cmlibarchive/libarchive/filter_fork_posix.c +++ b/Utilities/cmlibarchive/libarchive/filter_fork_posix.c @@ -72,8 +72,9 @@ __FBSDID("$FreeBSD: head/lib/libarchive/filter_fork.c 182958 2008-09-12 05:33:00 #include "filter_fork.h" -pid_t -__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout) +int +__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout, + pid_t *out_child) { pid_t child; int stdin_pipe[2], stdout_pipe[2], tmp; @@ -177,7 +178,8 @@ __archive_create_child(const char *cmd, int *child_stdin, int *child_stdout) fcntl(*child_stdout, F_SETFL, O_NONBLOCK); __archive_cmdline_free(cmdline); - return child; + *out_child = child; + return ARCHIVE_OK; #if HAVE_POSIX_SPAWNP actions_inited: @@ -192,7 +194,7 @@ stdin_opened: close(stdin_pipe[1]); state_allocated: __archive_cmdline_free(cmdline); - return -1; + return ARCHIVE_FAILED; } void diff --git a/Utilities/cmlibarchive/libarchive/filter_fork_windows.c b/Utilities/cmlibarchive/libarchive/filter_fork_windows.c index ad271fe..8d11179 100644 --- a/Utilities/cmlibarchive/libarchive/filter_fork_windows.c +++ b/Utilities/cmlibarchive/libarchive/filter_fork_windows.c @@ -31,8 +31,9 @@ #include "filter_fork.h" -pid_t -__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout) +int +__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout, + HANDLE *out_child) { HANDLE childStdout[2], childStdin[2],childStderr; SECURITY_ATTRIBUTES secAtts; @@ -44,6 +45,7 @@ __archive_create_child(const char *cmd, int *child_stdin, int *child_stdout) char *arg0, *ext; int i, l; DWORD fl, fl_old; + HANDLE child; childStdout[0] = childStdout[1] = INVALID_HANDLE_VALUE; childStdin[0] = childStdin[1] = INVALID_HANDLE_VALUE; @@ -154,13 +156,20 @@ __archive_create_child(const char *cmd, int *child_stdin, int *child_stdout) *child_stdout = _open_osfhandle((intptr_t)childStdout[0], _O_RDONLY); *child_stdin = _open_osfhandle((intptr_t)childStdin[1], _O_WRONLY); + child = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, + childInfo.dwProcessId); + if (child == NULL) // INVALID_HANDLE_VALUE ? + goto fail; + + *out_child = child; + CloseHandle(childStdout[1]); CloseHandle(childStdin[0]); archive_string_free(&cmdline); archive_string_free(&fullpath); __archive_cmdline_free(acmd); - return (childInfo.dwProcessId); + return ARCHIVE_OK; fail: if (childStdout[0] != INVALID_HANDLE_VALUE) @@ -176,7 +185,7 @@ fail: archive_string_free(&cmdline); archive_string_free(&fullpath); __archive_cmdline_free(acmd); - return (-1); + return ARCHIVE_FAILED; } void |